From 026e8534c69f65b889fbf64a608af1a37cdbf3a3 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Thu, 5 Jul 2012 23:07:58 +0200 Subject: [PATCH] Add a context parameter to Liker::generateRollback() and Linker::buildRollbackLink() and updated callers. This allows both methods to not always rely on global object, but also to use the local context when possible. Change-Id: Id10f55ed9b18c889afd8d9937d9f35acb376cce4 --- includes/Linker.php | 26 +++++++++++++++------- includes/actions/HistoryAction.php | 2 +- includes/diff/DifferenceEngine.php | 2 +- includes/specials/SpecialContributions.php | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 674eee71a1..526ad0c9ce 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1646,11 +1646,17 @@ class Linker { * other users. * * @param $rev Revision object + * @param $context IContextSource context to use or null for the main context. * @return string */ - public static function generateRollback( $rev ) { + public static function generateRollback( $rev, IContextSource $context = null ) { + if ( $context === null ) { + $context = RequestContext::getMain(); + } + return '' - . wfMessage( 'brackets' )->rawParams( self::buildRollbackLink( $rev ) )->plain() + . $context->msg( 'brackets' )->rawParams( + self::buildRollbackLink( $rev, $context ) )->plain() . ''; } @@ -1658,24 +1664,28 @@ class Linker { * Build a raw rollback link, useful for collections of "tool" links * * @param $rev Revision object + * @param $context IContextSource context to use or null for the main context. * @return String: HTML fragment */ - public static function buildRollbackLink( $rev ) { - global $wgRequest, $wgUser; + public static function buildRollbackLink( $rev, IContextSource $context = null ) { + if ( $context === null ) { + $context = RequestContext::getMain(); + } + $title = $rev->getTitle(); $query = array( 'action' => 'rollback', 'from' => $rev->getUserText(), - 'token' => $wgUser->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ), + 'token' => $context->getUser()->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ), ); - if ( $wgRequest->getBool( 'bot' ) ) { + if ( $context->getRequest()->getBool( 'bot' ) ) { $query['bot'] = '1'; $query['hidediff'] = '1'; // bug 15999 } return self::link( $title, - wfMsgHtml( 'rollbacklink' ), - array( 'title' => wfMsg( 'tooltip-rollback' ) ), + $context->msg( 'rollbacklink' )->escaped(), + array( 'title' => $context->msg( 'tooltip-rollback' )->text() ), $query, array( 'known', 'noclasses' ) ); diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 0c5560a808..6f48cd00e2 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -647,7 +647,7 @@ class HistoryPager extends ReverseChronologicalPager { if ( $latest && !count( $this->getTitle()->getUserPermissionsErrors( 'rollback', $this->getUser() ) ) ) { $this->preventClickjacking(); $tools[] = '' . - Linker::buildRollbackLink( $rev ) . ''; + Linker::buildRollbackLink( $rev, $this->getContext() ) . ''; } if ( !$rev->isDeleted( Revision::DELETED_TEXT ) diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index eb3a319fe4..08154c7b65 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -278,7 +278,7 @@ class DifferenceEngine extends ContextSource { if ( $samePage && $this->mNewPage->quickUserCan( 'edit', $user ) ) { if ( $this->mNewRev->isCurrent() && $this->mNewPage->userCan( 'rollback', $user ) ) { $out->preventClickjacking(); - $rollback = '   ' . Linker::generateRollback( $this->mNewRev ); + $rollback = '   ' . Linker::generateRollback( $this->mNewRev, $this->getContext() ); } if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) && !$this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) { $undoLink = ' ' . $this->msg( 'parentheses' )->rawParams( diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 6162ba4a5f..e8223e8e85 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -850,7 +850,7 @@ class ContribsPager extends ReverseChronologicalPager { && $page->quickUserCan( 'edit', $user ) ) { $this->preventClickjacking(); - $topmarktext .= ' ' . Linker::generateRollback( $rev ); + $topmarktext .= ' ' . Linker::generateRollback( $rev, $this->getContext() ); } } # Is there a visible previous revision? -- 2.20.1