r85929 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85928‎ | r85929 | r85930 >
Date:23:00, 12 April 2011
Author:happy-melon
Status:resolved (Comments)
Tags:
Comment:
Implement a $context and getContext/setContext methods for Article (and its subclasses).
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -17,6 +17,8 @@
1818 /**@{{
1919 * @private
2020 */
 21+ protected $mContext; // !< RequestContext
 22+
2123 var $mContent; // !<
2224 var $mContentLoaded = false; // !<
2325 var $mCounter = -1; // !< Not loaded
@@ -4531,6 +4533,31 @@
45324534 return $this->getOutputFromWikitext( $text, $useParserCache );
45334535 }
45344536
 4537+ /**
 4538+ * Sets the context this Article is executed in
 4539+ *
 4540+ * @param $context RequestContext
 4541+ * @since 1.18
 4542+ */
 4543+ public function setContext( $context ) {
 4544+ $this->mContext = $context;
 4545+ }
 4546+
 4547+ /**
 4548+ * Gets the context this Article is executed in
 4549+ *
 4550+ * @return RequestContext
 4551+ * @since 1.18
 4552+ */
 4553+ public function getContext() {
 4554+ if ( $this->mContext instanceof RequestContext ) {
 4555+ return $this->mContext;
 4556+ } else {
 4557+ wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
 4558+ return RequestContext::getMain();
 4559+ }
 4560+ }
 4561+
45354562 }
45364563
45374564 class PoolWorkArticleView extends PoolCounterWork {
Index: trunk/phase3/includes/Wiki.php
@@ -266,7 +266,7 @@
267267 * @param $title Title
268268 * @return Article object
269269 */
270 - public static function articleFromTitle( &$title ) {
 270+ public static function articleFromTitle( &$title, RequestContext &$context ) {
271271 if ( NS_MEDIA == $title->getNamespace() ) {
272272 // FIXME: where should this go?
273273 $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
@@ -280,12 +280,14 @@
281281
282282 switch( $title->getNamespace() ) {
283283 case NS_FILE:
284 - return new ImagePage( $title );
 284+ $page = new ImagePage( $title );
285285 case NS_CATEGORY:
286 - return new CategoryPage( $title );
 286+ $page = new CategoryPage( $title );
287287 default:
288 - return new Article( $title );
 288+ $page = new Article( $title );
289289 }
 290+ $page->setContext( $context );
 291+ return $page;
290292 }
291293
292294 /**
@@ -332,7 +334,7 @@
333335 wfProfileIn( __METHOD__ );
334336
335337 $action = $this->context->request->getVal( 'action', 'view' );
336 - $article = self::articleFromTitle( $this->context->title );
 338+ $article = self::articleFromTitle( $this->context->title, $this->context );
337339 // NS_MEDIAWIKI has no redirects.
338340 // It is also used for CSS/JS, so performance matters here...
339341 if ( $this->context->title->getNamespace() == NS_MEDIAWIKI ) {
@@ -369,7 +371,7 @@
370372 }
371373 if ( is_object( $target ) ) {
372374 // Rewrite environment to redirected article
373 - $rarticle = self::articleFromTitle( $target );
 375+ $rarticle = self::articleFromTitle( $target, $this->context );
374376 $rarticle->loadPageData();
375377 if ( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) {
376378 $rarticle->setRedirectedFrom( $this->context->title );
@@ -467,9 +469,16 @@
468470 return;
469471 }
470472
471 - $action = $this->getAction();
 473+ $act = $this->getAction();
472474
473 - switch( $action ) {
 475+ $action = Action::factory( $this->getAction(), $article );
 476+ if( $action instanceof Action ){
 477+ $action->execute();
 478+ wfProfileOut( __METHOD__ );
 479+ return;
 480+ }
 481+
 482+ switch( $act ) {
474483 case 'view':
475484 $this->context->output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
476485 $article->view();
@@ -492,7 +501,7 @@
493502 case 'render':
494503 case 'deletetrackback':
495504 case 'purge':
496 - $article->$action();
 505+ $article->$act();
497506 break;
498507 case 'print':
499508 $article->view();
@@ -513,9 +522,6 @@
514523 $rdf->show();
515524 }
516525 break;
517 - case 'credits':
518 - Credits::showPage( $article );
519 - break;
520526 case 'submit':
521527 if ( session_id() == '' ) {
522528 // Send a cookie so anons get talk message notifications
@@ -528,7 +534,7 @@
529535 $external = $this->context->request->getVal( 'externaledit' );
530536 $section = $this->context->request->getVal( 'section' );
531537 $oldid = $this->context->request->getVal( 'oldid' );
532 - if ( !$this->getVal( 'UseExternalEditor' ) || $action == 'submit' || $internal ||
 538+ if ( !$this->getVal( 'UseExternalEditor' ) || $act == 'submit' || $internal ||
533539 $section || $oldid || ( !$this->context->user->getOption( 'externaleditor' ) && !$external ) ) {
534540 $editor = new EditPage( $article );
535541 $editor->submit();
@@ -557,7 +563,7 @@
558564 $special->execute( '' );
559565 break;
560566 default:
561 - if ( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
 567+ if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {
562568 $this->context->output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
563569 }
564570 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r85931Follow-up r85928: back out unrelated changes.happy-melon23:28, 12 April 2011
r85939followup to r85929 -- missing the break;s for non-default cases.neilk05:31, 13 April 2011
r85950Follow-up r85929: update MediaWiki::articleFromTitle() call in SearchEngine.phphappy-melon14:27, 13 April 2011
r86273Follow-up r85929: update MediaWiki::articleFromTitle() calls in extensions (a...happy-melon19:25, 17 April 2011

Comments

#Comment by Krinkle (talk | contribs)   08:21, 13 April 2011

After up'ing to this revision my local wiki doesn't do anything anymore, just display this:

Fatal error: Class 'Action' not found in /trunk/phase3/includes/Wiki.php on line 474

Test before commit ;-)

#Comment by Happy-melon (talk | contribs)   10:34, 13 April 2011

This is a result of having multiple separate things going on in my working copy at the same time and trying to break up commits. The Action class exists in my working copy and so tests fine, but both sets of changes alter Wiki.php in different ways. I missed the AutoLoader entry from r85928 for the same reason.

This was already fixed in r85931.

#Comment by Tbleher (talk | contribs)   18:43, 17 April 2011

Can you please update callers in extensions? DumpHTML was broken by this change, as it calls MediaWiki::articleFromTitle():

Catchable fatal error: Argument 2 passed to MediaWiki::articleFromTitle() must be an instance of RequestContext, none given, called in /srv/www/mediawiki/extensions/DumpHTML/dumpHTML.inc on line 804 and defined in /srv/www/mediawiki/code/includes/Wiki.php on line 269
#Comment by Krinkle (talk | contribs)   18:56, 17 April 2011

Potentially more extensions:

"articleFromTitle" in /trunk/extensions/:

http://toolserver.org/~krinkle/wikimedia-svn-search/view.php?id=173&hash=082b8bdeb037aee898c6e2ae77910bb0

#Comment by Happy-melon (talk | contribs)   19:26, 17 April 2011

Done in r86273.

#Comment by Krinkle (talk | contribs)   19:27, 17 April 2011

Hm.. can/should we make it default to Main ?

#Comment by Aaron Schulz (talk | contribs)   00:38, 21 June 2011

I hate this class...

#Comment by Aaron Schulz (talk | contribs)   01:51, 21 June 2011

Article.php that is.

Status & tagging log