Article refactoring and changes for bug 31144. Dependency inject ParserOutput objects...
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 24 Sep 2011 21:12:26 +0000 (21:12 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 24 Sep 2011 21:12:26 +0000 (21:12 +0000)
docs/hooks.txt
includes/Article.php

index 536ee8f..d661e9d 100644 (file)
@@ -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
index a91ad26..2c736a2 100644 (file)
@@ -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 <title> 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() )
                        );
                }