r98030 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98029‎ | r98030 | r98031 >
Date:21:12, 24 September 2011
Author:aaron
Status:ok
Tags:post1.18deploy 
Comment:
Article refactoring and changes for bug 31144. Dependency inject ParserOutput objects in some places and let hooks set $outputDone as the parser output used.
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -540,7 +540,8 @@
541541 viewing.
542542 &$article: the article
543543 &$pcache: whether to try the parser cache or not
544 -&$outputDone: whether the output for this page finished or not
 544+&$outputDone: whether the output for this page finished or not. Set to a ParserOutput
 545+object to both indicate that the output is done and what parser output was used.
545546
546547 'ArticleViewRedirect': before setting "Redirected from ..." subtitle when
547548 follwed an redirect
Index: trunk/phase3/includes/Article.php
@@ -548,13 +548,15 @@
549549 }
550550 }
551551
552 - # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
553 - if ( $this->mParserOutput ) {
554 - $titleText = $this->mParserOutput->getTitleText();
 552+ # Get the ParserOutput actually *displayed* here.
 553+ # Note that $this->mParserOutput is the *current* version output.
 554+ $pOutput = ( $outputDone instanceof ParserOutput )
 555+ ? $outputDone // object fetched by hook
 556+ : $this->mParserOutput;
555557
556 - if ( strval( $titleText ) !== '' ) {
557 - $wgOut->setPageTitle( $titleText );
558 - }
 558+ # Adjust title for main page & pages with displaytitle
 559+ if ( $pOutput ) {
 560+ $this->adjustDisplayTitle( $pOutput );
559561 }
560562
561563 # For the main page, overwrite the <title> element with the con-
@@ -568,17 +570,30 @@
569571 }
570572 }
571573
572 - # Now that we've filled $this->mParserOutput, we know whether
573 - # there are any __NOINDEX__ tags on the page
574 - $policy = $this->getRobotPolicy( 'view' );
 574+ # Check for any __NOINDEX__ tags on the page using $pOutput
 575+ $policy = $this->getRobotPolicy( 'view', $pOutput );
575576 $wgOut->setIndexPolicy( $policy['index'] );
576577 $wgOut->setFollowPolicy( $policy['follow'] );
577578
578579 $this->showViewFooter();
579580 $this->mPage->viewUpdates();
 581+
580582 wfProfileOut( __METHOD__ );
581583 }
582584
 585+ /*
 586+ * Adjust title for pages with displaytitle, -{T|}- or language conversion
 587+ * @param $pOutput ParserOutput
 588+ */
 589+ public function adjustDisplayTitle( ParserOutput $pOutput ) {
 590+ global $wgOut;
 591+ # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
 592+ $titleText = $pOutput->getTitleText();
 593+ if ( strval( $titleText ) !== '' ) {
 594+ $wgOut->setPageTitle( $titleText );
 595+ }
 596+ }
 597+
583598 /**
584599 * Show a diff page according to current request variables. For use within
585600 * Article::view() only, other callers should use the DifferenceEngine class.
@@ -634,10 +649,11 @@
635650 /**
636651 * Get the robot policy to be used for the current view
637652 * @param $action String the action= GET parameter
 653+ * @param $pOutput ParserOutput
638654 * @return Array the policy that should be set
639655 * TODO: actions other than 'view'
640656 */
641 - public function getRobotPolicy( $action ) {
 657+ public function getRobotPolicy( $action, $pOutput ) {
642658 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
643659 global $wgDefaultRobotPolicy, $wgRequest;
644660
@@ -685,12 +701,12 @@
686702 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
687703 );
688704 }
689 - if ( $this->getTitle()->canUseNoindex() && is_object( $this->mParserOutput ) && $this->mParserOutput->getIndexPolicy() ) {
 705+ if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
690706 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
691707 # a final sanity check that we have really got the parser output.
692708 $policy = array_merge(
693709 $policy,
694 - array( 'index' => $this->mParserOutput->getIndexPolicy() )
 710+ array( 'index' => $pOutput->getIndexPolicy() )
695711 );
696712 }
697713

Follow-up revisions

RevisionCommit summaryAuthorDate
r98032* (bug 31144) __NOINDEX__should apply to stable versions of pages. Builds off...aaron21:15, 24 September 2011

Status & tagging log