* @todo document
* @ingroup DifferenceEngine
*/
-class DifferenceEngine {
+class DifferenceEngine extends ContextSource {
/**#@+
* @private
*/
/**
* @var Title
*/
- var $mOldPage, $mNewPage, $mTitle;
+ var $mOldPage, $mNewPage;
var $mRcidMarkPatrolled;
/**
/**
* 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;
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
*/
* @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 ),
}
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.
),
);
- $externalEditor = new ExternalEdit( $context, $urls );
+ $externalEditor = new ExternalEdit( $this->getContext(), $urls );
$externalEditor->execute();
wfProfileOut( __METHOD__ );
$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
# 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 = '   ' . 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();
}
}
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
);
}
# 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;
}
}
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
);
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 {
$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 ) {
* @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;
}
// 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',
* @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(
* 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;
}
}
* 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' );
}
/**
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;
}
}
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();
}
* @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();
}
/**
* @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;
$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 );
# 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".
} 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 ) );
}
}
// 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;