Merge "Make showDiffPage() protected"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 17 Feb 2015 17:56:16 +0000 (17:56 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 17 Feb 2015 17:56:16 +0000 (17:56 +0000)
1  2 
includes/page/Article.php

@@@ -226,6 -226,7 +226,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
                        $content = $this->mContentObject;
                }
  
 -              wfProfileOut( __METHOD__ );
                return $content;
        }
  
                        return $this->mContent;
                }
  
 -              wfProfileIn( __METHOD__ );
 -
                $content = $this->fetchContentObject();
  
                if ( !$content ) {
 -                      wfProfileOut( __METHOD__ );
                        return false;
                }
  
                $this->mContent = ContentHandler::getContentText( $content );
                ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
  
 -              wfProfileOut( __METHOD__ );
 -
                return $this->mContent;
        }
  
                        return $this->mContentObject;
                }
  
 -              wfProfileIn( __METHOD__ );
 -
                $this->mContentLoaded = true;
                $this->mContent = null;
  
                                $this->mRevision = Revision::newFromId( $oldid );
                                if ( !$this->mRevision ) {
                                        wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
 -                                      wfProfileOut( __METHOD__ );
                                        return false;
                                }
                        }
                        if ( !$this->mPage->getLatest() ) {
                                wfDebug( __METHOD__ . " failed to find page data for title " .
                                        $this->getTitle()->getPrefixedText() . "\n" );
 -                              wfProfileOut( __METHOD__ );
                                return false;
                        }
  
                        if ( !$this->mRevision ) {
                                wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " .
                                        $this->mPage->getLatest() . "\n" );
 -                              wfProfileOut( __METHOD__ );
                                return false;
                        }
                }
                // @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;
        }
  
        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
                $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
                if ( count( $permErrors ) ) {
                        wfDebug( __METHOD__ . ": denied on secondary read check\n" );
 -                      wfProfileOut( __METHOD__ );
                        throw new PermissionsError( 'read', $permErrors );
                }
  
                if ( $this->mRedirectUrl ) {
                        $outputPage->redirect( $this->mRedirectUrl );
                        wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
 -                      wfProfileOut( __METHOD__ );
  
                        return;
                }
                if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
                        wfDebug( __METHOD__ . ": showing diff page\n" );
                        $this->showDiffPage();
 -                      wfProfileOut( __METHOD__ );
  
                        return;
                }
                        # Is it client cached?
                        if ( $outputPage->checkLastModified( $timestamp ) ) {
                                wfDebug( __METHOD__ . ": done 304\n" );
 -                              wfProfileOut( __METHOD__ );
  
                                return;
                        # Try file cache
                                # tell wgOut that output is taken care of
                                $outputPage->disable();
                                $this->mPage->doViewUpdates( $user, $oldid );
 -                              wfProfileOut( __METHOD__ );
  
                                return;
                        }
                                                wfDebug( __METHOD__ . ": showing missing article\n" );
                                                $this->showMissingArticle();
                                                $this->mPage->doViewUpdates( $user );
 -                                              wfProfileOut( __METHOD__ );
                                                return;
                                        }
  
  
                                                if ( !$this->showDeletedRevisionHeader() ) {
                                                        wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
 -                                                      wfProfileOut( __METHOD__ );
                                                        return;
                                                }
                                        }
                                                        $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
  
                $outputPage->addModules( 'mediawiki.action.view.postEdit' );
  
 -              wfProfileOut( __METHOD__ );
        }
  
        /**
         * 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' );
                        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
  
                // Check for cached results
                if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
 -                      wfProfileOut( __METHOD__ );
                        return false;
                }
  
                ) {
                        // 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;
                }
  
                        // 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;
                }
  
                        '</div>'
                );
  
 -              wfProfileOut( __METHOD__ );
                return true;
        }
  
                        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();
                $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 );
                # 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 ) )
                );
  
                $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',
                $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',
                                ) + $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',
                }
  
                $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>" );
        }
                $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 );
                                ( $forceKnown ? array( 'known', 'noclasses' ) : array() )
                        ) . '</li>';
                }
 +              $html .= '</ul>';
  
                $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->text();
  
                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" );