Made DifferenceEngine use a context instead of global variables and updaters calls...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 10 Nov 2011 13:06:52 +0000 (13:06 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 10 Nov 2011 13:06:52 +0000 (13:06 +0000)
includes/Article.php
includes/EditPage.php
includes/actions/RollbackAction.php
includes/api/ApiComparePages.php
includes/api/ApiQueryRevisions.php
includes/diff/DifferenceEngine.php
includes/specials/SpecialComparePages.php
includes/specials/SpecialUndelete.php

index b383a3b..71d6599 100644 (file)
@@ -613,7 +613,7 @@ class Article extends Page {
                $unhide = $wgRequest->getInt( 'unhide' ) == 1;
                $oldid = $this->getOldID();
 
-               $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
+               $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
                // DifferenceEngine directly fetched the revision:
                $this->mRevIdFetched = $de->mNewid;
                $de->showDiffPage( $diffOnly );
index ec92b70..c500a52 100644 (file)
@@ -2060,7 +2060,7 @@ HTML
                if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
                        $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
 
-                       $de = new DifferenceEngine( $this->mTitle );
+                       $de = new DifferenceEngine( $this->mArticle->getContext() );
                        $de->setText( $this->textbox2, $this->textbox1 );
                        $de->showDiff( wfMsgExt( 'yourtext', 'parseinline' ), wfMsg( 'storedversion' ) );
 
@@ -2329,7 +2329,7 @@ HTML
                $wgOut->addHTML( '</div>' );
 
                $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
-               $de = new DifferenceEngine( $this->mTitle );
+               $de = new DifferenceEngine( $this->mArticle->getContext() );
                $de->setText( $this->getContent(), $this->textbox2 );
                $de->showDiff( wfMsg( "storedversion" ), wfMsgExt( 'yourtext', 'parseinline' ) );
 
@@ -2737,7 +2737,7 @@ HTML
                $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
                $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
                if ( $oldtext !== false  || $newtext != '' ) {
-                       $de = new DifferenceEngine( $this->mTitle );
+                       $de = new DifferenceEngine( $this->mArticle->getContext() );
                        $de->setText( $oldtext, $newtext );
                        $difftext = $de->getDiff( $oldtitle, $newtitle );
                        $de->showDiffStyle();
index 1cc64b3..8379e27 100644 (file)
@@ -109,7 +109,7 @@ class RollbackAction extends FormlessAction {
                $this->getOutput()->returnToMain( false, $this->getTitle() );
 
                if ( !$request->getBool( 'hidediff', false ) && !$this->getUser()->getBoolOption( 'norollbackdiff', false ) ) {
-                       $de = new DifferenceEngine( $this->getTitle(), $current->getId(), $newId, false, true );
+                       $de = new DifferenceEngine( $this->getContext(), $current->getId(), $newId, false, true );
                        $de->showDiff( '', '' );
                }
        }
index 3609262..6c22f18 100644 (file)
@@ -35,7 +35,7 @@ class ApiComparePages extends ApiBase {
                $rev1 = $this->revisionOrTitle( $params['fromrev'], $params['fromtitle'] );
                $rev2 = $this->revisionOrTitle( $params['torev'], $params['totitle'] );
 
-               $de = new DifferenceEngine( null,
+               $de = new DifferenceEngine( $this->getContext(),
                        $rev1,
                        $rev2,
                        null, // rcid
index 807b201..435bfe7 100644 (file)
@@ -493,11 +493,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                        static $n = 0; // Number of uncached diffs we've had
                        if ( $n < $wgAPIMaxUncachedDiffs ) {
                                $vals['diff'] = array();
+                               $context = new DerivativeContext( $this->getContext() );
+                               $context->setTitle( $title );
                                if ( !is_null( $this->difftotext ) ) {
-                                       $engine = new DifferenceEngine( $title );
+                                       $engine = new DifferenceEngine( $context );
                                        $engine->setText( $text, $this->difftotext );
                                } else {
-                                       $engine = new DifferenceEngine( $title, $revision->getID(), $this->diffto );
+                                       $engine = new DifferenceEngine( $context, $revision->getID(), $this->diffto );
                                        $vals['diff']['from'] = $engine->getOldid();
                                        $vals['diff']['to'] = $engine->getNewid();
                                }
index 0203c02..5115343 100644 (file)
@@ -18,7 +18,7 @@ define( 'MW_DIFF_VERSION', '1.11a' );
  * @todo document
  * @ingroup DifferenceEngine
  */
-class DifferenceEngine {
+class DifferenceEngine extends ContextSource {
        /**#@+
         * @private
         */
@@ -29,7 +29,7 @@ class DifferenceEngine {
        /**
         * @var Title
         */
-       var $mOldPage, $mNewPage, $mTitle;
+       var $mOldPage, $mNewPage;
        var $mRcidMarkPatrolled;
 
        /**
@@ -60,22 +60,20 @@ class DifferenceEngine {
 
        /**
         * Constructor
-        * @param $titleObj Title object that the diff is associated with
+        * @param $context IContextSource context to use, anything else will be ignored
         * @param $old Integer old ID we want to show and diff with.
         * @param $new String either 'prev' or 'next'.
         * @param $rcid Integer ??? FIXME (default 0)
         * @param $refreshCache boolean If set, refreshes the diff cache
         * @param $unhide boolean If set, allow viewing deleted revs
         */
-       function __construct( $titleObj = null, $old = 0, $new = 0, $rcid = 0,
+       function __construct( $context = null, $old = 0, $new = 0, $rcid = 0,
                $refreshCache = false, $unhide = false )
        {
-               if ( $titleObj ) {
-                       $this->mTitle = $titleObj;
-               } else {
-                       global $wgTitle;
-                       $this->mTitle = $wgTitle; // @TODO: get rid of this
+               if ( $context instanceof IContextSource ) {
+                       $this->setContext( $context );
                }
+
                wfDebug( "DifferenceEngine old '$old' new '$new' rcid '$rcid'\n" );
 
                $this->mOldid = $old;
@@ -98,18 +96,11 @@ class DifferenceEngine {
        function getDiffLang() {
                if ( $this->mDiffLang === null ) {
                        # Default language in which the diff text is written.
-                       $this->mDiffLang = $this->mTitle->getPageLanguage();
+                       $this->mDiffLang = $this->getTitle()->getPageLanguage();
                }
                return $this->mDiffLang;
        }
 
-       /**
-        * @return Title
-        */
-       function getTitle() {
-               return $this->mTitle;
-       }
-
        /**
         * @return bool
         */
@@ -141,8 +132,7 @@ class DifferenceEngine {
         * @return mixed URL or false
         */
        function deletedLink( $id ) {
-               global $wgUser;
-               if ( $wgUser->isAllowed( 'deletedhistory' ) ) {
+               if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
                        $dbr = wfGetDB( DB_SLAVE );
                        $row = $dbr->selectRow('archive', '*',
                                array( 'ar_rev_id' => $id ),
@@ -175,42 +165,40 @@ class DifferenceEngine {
        }
 
        function showDiffPage( $diffOnly = false ) {
-               global $wgUser, $wgOut, $wgRequest;
                wfProfileIn( __METHOD__ );
 
                # Allow frames except in certain special cases
-               $wgOut->allowClickjacking();
-               $wgOut->setRobotPolicy( 'noindex,nofollow' );
+               $out = $this->getOutput();
+               $out->allowClickjacking();
+               $out->setRobotPolicy( 'noindex,nofollow' );
 
                if ( !$this->loadRevisionData() ) {
                        // Sounds like a deleted revision... Let's see what we can do.
-                       $t = $this->mTitle->getPrefixedText();
-                       $d = wfMsgExt( 'missingarticle-diff', array( 'escape' ),
+                       $t = $this->getTitle()->getPrefixedText();
+                       $d = $this->msg( 'missingarticle-diff',
                                $this->deletedIdMarker( $this->mOldid ),
-                               $this->deletedIdMarker( $this->mNewid ) );
-                       $wgOut->setPageTitle( wfMessage( 'errorpagetitle' ) );
-                       $wgOut->addWikiMsg( 'missing-article', "<nowiki>$t</nowiki>", "<span class='plainlinks'>$d</span>" );
+                               $this->deletedIdMarker( $this->mNewid ) )->escaped();
+                       $out->setPageTitle( $this->msg( 'errorpagetitle' ) );
+                       $out->addWikiMsg( 'missing-article', "<nowiki>$t</nowiki>", "<span class='plainlinks'>$d</span>" );
                        wfProfileOut( __METHOD__ );
                        return;
                }
 
-               $permErrors = $this->mNewPage->getUserPermissionsErrors( 'read', $wgUser );
+               $user = $this->getUser();
+               $permErrors = $this->mNewPage->getUserPermissionsErrors( 'read', $user );
                if ( $this->mOldPage ) { # mOldPage might not be set, see below.
                        $permErrors = wfMergeErrorArrays( $permErrors,
-                               $this->mOldPage->getUserPermissionsErrors( 'read', $wgUser ) );
+                               $this->mOldPage->getUserPermissionsErrors( 'read', $user ) );
                }
                if ( count( $permErrors ) ) {
                        wfProfileOut( __METHOD__ );
                        throw new PermissionsError( 'read', $permErrors );
                }
 
-               /// @todo Make RequestContext::getMain() go away when we have a context available
-               $context = RequestContext::getMain();
-
                # If external diffs are enabled both globally and for the user,
                # we'll use the application/x-external-editor interface to call
                # an external diff tool like kompare, kdiff3, etc.
-               if ( ExternalEdit::useExternalEngine( $context, 'diff' ) ) {
+               if ( ExternalEdit::useExternalEngine( $this->getContext(), 'diff' ) ) {
                        $urls = array(
                                'File' => array( 'Extension' => 'wiki', 'URL' =>
                                        # This should be mOldPage, but it may not be set, see below.
@@ -223,7 +211,7 @@ class DifferenceEngine {
                                ),
                        );
 
-                       $externalEditor = new ExternalEdit( $context, $urls );
+                       $externalEditor = new ExternalEdit( $this->getContext(), $urls );
                        $externalEditor->execute();
 
                        wfProfileOut( __METHOD__ );
@@ -235,7 +223,7 @@ class DifferenceEngine {
 
                $query = array();
                # Carry over 'diffonly' param via navigation links
-               if ( $diffOnly != $wgUser->getBoolOption( 'diffonly' ) ) {
+               if ( $diffOnly != $user->getBoolOption( 'diffonly' ) ) {
                        $query['diffonly'] = $diffOnly;
                }
                # Cascade unhide param in links for easy deletion browsing
@@ -245,47 +233,50 @@ class DifferenceEngine {
 
                # Check if one of the revisions is deleted/suppressed
                $deleted = $suppressed = false;
-               $allowed = $this->mNewRev->userCan( Revision::DELETED_TEXT );
+               $allowed = $this->mNewRev->userCan( Revision::DELETED_TEXT, $user );
 
                # mOldRev is false if the difference engine is called with a "vague" query for
                # a diff between a version V and its previous version V' AND the version V
                # is the first version of that article. In that case, V' does not exist.
                if ( $this->mOldRev === false ) {
-                       $wgOut->setPageTitle( $this->mNewPage->getPrefixedText() );
-                       $wgOut->addSubtitle( wfMessage( 'difference' ) );
+                       $out->setPageTitle( $this->mNewPage->getPrefixedText() );
+                       $out->addSubtitle( $this->msg( 'difference' ) );
                        $samePage = true;
                        $oldHeader = '';
                } else {
                        wfRunHooks( 'DiffViewHeader', array( $this, $this->mOldRev, $this->mNewRev ) );
 
-                       $sk = $wgUser->getSkin();
+                       $sk = $this->getSkin();
                        if ( method_exists( $sk, 'suppressQuickbar' ) ) {
                                $sk->suppressQuickbar();
                        }
 
                        if ( $this->mNewPage->equals( $this->mOldPage ) ) {
-                               $wgOut->setPageTitle( $this->mNewPage->getPrefixedText() );
-                               $wgOut->addSubtitle( wfMessage( 'difference' ) );
+                               $out->setPageTitle( $this->mNewPage->getPrefixedText() );
+                               $out->addSubtitle( $this->msg( 'difference' ) );
                                $samePage = true;
                        } else {
-                               $wgOut->setPageTitle( $this->mOldPage->getPrefixedText() . ', ' . $this->mNewPage->getPrefixedText() );
-                               $wgOut->addSubtitle( wfMessage( 'difference-multipage' ) );
+                               $out->setPageTitle( $this->mOldPage->getPrefixedText() . ', ' . $this->mNewPage->getPrefixedText() );
+                               $out->addSubtitle( $this->msg( 'difference-multipage' ) );
                                $samePage = false;
                        }
 
-                       if ( $samePage && $this->mNewPage->userCan( 'edit' ) ) {
-                               if ( $this->mNewRev->isCurrent() && $this->mNewPage->userCan( 'rollback' ) ) {
-                                       $wgOut->preventClickjacking();
+                       if ( $samePage && $this->mNewPage->userCan( 'edit', $user ) ) {
+                               if ( $this->mNewRev->isCurrent() && $this->mNewPage->userCan( 'rollback', $user ) ) {
+                                       $out->preventClickjacking();
                                        $rollback = '&#160;&#160;&#160;' . Linker::generateRollback( $this->mNewRev );
                                }
                                if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) && !$this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
-                                       $undoLink = ' ' . wfMsgHtml( 'parentheses', Html::element( 'a', array(
-                                               'href' => $this->mNewPage->getLocalUrl( array(
-                                                       'action' => 'edit',
-                                                       'undoafter' => $this->mOldid,
-                                                       'undo' => $this->mNewid ) ),
-                                               'title' => Linker::titleAttrib( 'undo' )
-                                       ), wfMsg( 'editundo' ) ) );
+                                       $undoLink = ' ' . $this->msg( 'parentheses' )->rawParams(
+                                               Html::element( 'a', array(
+                                                       'href' => $this->mNewPage->getLocalUrl( array(
+                                                               'action' => 'edit',
+                                                               'undoafter' => $this->mOldid,
+                                                               'undo' => $this->mNewid ) ),
+                                                       'title' => Linker::titleAttrib( 'undo' )
+                                               ),
+                                               $this->msg( 'editundo' )->text()
+                                       ) )->escaped();
                                }
                        }
 
@@ -293,7 +284,7 @@ class DifferenceEngine {
                        if ( $samePage && $this->mOldRev->getPrevious() ) {
                                $prevlink = Linker::linkKnown(
                                        $this->mOldPage,
-                                       wfMsgHtml( 'previousdiff' ),
+                                       $this->msg( 'previousdiff' )->escaped(),
                                        array( 'id' => 'differences-prevlink' ),
                                        array( 'diff' => 'prev', 'oldid' => $this->mOldid ) + $query
                                );
@@ -325,7 +316,7 @@ class DifferenceEngine {
                        }
 
                        # Check if this user can see the revisions
-                       if ( !$this->mOldRev->userCan( Revision::DELETED_TEXT ) ) {
+                       if ( !$this->mOldRev->userCan( Revision::DELETED_TEXT, $user ) ) {
                                $allowed = false;
                        }
                }
@@ -335,7 +326,7 @@ class DifferenceEngine {
                if ( $samePage && !$this->mNewRev->isCurrent() ) {
                        $nextlink = Linker::linkKnown(
                                $this->mNewPage,
-                               wfMsgHtml( 'nextdiff' ),
+                               $this->msg( 'nextdiff' )->escaped(),
                                array( 'id' => 'differences-nextlink' ),
                                array( 'diff' => 'next', 'oldid' => $this->mNewid ) + $query
                        );
@@ -371,17 +362,17 @@ class DifferenceEngine {
                if ( $deleted && ( !$this->unhide || !$allowed ) ) {
                        $this->showDiffStyle();
                        $multi = $this->getMultiNotice();
-                       $wgOut->addHTML( $this->addHeader( '', $oldHeader, $newHeader, $multi ) );
+                       $out->addHTML( $this->addHeader( '', $oldHeader, $newHeader, $multi ) );
                        if ( !$allowed ) {
                                $msg = $suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff';
                                # Give explanation for why revision is not visible
-                               $wgOut->wrapWikiMsg( "<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n",
+                               $out->wrapWikiMsg( "<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n",
                                        array( $msg ) );
                        } else {
                                # Give explanation and add a link to view the diff...
-                               $link = $this->mTitle->getFullUrl( $wgRequest->appendQueryValue( 'unhide', '1', true ) );
+                               $link = $this->getTitle()->getFullUrl( $this->getRequest()->appendQueryValue( 'unhide', '1', true ) );
                                $msg = $suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff';
-                               $wgOut->wrapWikiMsg( "<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n", array( $msg, $link ) );
+                               $out->wrapWikiMsg( "<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n", array( $msg, $link ) );
                        }
                # Otherwise, output a regular diff...
                } else {
@@ -389,7 +380,7 @@ class DifferenceEngine {
                        $notice = '';
                        if ( $deleted ) {
                                $msg = $suppressed ? 'rev-suppressed-diff-view' : 'rev-deleted-diff-view';
-                               $notice = "<div id='mw-$msg' class='mw-warning plainlinks'>\n" . wfMsgExt( $msg, 'parseinline' ) . "</div>\n";
+                               $notice = "<div id='mw-$msg' class='mw-warning plainlinks'>\n" . $this->msg( $msg )->parse() . "</div>\n";
                        }
                        $this->showDiff( $oldHeader, $newHeader, $notice );
                        if ( !$diffOnly ) {
@@ -408,11 +399,11 @@ class DifferenceEngine {
         * @return String
         */
        protected function markPatrolledLink() {
-               global $wgUseRCPatrol, $wgUser, $wgOut;
+               global $wgUseRCPatrol;
 
                if ( $this->mMarkPatrolledLink === null ) {
                        // Prepare a change patrol link, if applicable
-                       if ( $wgUseRCPatrol && $this->mNewPage->userCan( 'patrol' ) ) {
+                       if ( $wgUseRCPatrol && $this->mNewPage->userCan( 'patrol', $this->getUser() ) ) {
                                // If we've been given an explicit change identifier, use it; saves time
                                if ( $this->mRcidMarkPatrolled ) {
                                        $rcid = $this->mRcidMarkPatrolled;
@@ -443,11 +434,11 @@ class DifferenceEngine {
                                }
                                // Build the link
                                if ( $rcid ) {
-                                       $wgOut->preventClickjacking();
-                                       $token = $wgUser->editToken( $rcid );
+                                       $this->getOutput()->preventClickjacking();
+                                       $token = $this->getUser()->editToken( $rcid );
                                        $this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
                                                $this->mNewPage,
-                                               wfMsgHtml( 'markaspatrolleddiff' ),
+                                               $this->msg( 'markaspatrolleddiff' )->escaped(),
                                                array(),
                                                array(
                                                        'action' => 'markpatrolled',
@@ -471,14 +462,14 @@ class DifferenceEngine {
         * @return String
         */
        protected function revisionDeleteLink( $rev ) {
-               global $wgUser;
                $link = '';
-               $canHide = $wgUser->isAllowed( 'deleterevision' );
+               $user = $this->getUser();
+               $canHide = $user->isAllowed( 'deleterevision' );
                // Show del/undel link if:
                // (a) the user can delete revisions, or
                // (b) the user can view deleted revision *and* this one is deleted
-               if ( $canHide || ( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
-                       if ( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
+               if ( $canHide || ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
+                       if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
                                $link = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
                        } else {
                                $query = array(
@@ -498,74 +489,73 @@ class DifferenceEngine {
         * Show the new revision of the page.
         */
        function renderNewRevision() {
-               global $wgOut;
                wfProfileIn( __METHOD__ );
+               $out = $this->getOutput();
                $revHeader = $this->getRevisionHeader( $this->mNewRev );
                # Add "current version as of X" title
-               $wgOut->addHTML( "<hr class='diff-hr' />
+               $out->addHTML( "<hr class='diff-hr' />
                <h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
                # Page content may be handled by a hooked call instead...
-               if ( wfRunHooks( 'ArticleContentOnDiff', array( $this, $wgOut ) ) ) {
+               if ( wfRunHooks( 'ArticleContentOnDiff', array( $this, $out ) ) ) {
                        # Use the current version parser cache if applicable
                        $pCache = true;
                        if ( !$this->mNewRev->isCurrent() ) {
-                               $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false );
+                               $oldEditSectionSetting = $out->parserOptions()->setEditSection( false );
                                $pCache = false;
                        }
 
                        $this->loadNewText();
-                       $wgOut->setRevisionId( $this->mNewRev->getId() );
-                       $wgOut->setArticleFlag( true );
+                       $out->setRevisionId( $this->mNewRev->getId() );
+                       $out->setArticleFlag( true );
 
                        if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) {
                                // Stolen from Article::view --AG 2007-10-11
                                // Give hooks a chance to customise the output
                                // @TODO: standardize this crap into one function
-                               if ( wfRunHooks( 'ShowRawCssJs', array( $this->mNewtext, $this->mNewPage, $wgOut ) ) ) {
+                               if ( wfRunHooks( 'ShowRawCssJs', array( $this->mNewtext, $this->mNewPage, $out ) ) ) {
                                        // Wrap the whole lot in a <pre> and don't parse
                                        $m = array();
                                        preg_match( '!\.(css|js)$!u', $this->mNewPage->getText(), $m );
-                                       $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
-                                       $wgOut->addHTML( htmlspecialchars( $this->mNewtext ) );
-                                       $wgOut->addHTML( "\n</pre>\n" );
+                                       $out->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
+                                       $out->addHTML( htmlspecialchars( $this->mNewtext ) );
+                                       $out->addHTML( "\n</pre>\n" );
                                }
                        } elseif ( $pCache ) {
-                               $article = new Article( $this->mNewPage, 0 );
-                               $pOutput = ParserCache::singleton()->get( $article, $wgOut->parserOptions() );
+                               $wikipage = WikiPage::factory( $this->mNewPage );
+                               $pOutput = ParserCache::singleton()->get( $wikipage, $out->parserOptions() );
                                if( $pOutput ) {
-                                       $wgOut->addParserOutput( $pOutput );
+                                       $out->addParserOutput( $pOutput );
                                } else {
-                                       $article->doViewParse();
+                                       $out->addWikiTextTidy( $this->mNewtext );
                                }
                        } else {
-                               $wgOut->addWikiTextTidy( $this->mNewtext );
+                               $out->addWikiTextTidy( $this->mNewtext );
                        }
 
                        if ( !$this->mNewRev->isCurrent() ) {
-                               $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
+                               $out->parserOptions()->setEditSection( $oldEditSectionSetting );
                        }
                }
                # Add redundant patrol link on bottom...
-               $wgOut->addHTML( $this->markPatrolledLink() );
+               $out->addHTML( $this->markPatrolledLink() );
 
                wfProfileOut( __METHOD__ );
        }
 
        /**
-        * Get the diff text, send it to $wgOut
+        * Get the diff text, send it to the OutputPage object
         * Returns false if the diff could not be generated, otherwise returns true
         *
         * @return bool
         */
        function showDiff( $otitle, $ntitle, $notice = '' ) {
-               global $wgOut;
                $diff = $this->getDiff( $otitle, $ntitle, $notice );
                if ( $diff === false ) {
-                       $wgOut->addWikiMsg( 'missing-article', "<nowiki>(fixme, bug)</nowiki>", '' );
+                       $this->getOutput()->addWikiMsg( 'missing-article', "<nowiki>(fixme, bug)</nowiki>", '' );
                        return false;
                } else {
                        $this->showDiffStyle();
-                       $wgOut->addHTML( $diff );
+                       $this->getOutput()->addHTML( $diff );
                        return true;
                }
        }
@@ -574,8 +564,7 @@ class DifferenceEngine {
         * Add style sheets and supporting JS for diff display.
         */
        function showDiffStyle() {
-               global $wgOut;
-               $wgOut->addModuleStyles( 'mediawiki.action.history.diff' );
+               $this->getOutput()->addModuleStyles( 'mediawiki.action.history.diff' );
        }
 
        /**
@@ -609,10 +598,10 @@ class DifferenceEngine {
                if ( !$this->loadRevisionData() ) {
                        wfProfileOut( __METHOD__ );
                        return false;
-               } elseif ( $this->mOldRev && !$this->mOldRev->userCan( Revision::DELETED_TEXT ) ) {
+               } elseif ( $this->mOldRev && !$this->mOldRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
                        wfProfileOut( __METHOD__ );
                        return false;
-               } elseif ( $this->mNewRev && !$this->mNewRev->userCan( Revision::DELETED_TEXT ) ) {
+               } elseif ( $this->mNewRev && !$this->mNewRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
                        wfProfileOut( __METHOD__ );
                        return false;
                }
@@ -794,9 +783,8 @@ class DifferenceEngine {
        }
 
        function localiseLineNumbersCb( $matches ) {
-               global $wgLang;
                if ( $matches[1] === '1' && $this->mReducedLineNumbers ) return '';
-               return wfMsgExt( 'lineno', 'escape', $wgLang->formatNum( $matches[1] ) );
+               return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
        }
 
 
@@ -837,15 +825,13 @@ class DifferenceEngine {
         * @return string
         */
        public static function intermediateEditsMsg( $numEdits, $numUsers, $limit ) {
-               global $wgLang;
                if ( $numUsers > $limit ) {
                        $msg = 'diff-multi-manyusers';
                        $numUsers = $limit;
                } else {
                        $msg = 'diff-multi';
                }
-               return wfMsgExt( $msg, 'parseinline',
-                       $wgLang->formatnum( $numEdits ), $wgLang->formatnum( $numUsers ) );
+               return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
        }
 
        /**
@@ -857,19 +843,19 @@ class DifferenceEngine {
         * @return String HTML fragment
         */
        private function getRevisionHeader( Revision $rev, $complete = '' ) {
-               global $wgLang;
-
+               $lang = $this->getLang();
+               $user = $this->getUser();
                $revtimestamp = $rev->getTimestamp();
-               $timestamp = $wgLang->timeanddate( $revtimestamp, true );
-               $dateofrev = $wgLang->date( $revtimestamp, true );
-               $timeofrev = $wgLang->time( $revtimestamp, true );
+               $timestamp = $lang->userTimeAndDate( $revtimestamp, $user );
+               $dateofrev = $lang->userDate( $revtimestamp, $user );
+               $timeofrev = $lang->userTime( $revtimestamp, $user );
 
-               $header = htmlspecialchars( wfMsg(
+               $header = $this->msg(
                        $rev->isCurrent() ? 'currentrev-asof' : 'revisionasof',
                        $timestamp,
                        $dateofrev,
                        $timeofrev
-               ) );
+               )->escaped();
 
                if ( $complete !== 'complete' ) {
                        return $header;
@@ -880,13 +866,13 @@ class DifferenceEngine {
                $header = Linker::linkKnown( $title, $header, array(),
                        array( 'oldid' => $rev->getID() ) );
 
-               if ( $rev->userCan( Revision::DELETED_TEXT ) ) {
+               if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) {
                        $editQuery = array( 'action' => 'edit' );
                        if ( !$rev->isCurrent() ) {
                                $editQuery['oldid'] = $rev->getID();
                        }
 
-                       $msg = wfMsgHtml( $title->userCan( 'edit' ) ? 'editold' : 'viewsourceold' );
+                       $msg = $this->msg( $title->userCan( 'edit', $user ) ? 'editold' : 'viewsourceold' )->escaped();
                        $header .= ' (' . Linker::linkKnown( $title, $msg, array(), $editQuery ) . ')';
                        if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
                                $header = Html::rawElement( 'span', array( 'class' => 'history-deleted' ), $header );
@@ -981,12 +967,12 @@ class DifferenceEngine {
                        # Show diff between revision $old and the previous one.
                        # Get previous one from DB.
                        $this->mNewid = intval( $old );
-                       $this->mOldid = $this->mTitle->getPreviousRevisionID( $this->mNewid );
+                       $this->mOldid = $this->getTitle()->getPreviousRevisionID( $this->mNewid );
                } elseif ( $new === 'next' ) {
                        # Show diff between revision $old and the next one.
                        # Get next one from DB.
                        $this->mOldid = intval( $old );
-                       $this->mNewid = $this->mTitle->getNextRevisionID( $this->mOldid );
+                       $this->mNewid = $this->getTitle()->getNextRevisionID( $this->mOldid );
                        if ( $this->mNewid === false ) {
                                # if no result, NewId points to the newest old revision. The only newer
                                # revision is cur, which is "0".
@@ -995,7 +981,7 @@ class DifferenceEngine {
                } else {
                        $this->mOldid = intval( $old );
                        $this->mNewid = intval( $new );
-                       wfRunHooks( 'NewDifferenceEngine', array( &$this->mTitle, &$this->mOldid, &$this->mNewid, $old, $new ) );
+                       wfRunHooks( 'NewDifferenceEngine', array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new ) );
                }
        }
 
@@ -1024,7 +1010,7 @@ class DifferenceEngine {
                // Load the new revision object
                $this->mNewRev = $this->mNewid
                        ? Revision::newFromId( $this->mNewid )
-                       : Revision::newFromTitle( $this->mTitle );
+                       : Revision::newFromTitle( $this->getTitle() );
 
                if ( !$this->mNewRev instanceof Revision ) {
                        return false;
index 0fa1391..1efb5bf 100644 (file)
@@ -111,7 +111,7 @@ class SpecialComparePages extends SpecialPage {
                $rev2 = self::revOrTitle( $data['Revision2'], $data['Page2'] );
 
                if( $rev1 && $rev2 ) {
-                       $de = new DifferenceEngine( null,
+                       $de = new DifferenceEngine( $this->getContext(),
                                $rev1,
                                $rev2,
                                null, // rcid
index dc509ec..4bf404f 100644 (file)
@@ -887,7 +887,7 @@ class SpecialUndelete extends SpecialPage {
         * @return String: HTML
         */
        function showDiff( $previousRev, $currentRev ) {
-               $diffEngine = new DifferenceEngine( $previousRev->getTitle() );
+               $diffEngine = new DifferenceEngine( $this->getContext() );
                $diffEngine->showDiffStyle();
                $this->getOutput()->addHTML(
                        "<div>" .