* (bug 41966) Follow-up I551a90b0 (c2172d4): fix fatal error in PoolWorkArticleView...
[lhc/web/wiklou.git] / includes / Article.php
index 54d658c..169dd03 100644 (file)
@@ -238,12 +238,12 @@ class Article extends Page {
         * This function has side effects! Do not use this function if you
         * only want the real revision text if any.
         *
-        * @deprecated in 1.21; use getContentObject() instead
+        * @deprecated in 1.21; use WikiPage::getContent() instead
         *
         * @return string Return the text of this revision
         */
        public function getContent() {
-               wfDeprecated( __METHOD__, '1.21' );
+               ContentHandler::deprecated( __METHOD__, '1.21' );
                $content = $this->getContentObject();
                return ContentHandler::getContentText( $content );
        }
@@ -262,11 +262,8 @@ class Article extends Page {
         * @return Content Return the content of this revision
         *
         * @since 1.21
-        *
-        * @todo: FIXME: this should really be protected, all callers should be changed to use WikiPage::getContent() instead.
         */
-       public function getContentObject() {
-               global $wgUser;
+       protected function getContentObject() {
                wfProfileIn( __METHOD__ );
 
                if ( $this->mPage->getID() === 0 ) {
@@ -380,7 +377,7 @@ class Article extends Page {
         * @deprecated in 1.21, use WikiPage::getContent() instead
         */
        function fetchContent() { #BC cruft!
-               wfDeprecated( __METHOD__, '1.21' );
+               ContentHandler::deprecated( __METHOD__, '1.21' );
 
                if ( $this->mContentLoaded && $this->mContent ) {
                        return $this->mContent;
@@ -455,7 +452,7 @@ class Article extends Page {
 
                // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
                // We should instead work with the Revision object when we need it...
-               $this->mContentObject = $this->mRevision->getContent( Revision::FOR_THIS_USER ); // Loads if user is allowed
+               $this->mContentObject = $this->mRevision->getContent( Revision::FOR_THIS_USER, $this->getContext()->getUser() ); // Loads if user is allowed
                $this->mRevIdFetched = $this->mRevision->getId();
 
                wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject ) );
@@ -680,27 +677,24 @@ class Article extends Page {
                                                $this->showCssOrJsPage();
                                                $outputDone = true;
                                        } elseif( !wfRunHooks( 'ArticleContentViewCustom',
-                                                                                       array( $this->fetchContentObject(), $this->getTitle(),
-                                                                                                       $outputPage ) ) ) {
+                                                       array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
 
                                                # Allow extensions do their own custom view for certain pages
                                                $outputDone = true;
                                        } elseif( !ContentHandler::runLegacyHooks( 'ArticleViewCustom',
-                                                                                                                               array( $this->fetchContentObject(), $this->getTitle(),
-                                                                                                                                               $outputPage ) ) ) {
+                                                       array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
 
                                                # Allow extensions do their own custom view for certain pages
                                                $outputDone = true;
                                        } else {
                                                $content = $this->getContentObject();
-                                               $rt = $content->getRedirectChain();
+                                               $rt = $content ? $content->getRedirectChain() : null;
                                                if ( $rt ) {
                                                        wfDebug( __METHOD__ . ": showing redirect=no page\n" );
                                                        # Viewing a redirect page (e.g. with parameter redirect=no)
                                                        $outputPage->addHTML( $this->viewRedirect( $rt ) );
                                                        # Parse just to get categories, displaytitle, etc.
-                                                       $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid,
-                                                                                                                                                               $parserOptions, false );
+                                                       $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
                                                        $outputPage->addParserOutputNoText( $this->mParserOutput );
                                                        $outputDone = true;
                                                }
@@ -710,9 +704,8 @@ class Article extends Page {
                                        # Run the parse, protected by a pool counter
                                        wfDebug( __METHOD__ . ": doing uncached parse\n" );
 
-                                       // @todo: shouldn't we be passing $this->getPage() to PoolWorkArticleView instead of plain $this?
-                                       $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
-                                               $this->getRevIdFetched(), $useParserCache, $this->getContentObject(), $this->getContext() );
+                                       $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
+                                               $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
 
                                        if ( !$poolArticleView->execute() ) {
                                                $error = $poolArticleView->getError();
@@ -810,7 +803,7 @@ class Article extends Page {
                $rev = $this->getRevisionFetched();
 
                if ( !$rev ) {
-                       $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' )->text() );
+                       $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
                        $this->getContext()->getOutput()->addWikiMsg( 'difference-missing-revision', $oldid, 1 );
                        return;
                }
@@ -834,22 +827,28 @@ class Article extends Page {
         *
         * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
         * page views.
+        *
+        * @param bool $showCacheHint whether to show a message telling the user to clear the browser cache (default: true).
         */
        protected function showCssOrJsPage( $showCacheHint = true ) {
-               global $wgOut;
+               $outputPage = $this->getContext()->getOutput();
 
                if ( $showCacheHint ) {
                        $dir = $this->getContext()->getLanguage()->getDir();
                        $lang = $this->getContext()->getLanguage()->getCode();
 
-                       $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
+                       $outputPage->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
                                'clearyourcache' );
                }
 
-               // Give hooks a chance to customise the output
-               if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->fetchContentObject(), $this->getTitle(), $wgOut ) ) ) {
-                       $po = $this->mContentObject->getParserOutput( $this->getTitle() );
-                       $wgOut->addHTML( $po->getText() );
+               $this->fetchContentObject();
+
+               if ( $this->mContentObject ) {
+                       // Give hooks a chance to customise the output
+                       if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mContentObject, $this->getTitle(), $outputPage ) ) ) {
+                               $po = $this->mContentObject->getParserOutput( $this->getTitle() );
+                               $outputPage->addHTML( $po->getText() );
+                       }
                }
        }
 
@@ -1476,7 +1475,7 @@ class Article extends Page {
                if ( !$reason ) {
                        try {
                                $reason = $this->generateReason( $hasHistory );
-                       } catch (MWException $e) {
+                       } catch ( MWException $e ) {
                                # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
                                wfDebug("Error while building auto delete summary: $e");
                                $reason = '';
@@ -1884,8 +1883,9 @@ class Article extends Page {
                wfDeprecated( __METHOD__, '1.18' );
                if ( $noRedir ) {
                        $query = 'redirect=no';
-                       if ( $extraQuery )
+                       if ( $extraQuery ) {
                                $query .= "&$extraQuery";
+                       }
                } else {
                        $query = $extraQuery;
                }
@@ -1964,7 +1964,13 @@ class Article extends Page {
         * @return bool
         */
        public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
-               return $this->mPage->updateRestrictions( $limit, $reason, $cascade, $expiry );
+               return $this->mPage->doUpdateRestrictions(
+                       $limit,
+                       $expiry,
+                       $cascade,
+                       $reason,
+                       $this->getContext()->getUser()
+               );
        }
 
        /**