Merge "Drop outdated "documentation reviewed" tags"
[lhc/web/wiklou.git] / includes / page / Article.php
index 5752262..eb597d2 100644 (file)
@@ -224,7 +224,6 @@ class Article implements Page {
         * @since 1.21
         */
        protected function getContentObject() {
-               wfProfileIn( __METHOD__ );
 
                if ( $this->mPage->getID() === 0 ) {
                        # If this is a MediaWiki:x message, then load the messages
@@ -245,7 +244,6 @@ class Article implements Page {
                        $content = $this->mContentObject;
                }
 
-               wfProfileOut( __METHOD__ );
                return $content;
        }
 
@@ -342,12 +340,9 @@ class Article implements Page {
                        return $this->mContent;
                }
 
-               wfProfileIn( __METHOD__ );
-
                $content = $this->fetchContentObject();
 
                if ( !$content ) {
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
@@ -355,8 +350,6 @@ class Article implements Page {
                $this->mContent = ContentHandler::getContentText( $content );
                ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
 
-               wfProfileOut( __METHOD__ );
-
                return $this->mContent;
        }
 
@@ -377,8 +370,6 @@ class Article implements Page {
                        return $this->mContentObject;
                }
 
-               wfProfileIn( __METHOD__ );
-
                $this->mContentLoaded = true;
                $this->mContent = null;
 
@@ -395,7 +386,6 @@ class Article implements Page {
                                $this->mRevision = Revision::newFromId( $oldid );
                                if ( !$this->mRevision ) {
                                        wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
-                                       wfProfileOut( __METHOD__ );
                                        return false;
                                }
                        }
@@ -403,7 +393,6 @@ class Article implements Page {
                        if ( !$this->mPage->getLatest() ) {
                                wfDebug( __METHOD__ . " failed to find page data for title " .
                                        $this->getTitle()->getPrefixedText() . "\n" );
-                               wfProfileOut( __METHOD__ );
                                return false;
                        }
 
@@ -412,7 +401,6 @@ class Article implements Page {
                        if ( !$this->mRevision ) {
                                wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " .
                                        $this->mPage->getLatest() . "\n" );
-                               wfProfileOut( __METHOD__ );
                                return false;
                        }
                }
@@ -420,16 +408,22 @@ class Article implements Page {
                // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
                // We should instead work with the Revision object when we need it...
                // Loads if user is allowed
-               $this->mContentObject = $this->mRevision->getContent(
+               $content = $this->mRevision->getContent(
                        Revision::FOR_THIS_USER,
                        $this->getContext()->getUser()
                );
+
+               if ( !$content ) {
+                       wfDebug( __METHOD__ . " failed to retrieve content of revision " .
+                               $this->mRevision->getId() . "\n" );
+                       return false;
+               }
+
+               $this->mContentObject = $content;
                $this->mRevIdFetched = $this->mRevision->getId();
 
                Hooks::run( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject ) );
 
-               wfProfileOut( __METHOD__ );
-
                return $this->mContentObject;
        }
 
@@ -480,8 +474,6 @@ class Article implements Page {
        public function view() {
                global $wgUseFileCache, $wgUseETag, $wgDebugToolbar, $wgMaxRedirects;
 
-               wfProfileIn( __METHOD__ );
-
                # Get variables from query string
                # As side effect this will load the revision and update the title
                # in a revision ID is passed in the request, so this should remain
@@ -493,7 +485,6 @@ class Article implements Page {
                $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
                if ( count( $permErrors ) ) {
                        wfDebug( __METHOD__ . ": denied on secondary read check\n" );
-                       wfProfileOut( __METHOD__ );
                        throw new PermissionsError( 'read', $permErrors );
                }
 
@@ -502,7 +493,6 @@ class Article implements Page {
                if ( $this->mRedirectUrl ) {
                        $outputPage->redirect( $this->mRedirectUrl );
                        wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
-                       wfProfileOut( __METHOD__ );
 
                        return;
                }
@@ -511,7 +501,6 @@ class Article implements Page {
                if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
                        wfDebug( __METHOD__ . ": showing diff page\n" );
                        $this->showDiffPage();
-                       wfProfileOut( __METHOD__ );
 
                        return;
                }
@@ -566,7 +555,6 @@ class Article implements Page {
                        # Is it client cached?
                        if ( $outputPage->checkLastModified( $timestamp ) ) {
                                wfDebug( __METHOD__ . ": done 304\n" );
-                               wfProfileOut( __METHOD__ );
 
                                return;
                        # Try file cache
@@ -575,7 +563,6 @@ class Article implements Page {
                                # tell wgOut that output is taken care of
                                $outputPage->disable();
                                $this->mPage->doViewUpdates( $user, $oldid );
-                               wfProfileOut( __METHOD__ );
 
                                return;
                        }
@@ -585,7 +572,7 @@ class Article implements Page {
                $useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid );
                wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
                if ( $user->getStubThreshold() ) {
-                       wfIncrStats( 'pcache_miss_stub' );
+                       $this->getContext()->getStats()->increment( 'pcache_miss_stub' );
                }
 
                $this->showRedirectedFromHeader();
@@ -608,7 +595,6 @@ class Article implements Page {
                                                wfDebug( __METHOD__ . ": showing missing article\n" );
                                                $this->showMissingArticle();
                                                $this->mPage->doViewUpdates( $user );
-                                               wfProfileOut( __METHOD__ );
                                                return;
                                        }
 
@@ -647,7 +633,6 @@ class Article implements Page {
 
                                                if ( !$this->showDeletedRevisionHeader() ) {
                                                        wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
-                                                       wfProfileOut( __METHOD__ );
                                                        return;
                                                }
                                        }
@@ -694,16 +679,14 @@ class Article implements Page {
                                                        $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
                                                }
                                                # Connection or timeout error
-                                               wfProfileOut( __METHOD__ );
                                                return;
                                        }
 
                                        $this->mParserOutput = $poolArticleView->getParserOutput();
                                        $outputPage->addParserOutput( $this->mParserOutput );
                                        if ( $content->getRedirectTarget() ) {
-                                               $outputPage->addSubtitle(
-                                                       "<span id=\"redirectsub\">" . wfMessage( 'redirectpagesub' )->parse() . "</span>"
-                                               );
+                                               $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
+                                                       $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
                                        }
 
                                        # Don't cache a dirty ParserOutput object
@@ -722,7 +705,7 @@ class Article implements Page {
                }
 
                # Get the ParserOutput actually *displayed* here.
-               # Note that $this->mParserOutput is the *current* version output.
+               # Note that $this->mParserOutput is the *current*/oldid version output.
                $pOutput = ( $outputDone instanceof ParserOutput )
                        ? $outputDone // object fetched by hook
                        : $this->mParserOutput;
@@ -753,7 +736,6 @@ class Article implements Page {
 
                $outputPage->addModules( 'mediawiki.action.view.postEdit' );
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -772,9 +754,8 @@ class Article implements Page {
         * Show a diff page according to current request variables. For use within
         * Article::view() only, other callers should use the DifferenceEngine class.
         *
-        * @todo Make protected
         */
-       public function showDiffPage() {
+       protected function showDiffPage() {
                $request = $this->getContext()->getRequest();
                $user = $this->getContext()->getUser();
                $diff = $request->getVal( 'diff' );
@@ -833,7 +814,7 @@ class Article implements Page {
 
                if ( $showCacheHint ) {
                        $dir = $this->getContext()->getLanguage()->getDir();
-                       $lang = $this->getContext()->getLanguage()->getCode();
+                       $lang = $this->getContext()->getLanguage()->getHtmlCode();
 
                        $outputPage->wrapWikiMsg(
                                "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
@@ -975,9 +956,10 @@ class Article implements Page {
         */
        public function showRedirectedFromHeader() {
                global $wgRedirectSources;
-               $outputPage = $this->getContext()->getOutput();
 
-               $request = $this->getContext()->getRequest();
+               $context = $this->getContext();
+               $outputPage = $context->getOutput();
+               $request = $context->getRequest();
                $rdfrom = $request->getVal( 'rdfrom' );
 
                // Construct a URL for the current page view, but with the target title
@@ -1002,7 +984,7 @@ class Article implements Page {
                                );
 
                                $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
-                                       wfMessage( 'redirectedfrom' )->rawParams( $redir )->parse()
+                                       $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
                                . "</span>" );
 
                                // Add the script to update the displayed URL and
@@ -1026,7 +1008,7 @@ class Article implements Page {
                        if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
                                $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
                                $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
-                                       wfMessage( 'redirectedfrom' )->rawParams( $redir )->parse()
+                                       $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
                                . "</span>" );
 
                                // Add the script to update the displayed URL
@@ -1098,8 +1080,6 @@ class Article implements Page {
                        return false;
                }
 
-               wfProfileIn( __METHOD__ );
-
                // New page patrol: Get the timestamp of the oldest revison which
                // the revision table holds for the given page. Then we look
                // whether it's within the RC lifespan and if it is, we try
@@ -1108,7 +1088,6 @@ class Article implements Page {
 
                // Check for cached results
                if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
@@ -1117,7 +1096,6 @@ class Article implements Page {
                ) {
                        // The current revision is already older than what could be in the RC table
                        // 6h tolerance because the RC might not be cleaned out regularly
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
@@ -1153,14 +1131,12 @@ class Article implements Page {
                        // Don't cache in case we can patrol as this could change
                        $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
 
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
-               if ( $rc->getPerformer()->getName() == $user->getName() ) {
+               if ( $rc->getPerformer()->equals( $user ) ) {
                        // Don't show a patrol link for own creations. If the user could
                        // patrol them, they already would be patrolled
-                       wfProfileOut( __METHOD__ );
                        return false;
                }
 
@@ -1190,7 +1166,6 @@ class Article implements Page {
                        '</div>'
                );
 
-               wfProfileOut( __METHOD__ );
                return true;
        }
 
@@ -1348,7 +1323,8 @@ class Article implements Page {
                        return;
                }
 
-               $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
+               $context = $this->getContext();
+               $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
 
                # Cascade unhide param in links for easy deletion browsing
                $extraParams = array();
@@ -1365,8 +1341,8 @@ class Article implements Page {
                $timestamp = $revision->getTimestamp();
 
                $current = ( $oldid == $this->mPage->getLatest() );
-               $language = $this->getContext()->getLanguage();
-               $user = $this->getContext()->getUser();
+               $language = $context->getLanguage();
+               $user = $context->getUser();
 
                $td = $language->userTimeAndDate( $timestamp, $user );
                $tddate = $language->userDate( $timestamp, $user );
@@ -1375,13 +1351,13 @@ class Article implements Page {
                # Show user links if allowed to see them. If hidden, then show them only if requested...
                $userlinks = Linker::revUserTools( $revision, !$unhide );
 
-               $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
+               $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
                        ? 'revision-info-current'
                        : 'revision-info';
 
-               $outputPage = $this->getContext()->getOutput();
+               $outputPage = $context->getOutput();
                $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" .
-                       wfMessage( $infomsg, $td )
+                       $context->msg( $infomsg, $td )
                                ->rawParams( $userlinks )
                                ->params( $revision->getID(), $tddate, $tdtime, $revision->getUserText() )
                                ->rawParams( Linker::revComment( $revision, true, true ) )
@@ -1390,18 +1366,18 @@ class Article implements Page {
                );
 
                $lnk = $current
-                       ? wfMessage( 'currentrevisionlink' )->escaped()
+                       ? $context->msg( 'currentrevisionlink' )->escaped()
                        : Linker::linkKnown(
                                $this->getTitle(),
-                               wfMessage( 'currentrevisionlink' )->escaped(),
+                               $context->msg( 'currentrevisionlink' )->escaped(),
                                array(),
                                $extraParams
                        );
                $curdiff = $current
-                       ? wfMessage( 'diff' )->escaped()
+                       ? $context->msg( 'diff' )->escaped()
                        : Linker::linkKnown(
                                $this->getTitle(),
-                               wfMessage( 'diff' )->escaped(),
+                               $context->msg( 'diff' )->escaped(),
                                array(),
                                array(
                                        'diff' => 'cur',
@@ -1412,30 +1388,30 @@ class Article implements Page {
                $prevlink = $prev
                        ? Linker::linkKnown(
                                $this->getTitle(),
-                               wfMessage( 'previousrevision' )->escaped(),
+                               $context->msg( 'previousrevision' )->escaped(),
                                array(),
                                array(
                                        'direction' => 'prev',
                                        'oldid' => $oldid
                                ) + $extraParams
                        )
-                       : wfMessage( 'previousrevision' )->escaped();
+                       : $context->msg( 'previousrevision' )->escaped();
                $prevdiff = $prev
                        ? Linker::linkKnown(
                                $this->getTitle(),
-                               wfMessage( 'diff' )->escaped(),
+                               $context->msg( 'diff' )->escaped(),
                                array(),
                                array(
                                        'diff' => 'prev',
                                        'oldid' => $oldid
                                ) + $extraParams
                        )
-                       : wfMessage( 'diff' )->escaped();
+                       : $context->msg( 'diff' )->escaped();
                $nextlink = $current
-                       ? wfMessage( 'nextrevision' )->escaped()
+                       ? $context->msg( 'nextrevision' )->escaped()
                        : Linker::linkKnown(
                                $this->getTitle(),
-                               wfMessage( 'nextrevision' )->escaped(),
+                               $context->msg( 'nextrevision' )->escaped(),
                                array(),
                                array(
                                        'direction' => 'next',
@@ -1443,10 +1419,10 @@ class Article implements Page {
                                ) + $extraParams
                        );
                $nextdiff = $current
-                       ? wfMessage( 'diff' )->escaped()
+                       ? $context->msg( 'diff' )->escaped()
                        : Linker::linkKnown(
                                $this->getTitle(),
-                               wfMessage( 'diff' )->escaped(),
+                               $context->msg( 'diff' )->escaped(),
                                array(),
                                array(
                                        'diff' => 'next',
@@ -1460,7 +1436,7 @@ class Article implements Page {
                }
 
                $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
-                       wfMessage( 'revision-nav' )->rawParams(
+                       $context->msg( 'revision-nav' )->rawParams(
                                $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
                        )->escaped() . "</div>" );
        }
@@ -1480,7 +1456,7 @@ class Article implements Page {
                $lang = $this->getTitle()->getPageLanguage();
                $out = $this->getContext()->getOutput();
                if ( $appendSubtitle ) {
-                       $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
+                       $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
                }
                $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
                return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
@@ -1516,8 +1492,9 @@ class Article implements Page {
                                ( $forceKnown ? array( 'known', 'noclasses' ) : array() )
                        ) . '</li>';
                }
+               $html .= '</ul>';
 
-               $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->text();
+               $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
 
                return '<div class="redirectMsg">' .
                        '<p>' . $redirectToText . '</p>' .
@@ -1624,7 +1601,7 @@ class Article implements Page {
                if ( !$reason ) {
                        try {
                                $reason = $this->generateReason( $hasHistory );
-                       } catch ( MWException $e ) {
+                       } catch ( Exception $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" );
@@ -1655,7 +1632,7 @@ class Article implements Page {
                                $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
                                $context->msg( 'word-separator' )->escaped() . Linker::linkKnown( $title,
                                        $context->msg( 'history' )->escaped(),
-                                       array( 'rel' => 'archives' ),
+                                       array(),
                                        array( 'action' => 'history' ) ) .
                                '</strong>'
                        );