From: Aaron Schulz Date: Sat, 24 Sep 2011 21:12:26 +0000 (+0000) Subject: Article refactoring and changes for bug 31144. Dependency inject ParserOutput objects... X-Git-Tag: 1.31.0-rc.0~27440 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=c5e8690bf911308502fd9c9be98fecd75b98f83d;p=lhc%2Fweb%2Fwiklou.git Article refactoring and changes for bug 31144. Dependency inject ParserOutput objects in some places and let hooks set $outputDone as the parser output used. --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 536ee8f416..d661e9dfb9 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -540,7 +540,8 @@ $article: Article object viewing. &$article: the article &$pcache: whether to try the parser cache or not -&$outputDone: whether the output for this page finished or not +&$outputDone: whether the output for this page finished or not. Set to a ParserOutput +object to both indicate that the output is done and what parser output was used. 'ArticleViewRedirect': before setting "Redirected from ..." subtitle when follwed an redirect diff --git a/includes/Article.php b/includes/Article.php index a91ad2642e..2c736a2d1c 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -548,13 +548,15 @@ class Article extends Page { } } - # Adjust the title if it was set by displaytitle, -{T|}- or language conversion - if ( $this->mParserOutput ) { - $titleText = $this->mParserOutput->getTitleText(); + # Get the ParserOutput actually *displayed* here. + # Note that $this->mParserOutput is the *current* version output. + $pOutput = ( $outputDone instanceof ParserOutput ) + ? $outputDone // object fetched by hook + : $this->mParserOutput; - if ( strval( $titleText ) !== '' ) { - $wgOut->setPageTitle( $titleText ); - } + # Adjust title for main page & pages with displaytitle + if ( $pOutput ) { + $this->adjustDisplayTitle( $pOutput ); } # For the main page, overwrite the element with the con- @@ -568,17 +570,30 @@ class Article extends Page { } } - # Now that we've filled $this->mParserOutput, we know whether - # there are any __NOINDEX__ tags on the page - $policy = $this->getRobotPolicy( 'view' ); + # Check for any __NOINDEX__ tags on the page using $pOutput + $policy = $this->getRobotPolicy( 'view', $pOutput ); $wgOut->setIndexPolicy( $policy['index'] ); $wgOut->setFollowPolicy( $policy['follow'] ); $this->showViewFooter(); $this->mPage->viewUpdates(); + wfProfileOut( __METHOD__ ); } + /* + * Adjust title for pages with displaytitle, -{T|}- or language conversion + * @param $pOutput ParserOutput + */ + public function adjustDisplayTitle( ParserOutput $pOutput ) { + global $wgOut; + # Adjust the title if it was set by displaytitle, -{T|}- or language conversion + $titleText = $pOutput->getTitleText(); + if ( strval( $titleText ) !== '' ) { + $wgOut->setPageTitle( $titleText ); + } + } + /** * Show a diff page according to current request variables. For use within * Article::view() only, other callers should use the DifferenceEngine class. @@ -634,10 +649,11 @@ class Article extends Page { /** * Get the robot policy to be used for the current view * @param $action String the action= GET parameter + * @param $pOutput ParserOutput * @return Array the policy that should be set * TODO: actions other than 'view' */ - public function getRobotPolicy( $action ) { + public function getRobotPolicy( $action, $pOutput ) { global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies; global $wgDefaultRobotPolicy, $wgRequest; @@ -685,12 +701,12 @@ class Article extends Page { self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] ) ); } - if ( $this->getTitle()->canUseNoindex() && is_object( $this->mParserOutput ) && $this->mParserOutput->getIndexPolicy() ) { + if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) { # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates # a final sanity check that we have really got the parser output. $policy = array_merge( $policy, - array( 'index' => $this->mParserOutput->getIndexPolicy() ) + array( 'index' => $pOutput->getIndexPolicy() ) ); }