jenkins-bot has submitted this change and it was merged.
Change subject: More degloblization
......................................................................
More degloblization
Change-Id: If57556243b428faf987ba320d6438528746904e0
---
M MediaWikiMessageChecker.php
M MessageChecks.php
M api/ApiAggregateGroups.php
M api/ApiGroupReview.php
M api/ApiHardMessages.php
M api/ApiTranslateSandbox.php
M api/ApiTranslationReview.php
M ffs/MediaWikiComplexMessages.php
M scripts/createCheckIndex.php
M scripts/fuzzy.php
M scripts/sync-group.php
M specials/SpecialTranslate.php
M tag/PageTranslationHooks.php
M tag/TranslateDeleteJob.php
M tag/TranslateMoveJob.php
M tests/api/ApiTokensTest.php
M utils/JsSelectToInput.php
M utils/MessageTable.php
M utils/MessageWebImporter.php
M utils/RcFilter.php
M utils/StatsTable.php
M utils/TranslationEditPage.php
M utils/TranslationHelpers.php
M utils/UserToggles.php
24 files changed, 185 insertions(+), 188 deletions(-)
Approvals:
Nikerabbit: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MediaWikiMessageChecker.php b/MediaWikiMessageChecker.php
index c83891a..7002b29 100644
--- a/MediaWikiMessageChecker.php
+++ b/MediaWikiMessageChecker.php
@@ -338,17 +338,13 @@
$defCount = count( $defArray );
$traCount = count( $traArray );
if ( $defCount !== $traCount ) {
- global $wgLang;
-
$warnings[$key][] = array(
array( 'miscmw', $subcheck,
$key, $code ),
'translate-checks-format',
- wfMessage(
-
'translate-checks-parametersnotequal',
- $wgLang->formatNum(
$traCount ),
- $wgLang->formatNum(
$defCount )
- )->text()
+ wfMessage(
'translate-checks-parametersnotequal' )
+ ->numParams( $traCount,
$defCount )->text()
);
+
continue;
}
diff --git a/MessageChecks.php b/MessageChecks.php
index 8ae1362..27a2c97 100644
--- a/MessageChecks.php
+++ b/MessageChecks.php
@@ -223,7 +223,7 @@
* @return array List of warning messages with parameters.
*/
protected function fixMessageParams( $warnings ) {
- global $wgLang;
+ $lang = RequestContext::getMain()->getLanguage();
foreach ( $warnings as $wkey => $warning ) {
array_shift( $warning );
@@ -235,9 +235,9 @@
} else {
list( $type, $value ) = $param;
if ( $type === 'COUNT' ) {
- $message[] =
$wgLang->formatNum( $value );
+ $message[] = $lang->formatNum(
$value );
} elseif ( $type === 'PARAMS' ) {
- $message[] =
$wgLang->commaList( $value );
+ $message[] = $lang->commaList(
$value );
} else {
throw new MWException( "Unknown
type $type" );
}
diff --git a/api/ApiAggregateGroups.php b/api/ApiAggregateGroups.php
index 5f20f25..ed85c68 100644
--- a/api/ApiAggregateGroups.php
+++ b/api/ApiAggregateGroups.php
@@ -20,9 +20,7 @@
protected static $salt = 'translate-manage';
public function execute() {
- global $wgUser;
-
- if ( !$wgUser->isallowed( self::$right ) ) {
+ if ( !$this->getUser()->isallowed( self::$right ) ) {
$this->dieUsage( 'Permission denied',
'permissiondenied' );
}
@@ -68,7 +66,7 @@
TranslateMetadata::setSubgroups( $aggregateGroup,
$subgroups );
- $logparams = array(
+ $logParams = array(
'aggregategroup' => TranslateMetadata::get(
$aggregateGroup, 'name' ),
'aggregategroup-id' => $aggregateGroup,
);
@@ -80,11 +78,11 @@
$title = $group ? $group->getTitle() :
Title::newFromText( "Special:Translate/$subgroupId" );
$entry = new ManualLogEntry( 'pagetranslation', $action
);
- $entry->setPerformer( $wgUser );
+ $entry->setPerformer( $this->getUser() );
$entry->setTarget( $title );
// @todo
// $entry->setComment( $comment );
- $entry->setParameters( $logparams );
+ $entry->setParameters( $logParams );
$logid = $entry->insert();
$entry->publish( $logid );
@@ -230,12 +228,12 @@
}
public static function getToken() {
- global $wgUser;
- if ( !$wgUser->isAllowed( self::$right ) ) {
+ $user = RequestContext::getMain()->getUser();
+ if ( !$user->isAllowed( self::$right ) ) {
return false;
}
- return $wgUser->getEditToken( self::$salt );
+ return $user->getEditToken( self::$salt );
}
public static function injectTokenFunction( &$list ) {
diff --git a/api/ApiGroupReview.php b/api/ApiGroupReview.php
index ffd8a56..d447517 100644
--- a/api/ApiGroupReview.php
+++ b/api/ApiGroupReview.php
@@ -190,12 +190,12 @@
}
public static function getToken() {
- global $wgUser;
- if ( !$wgUser->isAllowed( self::$right ) ) {
+ $user = RequestContext::getMain()->getUser();
+ if ( !$user->isAllowed( self::$right ) ) {
return false;
}
- return $wgUser->getEditToken( self::$salt );
+ return $user->getEditToken( self::$salt );
}
public static function injectTokenFunction( &$list ) {
diff --git a/api/ApiHardMessages.php b/api/ApiHardMessages.php
index db7b4eb..20b2ea6 100644
--- a/api/ApiHardMessages.php
+++ b/api/ApiHardMessages.php
@@ -162,12 +162,12 @@
}
public static function getToken() {
- global $wgUser;
- if ( !$wgUser->isAllowed( self::$right ) ) {
+ $user = RequestContext::getMain()->getUser();
+ if ( !$user->isAllowed( self::$right ) ) {
return false;
}
- return $wgUser->getEditToken();
+ return $user->getEditToken();
}
public static function injectTokenFunction( &$list ) {
diff --git a/api/ApiTranslateSandbox.php b/api/ApiTranslateSandbox.php
index 995e6e6..833b0fa 100644
--- a/api/ApiTranslateSandbox.php
+++ b/api/ApiTranslateSandbox.php
@@ -138,10 +138,9 @@
}
public static function getToken() {
- global $wgUser;
-
// Who designed this?!?!?!
- return $wgUser->getEditToken( 'sandbox' );
+ $user = RequestContext::getMain()->getUser();
+ return $user->getEditToken( 'sandbox' );
}
public function getAllowedParams() {
diff --git a/api/ApiTranslationReview.php b/api/ApiTranslationReview.php
index 62be3d7..226b018 100644
--- a/api/ApiTranslationReview.php
+++ b/api/ApiTranslationReview.php
@@ -194,12 +194,12 @@
}
public static function getToken() {
- global $wgUser;
- if ( !$wgUser->isAllowed( self::$right ) ) {
+ $user = RequestContext::getMain()->getUser();
+ if ( !$user->isAllowed( self::$right ) ) {
return false;
}
- return $wgUser->getEditToken( self::$salt );
+ return $user->getEditToken( self::$salt );
}
public static function injectTokenFunction( &$list ) {
diff --git a/ffs/MediaWikiComplexMessages.php b/ffs/MediaWikiComplexMessages.php
index 741de68..d3ba150 100644
--- a/ffs/MediaWikiComplexMessages.php
+++ b/ffs/MediaWikiComplexMessages.php
@@ -262,8 +262,6 @@
}
public function output() {
- global $wgRequest;
-
$colspan = array( 'colspan' => 3 );
$s = Xml::openElement( 'table', $this->tableAttributes );
@@ -304,8 +302,9 @@
}
}
- global $wgUser;
- if ( $wgUser->isAllowed( 'translate' ) ) {
+ $context = RequestContext::getMain();
+
+ if ( $context->getUser()->isAllowed( 'translate' ) ) {
$s .= '<tr>' . Xml::tags( 'td', $colspan,
$this->getButtons() ) . '<tr>';
}
@@ -313,7 +312,10 @@
return Xml::tags(
'form',
- array( 'method' => 'post', 'action' =>
$wgRequest->getRequestURL() ),
+ array(
+ 'method' => 'post',
+ 'action' =>
$context->getRequest()->getRequestURL()
+ ),
$s
);
}
diff --git a/scripts/createCheckIndex.php b/scripts/createCheckIndex.php
index f4dc6c4..cec5813 100644
--- a/scripts/createCheckIndex.php
+++ b/scripts/createCheckIndex.php
@@ -68,6 +68,8 @@
$collection->resetForNewLanguage( $code );
$collection->loadTranslations();
+ global $wgContLang;
+
foreach ( $collection as $key => $message ) {
$prob = $checker->checkMessageFast( $message, $code );
if ( $prob ) {
diff --git a/scripts/fuzzy.php b/scripts/fuzzy.php
index c42563b..e267148 100644
--- a/scripts/fuzzy.php
+++ b/scripts/fuzzy.php
@@ -171,10 +171,11 @@
* @param string $comment Edit summary.
*/
private function updateMessage( $title, $text, $dryrun, $comment = null
) {
- global $wgTranslateDocumentationLanguageCode, $wgUser;
+ global $wgTranslateDocumentationLanguageCode;
- $oldUser = $wgUser;
- $wgUser = FuzzyBot::getUser();
+ $context = RequestContext::getMain();
+ $oldUser = $context->getUser();
+ $context->setUser( FuzzyBot::getUser() );
STDOUT( "Updating {$title->getPrefixedText()}... ", $title );
if ( !$title instanceof Title ) {
@@ -203,6 +204,6 @@
$success = $status === true || ( is_object( $status ) &&
$status->isOK() );
STDOUT( $success ? 'OK' : 'FAILED', $title );
- $wgUser = $oldUser;
+ $context->setUser( $oldUser );
}
}
diff --git a/scripts/sync-group.php b/scripts/sync-group.php
index 26becf7..1bce00e 100644
--- a/scripts/sync-group.php
+++ b/scripts/sync-group.php
@@ -267,15 +267,15 @@
STDOUT( "Conflict in " . $this->color( 'bold', $page )
. "!", $page );
- global $wgLang;
$iso = 'xnY-xnm-xnd"T"xnH:xni:xns';
+ $lang = RequestContext::getMain()->getLanguage();
// Finally all is ok, now lets start comparing
timestamps
// Make sure we are comparing timestamps in same format
$wikiTs = $this->getLastGoodChange( $title, $startTs );
if ( $wikiTs ) {
$wikiTs = wfTimestamp( TS_UNIX, $wikiTs );
- $wikiDate = $wgLang->sprintfDate( $iso,
wfTimestamp( TS_MW, $wikiTs ) );
+ $wikiDate = $lang->sprintfDate( $iso,
wfTimestamp( TS_MW, $wikiTs ) );
} else {
$wikiDate = 'Unknown';
}
@@ -289,7 +289,7 @@
}
if ( $changeTs ) {
$changeTs = wfTimestamp( TS_UNIX, $changeTs );
- $changeDate = $wgLang->sprintfDate( $iso,
wfTimestamp( TS_MW, $changeTs ) );
+ $changeDate = $lang->sprintfDate( $iso,
wfTimestamp( TS_MW, $changeTs ) );
} else {
$changeDate = 'Unknown';
}
@@ -392,10 +392,9 @@
* @param $comment \string Edit summary.
*/
public function import( $title, $translation, $comment ) {
- global $wgUser;
-
- $old = $wgUser;
- $wgUser = FuzzyBot::getUser();
+ $context = RequestContext::getMain();
+ $oldUser = $context->getUser();
+ $context->setUser( FuzzyBot::getUser() );
$flags = EDIT_FORCE_BOT;
if ( $this->norc ) {
@@ -408,7 +407,7 @@
$success = $status === true || ( is_object( $status ) &&
$status->isOK() );
STDOUT( $success ? 'OK' : 'FAILED', $title );
- $wgUser = $old;
+ $context->setUser( $oldUser );
}
}
diff --git a/specials/SpecialTranslate.php b/specials/SpecialTranslate.php
index 871a23a..d4e9f2b 100644
--- a/specials/SpecialTranslate.php
+++ b/specials/SpecialTranslate.php
@@ -559,13 +559,13 @@
protected function tuxLanguageSelector() {
// Changes here must also be reflected when the language
// changes on the client side
- global $wgLang, $wgTranslateDocumentationLanguageCode;
+ global $wgTranslateDocumentationLanguageCode;
if ( $this->options['language'] ===
$wgTranslateDocumentationLanguageCode ) {
// The name will be displayed in the UI language,
// so use for lang and dir
- $targetLangCode = $wgLang->getCode();
- $targetLangDir = $wgLang->getDir();
+ $targetLangCode = $this->getLanguage()->getCode();
+ $targetLangDir = $this->getLanguage()->getDir();
$targetLangName = $this->msg(
'translate-documentation-language' )->text();
} else {
$targetLangCode = $this->options['language'];
diff --git a/tag/PageTranslationHooks.php b/tag/PageTranslationHooks.php
index 13c5567..746fdc8 100644
--- a/tag/PageTranslationHooks.php
+++ b/tag/PageTranslationHooks.php
@@ -660,7 +660,7 @@
}
protected static function sourcePageHeader( Title $title ) {
- global $wgUser, $wgLang;
+ $context = RequestContext::getMain();
$page = TranslatablePage::newFromTitle( $title );
@@ -674,15 +674,15 @@
$actions = array();
- if ( $marked && $wgUser->isAllowed( 'translate' ) ) {
+ if ( $marked && $context->getUser()->isAllowed( 'translate' ) )
{
$par = array(
'group' => $page->getMessageGroupId(),
- 'language' => $wgLang->getCode(),
+ 'language' =>
$context->getLanguage()->getCode(),
'task' => 'view'
);
$translate = SpecialPage::getTitleFor( 'Translate' );
- $linkDesc = wfMessage(
'translate-tag-translate-link-desc' )->escaped();
+ $linkDesc = $context->msg(
'translate-tag-translate-link-desc' )->escaped();
$actions[] = Linker::link( $translate, $linkDesc,
array(), $par );
}
@@ -691,18 +691,18 @@
$par = array( 'target' => $title->getPrefixedText() );
$translate = SpecialPage::getTitleFor(
'PageTranslation' );
- if ( $wgUser->isAllowed( 'pagetranslation' ) ) {
+ if ( $context->getUser()->isAllowed( 'pagetranslation'
) ) {
// This page has never been marked
if ( $marked === false ) {
- $linkDesc = wfMessage(
'translate-tag-markthis' )->escaped();
+ $linkDesc = $context->msg(
'translate-tag-markthis' )->escaped();
$actions[] = Linker::link( $translate,
$linkDesc, array(), $par );
} else {
$markUrl = $translate->getFullUrl( $par
);
- $actions[] = wfMessage(
'translate-tag-markthisagain', $diffUrl, $markUrl )
+ $actions[] = $context->msg(
'translate-tag-markthisagain', $diffUrl, $markUrl )
->parse();
}
} else {
- $actions[] = wfMessage( 'translate-tag-hasnew',
$diffUrl )->parse();
+ $actions[] = $context->msg(
'translate-tag-hasnew', $diffUrl )->parse();
}
}
@@ -713,17 +713,13 @@
$legend = Html::rawElement(
'div',
array( 'class' => 'mw-pt-translate-header noprint
nomobile' ),
- $wgLang->semicolonList( $actions )
+ $context->getLanguage()->semicolonList( $actions )
) . Html::element( 'hr' );
- global $wgOut;
-
- $wgOut->addHTML( $legend );
+ $context->getOutput()->addHTML( $legend );
}
protected static function translationPageHeader( Title $title ) {
- global $wgOut;
-
if ( !$title->exists() ) {
return;
}
@@ -747,9 +743,10 @@
// Output
$wrap = '<div class="mw-translate-page-info">$1</div>';
- $wgOut->wrapWikiMsg( $wrap, array( 'tpt-translation-intro',
$url, $titleText, $per ) );
+ $out = RequestContext::getMain()->getOutput();
- $wgOut->addHTML( '<hr />' );
+ $out->wrapWikiMsg( $wrap, array( 'tpt-translation-intro', $url,
$titleText, $per ) );
+ $out->addHTML( '<hr />' );
}
/// Hook: SpecialPage_initList
@@ -779,13 +776,7 @@
}
/// Hook: SkinSubPageSubtitle
- public static function replaceSubtitle( &$subpages, $skin = null, $out
= null ) {
- global $wgOut;
- // $out was only added in some MW version
- if ( $out === null ) {
- $out = $wgOut;
- }
-
+ public static function replaceSubtitle( &$subpages, $skin = null,
OutputPage $out ) {
if ( !TranslatablePage::isTranslationPage( $out->getTitle() )
&& !TranslatablePage::isSourcePage( $out->getTitle() )
) {
diff --git a/tag/TranslateDeleteJob.php b/tag/TranslateDeleteJob.php
index 5659ae7..4383b57 100644
--- a/tag/TranslateDeleteJob.php
+++ b/tag/TranslateDeleteJob.php
@@ -39,9 +39,8 @@
}
function run() {
- global $wgUser;
-
// Initialization
+ $context = RequestContext::getMain();
$title = $this->title;
// Other stuff
$user = $this->getUser();
@@ -50,8 +49,8 @@
$doer = User::newFromName( $this->getPerformer() );
PageTranslationHooks::$allowTargetEdit = true;
- $oldUser = $wgUser;
- $wgUser = $user;
+ $oldUser = $context->getUser();
+ $context->setUser( $user );
$error = '';
$article = new Article( $title, 0 );
@@ -94,7 +93,7 @@
$title->invalidateCache();
}
- $wgUser = $oldUser;
+ $context->setUser( $oldUser );
return true;
}
diff --git a/tag/TranslateMoveJob.php b/tag/TranslateMoveJob.php
index 18b80c6..55d027c 100644
--- a/tag/TranslateMoveJob.php
+++ b/tag/TranslateMoveJob.php
@@ -43,9 +43,8 @@
}
function run() {
- global $wgUser;
-
// Initialization
+ $context = RequestContext::getMain();
$title = $this->title;
// Other stuff
$user = $this->getUser();
@@ -55,8 +54,8 @@
$doer = User::newFromName( $this->getPerformer() );
PageTranslationHooks::$allowTargetEdit = true;
- $oldUser = $wgUser;
- $wgUser = $user;
+ $oldUser = $context->getUser();
+ $context->setUser( $user );
self::forceRedirects( false );
// Don't check perms, don't leave a redirect
@@ -101,7 +100,7 @@
$entry->publish( $logid );
}
- $wgUser = $oldUser;
+ $context->setUser( $oldUser );
return true;
}
@@ -181,7 +180,6 @@
static $originalLevel = null;
global $wgGroupPermissions;
- global $wgUser;
if ( $end ) {
if ( $suppressCount ) {
@@ -203,6 +201,7 @@
}
++$suppressCount;
}
- $wgUser->clearInstanceCache();
+
+ RequestContext::getMain()->getUser()->clearInstanceCache();
}
}
diff --git a/tests/api/ApiTokensTest.php b/tests/api/ApiTokensTest.php
index fc1b32e..74688fa 100644
--- a/tests/api/ApiTokensTest.php
+++ b/tests/api/ApiTokensTest.php
@@ -15,9 +15,9 @@
/** @dataProvider provideTokenClasses */
public function testTokenRetrieval( $id, $class ) {
// Make sure we have the right to get the token
- global $wgGroupPermissions, $wgUser;
+ global $wgGroupPermissions;
$wgGroupPermissions['*'][$class::getRight()] = true;
- $wgUser->clearInstanceCache(); // Reread above global
+ RequestContext::getMain()->getUser()->clearInstanceCache(); //
Reread above global
// We should be getting anonymous user token
$expected = $class::getToken();
diff --git a/utils/JsSelectToInput.php b/utils/JsSelectToInput.php
index 0267cd8..fda586b 100644
--- a/utils/JsSelectToInput.php
+++ b/utils/JsSelectToInput.php
@@ -123,7 +123,6 @@
return;
}
- global $wgOut;
- $wgOut->addModules( 'ext.translate.selecttoinput' );
+ RequestContext::getMain()->getOutput()->addModules(
'ext.translate.selecttoinput' );
}
}
diff --git a/utils/MessageTable.php b/utils/MessageTable.php
index 52ef86b..8f57529 100644
--- a/utils/MessageTable.php
+++ b/utils/MessageTable.php
@@ -108,9 +108,7 @@
}
public function includeAssets() {
- global $wgOut;
-
- TranslationHelpers::addModules( $wgOut );
+ TranslationHelpers::addModules( $this->context->getOutput() );
$pages = array();
foreach ( $this->collection->getTitles() as $title ) {
@@ -118,7 +116,7 @@
}
$vars = array( 'trlKeys' => $pages );
- $wgOut->addScript( Skin::makeVariablesScript( $vars ) );
+ $this->context->getOutput()->addScript(
Skin::makeVariablesScript( $vars ) );
}
public function header() {
@@ -149,7 +147,7 @@
}
public function contents() {
- $optional = wfMessage( 'translate-optional' )->escaped();
+ $optional = $this->context->msg( 'translate-optional'
)->escaped();
$this->doLinkBatch();
@@ -192,8 +190,10 @@
// Using Html::element( a ) because Linker::link is
memory hog.
// It takes about 20 KiB per call, and that times 5000
is quite
// a lot of memory.
- global $wgLang;
- $niceTitle = htmlspecialchars( $wgLang->truncate(
$title->getPrefixedText(), -35 ) );
+ $niceTitle = htmlspecialchars(
$this->context->getLanguage()->truncate(
+ $title->getPrefixedText(),
+ -35
+ ) );
$linkAttribs = array(
'href' => $title->getLocalUrl( array( 'action'
=> 'edit' ) + $this->editLinkParams ),
);
@@ -289,11 +289,10 @@
}
protected function getReviewButton( TMessage $message ) {
- global $wgUser;
-
$revision = $message->getProperty( 'revision' );
+ $user = $this->context->getUser();
- if ( !$this->reviewMode || !$wgUser->isAllowed(
'translate-messagereview' ) || !$revision ) {
+ if ( !$this->reviewMode || !$user->isAllowed(
'translate-messagereview' ) || !$revision ) {
return '';
}
@@ -306,7 +305,7 @@
);
$reviewers = (array)$message->getProperty( 'reviewers' );
- if ( in_array( $wgUser->getId(), $reviewers ) ) {
+ if ( in_array( $user->getId(), $reviewers ) ) {
$attribs['value'] = wfMessage(
'translate-messagereview-done' )->text();
$attribs['disabled'] = 'disabled';
$attribs['title'] = wfMessage(
'translate-messagereview-doit' )->text();
@@ -314,7 +313,7 @@
$attribs['value'] = wfMessage(
'translate-messagereview-submit' )->text();
$attribs['disabled'] = 'disabled';
$attribs['title'] = wfMessage(
'translate-messagereview-no-fuzzy' )->text();
- } elseif ( $wgUser->getName() === $message->getProperty(
'last-translator-text' ) ) {
+ } elseif ( $user->getName() === $message->getProperty(
'last-translator-text' ) ) {
$attribs['value'] = wfMessage(
'translate-messagereview-submit' )->text();
$attribs['disabled'] = 'disabled';
$attribs['title'] = wfMessage(
'translate-messagereview-no-own' )->text();
@@ -331,8 +330,6 @@
protected $reviewStatusCache = array();
protected function getReviewStatus( TMessage $message ) {
- global $wgUser;
-
if ( !$this->reviewMode ) {
return '';
}
@@ -344,7 +341,8 @@
return '';
}
- $you = in_array( $wgUser->getId(), $reviewers );
+ $userId = $this->context->getUser()->getId();
+ $you = in_array( $userId, $reviewers );
$key = $you ? "y$count" : "n$count";
// ->text() (and ->parse()) invokes the parser. Each call takes
diff --git a/utils/MessageWebImporter.php b/utils/MessageWebImporter.php
index da80029..8b35f02 100644
--- a/utils/MessageWebImporter.php
+++ b/utils/MessageWebImporter.php
@@ -61,10 +61,11 @@
$this->title = $title;
}
+ /**
+ * @return User
+ */
public function getUser() {
- global $wgUser;
-
- return $this->user ? $this->user : $wgUser;
+ return $this->user ? $this->user :
RequestContext::getMain()->getUser();
}
public function setUser( User $user ) {
@@ -133,11 +134,11 @@
* @return bool
*/
protected function allowProcess() {
- global $wgRequest;
+ $request = RequestContext::getMain()->getRequest();
- if ( $wgRequest->wasPosted() &&
- $wgRequest->getBool( 'process', false ) &&
- $this->getUser()->matchEditToken( $wgRequest->getVal(
'token' ) )
+ if ( $request->wasPosted() &&
+ $request->getBool( 'process', false ) &&
+ $this->getUser()->matchEditToken( $request->getVal(
'token' ) )
) {
return true;
@@ -171,9 +172,8 @@
}
public function execute( $messages ) {
- global $wgOut, $wgLang;
-
- $this->out = $wgOut;
+ $context = RequestContext::getMain();
+ $this->out = $context->getOutput();
// Set up diff engine
$diff = new DifferenceEngine;
@@ -209,7 +209,8 @@
if ( $old === false ) {
$para = '<code class="mw-tmi-new">' .
htmlspecialchars( $key ) . '</code>';
- $name = wfMessage(
'translate-manage-import-new' )->rawParams( $para )->escaped();
+ $name = $context->msg(
'translate-manage-import-new' )->rawParams( $para )
+ ->escaped();
$text =
TranslateUtils::convertWhiteSpaceToHTML( $value );
$changed[] = self::makeSectionElement( $name,
'new', $text );
} else {
@@ -217,8 +218,8 @@
$text = $diff->getDiff( '', '' );
$type = 'changed';
- global $wgRequest;
- $action = $wgRequest->getVal(
self::escapeNameForPHP( "action-$type-$key" ) );
+ $action = $context->getRequest()
+ ->getVal( self::escapeNameForPHP(
"action-$type-$key" ) );
if ( $process ) {
if ( !count( $changed ) ) {
@@ -226,9 +227,10 @@
}
if ( $action === null ) {
- $message = wfMessage(
+ $message = $context->msg(
'translate-manage-inconsistent',
- wfEscapeWikiText(
"action-$type-$key" ) )->parse();
+ wfEscapeWikiText(
"action-$type-$key" )
+ )->parse();
$changed[] =
"<li>$message</li></ul>";
$process = false;
} else {
@@ -247,13 +249,13 @@
$key = array_shift( $message );
$params = $message;
- $message = wfMessage( $key,
$params )->parse();
+ $message = $context->msg( $key,
$params )->parse();
$changed[] =
"<li>$message</li>";
if ( $this->checkProcessTime()
) {
$process = false;
- $message = wfMessage(
-
'translate-manage-toolong' )->numParams( $this->processingTime )->parse();
+ $message =
$context->msg( 'translate-manage-toolong' )
+ ->numParams(
$this->processingTime )->parse();
$changed[] =
"<li>$message</li></ul>";
}
continue;
@@ -271,14 +273,14 @@
// translate-manage-action-import,
translate-manage-action-conflict,
// translate-manage-action-ignore,
translate-manage-action-fuzzy
foreach ( $actions as $action ) {
- $label = wfMessage(
"translate-manage-action-$action" )->text();
+ $label = $context->msg(
"translate-manage-action-$action" )->text();
$name = self::escapeNameForPHP(
"action-$type-$key" );
$id = Sanitizer::escapeId(
"action-$key-$action" );
$act[] = Xml::radioLabel( $label,
$name, $action, $id, $action === $defaction );
}
$param = '<code class="mw-tmi-diff">' .
htmlspecialchars( $key ) . '</code>';
- $name = wfMessage(
'translate-manage-import-diff', $param,
+ $name = $context->msg(
'translate-manage-import-diff', $param,
implode( ' ', $act )
)->text();
@@ -294,7 +296,7 @@
foreach ( $diff as $s ) {
$para = '<code class="mw-tmi-deleted">' .
htmlspecialchars( $s ) . '</code>';
- $name = wfMessage(
'translate-manage-import-deleted' )->rawParams( $para )->escaped();
+ $name = $context->msg(
'translate-manage-import-deleted' )->rawParams( $para )->escaped();
$text =
TranslateUtils::convertWhiteSpaceToHTML( $collection[$s]->translation() );
$changed[] = self::makeSectionElement( $name,
'deleted', $text );
}
@@ -309,7 +311,7 @@
$changed[] = '<ul>';
}
- $message = wfMessage( 'translate-manage-import-done'
)->parse();
+ $message = $context->msg(
'translate-manage-import-done' )->parse();
$changed[] = "<li>$message</li></ul>";
$this->out->addHTML( implode( "\n", $changed ) );
} else {
@@ -318,12 +320,15 @@
if ( $code === 'en' ) {
$this->out->addWikiMsg(
'translate-manage-intro-en' );
} else {
- $lang =
TranslateUtils::getLanguageName( $code, $wgLang->getCode() );
+ $lang = TranslateUtils::getLanguageName(
+ $code,
+
$context->getLanguage()->getCode()
+ );
$this->out->addWikiMsg(
'translate-manage-intro-other', $lang );
}
$this->out->addHTML( Html::hidden( 'language',
$code ) );
$this->out->addHTML( implode( "\n", $changed )
);
- $this->out->addHTML( Xml::submitButton(
wfMessage( 'translate-manage-submit' )->text() ) );
+ $this->out->addHTML( Xml::submitButton(
$context->msg( 'translate-manage-submit' )->text() ) );
} else {
$this->out->addWikiMsg(
'translate-manage-nochanges' );
}
@@ -343,7 +348,7 @@
* @param string $code Language code
* @param string $message Contents for the $key/code combination
* @param string $comment Edit summary (default: empty) - see
Article::doEdit
- * @param User $user User that will make the edit (default: null -
$wgUser).
+ * @param User $user User that will make the edit (default: null -
RequestContext user).
* See Article::doEdit.
* @param int $editFlags Integer bitfield: see Article::doEdit
* @throws MWException
@@ -420,10 +425,10 @@
* @return array|String
*/
public static function doFuzzy( $title, $message, $comment, $user,
$editFlags = 0 ) {
- global $wgUser;
+ $context = RequestContext::getMain();
- if ( !$wgUser->isAllowed( 'translate-manage' ) ) {
- return wfMessage( 'badaccess-group0' )->text();
+ if ( !$context->getUser()->isAllowed( 'translate-manage' ) ) {
+ return $context->msg( 'badaccess-group0' )->text();
}
$dbw = wfGetDB( DB_MASTER );
@@ -483,7 +488,7 @@
$text = '';
foreach ( $changed as $c ) {
$key = array_shift( $c );
- $text .= "* " . wfMessage( $key, $c )->plain() . "\n";
+ $text .= "* " . $context->msg( $key, $c )->plain() .
"\n";
}
return array( 'translate-manage-import-fuzzy', "\n" . $text );
diff --git a/utils/RcFilter.php b/utils/RcFilter.php
index 6998e65..67889fb 100644
--- a/utils/RcFilter.php
+++ b/utils/RcFilter.php
@@ -26,9 +26,10 @@
* @return bool true
*/
public static function translationFilter( &$conds, &$tables,
&$join_conds, $opts ) {
- global $wgRequest, $wgTranslateMessageNamespaces,
$wgTranslateRcFilterDefault;
+ global $wgTranslateMessageNamespaces,
$wgTranslateRcFilterDefault;
- $translations = $wgRequest->getVal( 'translations',
$wgTranslateRcFilterDefault );
+ $request = RequestContext::getMain()->getRequest();
+ $translations = $request->getVal( 'translations',
$wgTranslateRcFilterDefault );
$opts->add( 'translations', $wgTranslateRcFilterDefault );
$opts->setValue( 'translations', $translations );
diff --git a/utils/StatsTable.php b/utils/StatsTable.php
index 30fdd6c..065bff3 100644
--- a/utils/StatsTable.php
+++ b/utils/StatsTable.php
@@ -31,9 +31,7 @@
protected $extraColumns = array();
public function __construct() {
- global $wgLang;
-
- $this->lang = $wgLang;
+ $this->lang = RequestContext::getMain()->getLanguage();
$this->translate = SpecialPage::getTitleFor( 'Translate' );
}
diff --git a/utils/TranslationEditPage.php b/utils/TranslationEditPage.php
index c8d0b58..7b10e32 100644
--- a/utils/TranslationEditPage.php
+++ b/utils/TranslationEditPage.php
@@ -66,12 +66,14 @@
* disabled all other output.
*/
public function execute() {
- global $wgOut, $wgServer, $wgScriptPath, $wgUser, $wgRequest;
+ global $wgServer, $wgScriptPath;
- $wgOut->disable();
+ $context = RequestContext::getMain();
+
+ $context->getOutput()->disable();
$data = $this->getEditInfo();
- $groupId = $wgRequest->getText( 'loadgroup', '' );
+ $groupId = $context->getRequest()->getText( 'loadgroup', '' );
$helpers = new TranslationHelpers( $this->getTitle(), $groupId
);
$id = "tm-target-{$helpers->dialogID()}";
@@ -108,7 +110,7 @@
'dir' => $targetLang->getDir(),
);
- if ( !$groupId || !$wgUser->isAllowed( 'translate' ) ) {
+ if ( !$groupId || !$context->getUser()->isAllowed( 'translate'
) ) {
$textareaParams['readonly'] = 'readonly';
}
@@ -132,23 +134,23 @@
$hidden[] = Html::hidden( 'action', 'edit' );
$summary = Xml::inputLabel(
- wfMessage( 'translate-js-summary' )->text(),
+ $context->msg( 'translate-js-summary' )->text(),
'summary',
'summary',
40
);
$save = Xml::submitButton(
- wfMessage( 'translate-js-save' )->text(),
+ $context->msg( 'translate-js-save' )->text(),
array( 'class' => 'mw-translate-save' )
);
$saveAndNext = Xml::submitButton(
- wfMessage( 'translate-js-next' )->text(),
+ $context->msg( 'translate-js-next' )->text(),
array( 'class' => 'mw-translate-next' )
);
$skip = Html::element( 'input', array(
'class' => 'mw-translate-skip',
'type' => 'button',
- 'value' => wfMessage( 'translate-js-skip' )->text()
+ 'value' => $context->msg( 'translate-js-skip' )->text()
) );
if ( $this->getTitle()->exists() ) {
@@ -157,7 +159,7 @@
array(
'class' => 'mw-translate-history',
'type' => 'button',
- 'value' => wfMessage(
'translate-js-history' )->text()
+ 'value' => $context->msg(
'translate-js-history' )->text()
)
);
} else {
@@ -166,10 +168,10 @@
$support = $this->getSupportButton( $this->getTitle() );
- if ( $wgUser->isAllowed( 'translate' ) ) {
+ if ( $context->getUser()->isAllowed( 'translate' ) ) {
$bottom =
"$summary$save$saveAndNext$skip$history$support";
} else {
- $text = wfMessage( 'translate-edit-nopermission'
)->escaped();
+ $text = $context->msg( 'translate-edit-nopermission'
)->escaped();
$button = $this->getPermissionPageButton();
$bottom = "$text $button$skip$history$support";
}
@@ -234,9 +236,9 @@
* @return \array
*/
public static function jsEdit( Title $title, $group = "", $type =
'default' ) {
- global $wgUser;
+ $context = RequestContext::getMain();
- if ( !$wgUser->getOption( 'translate-jsedit' ) ) {
+ if ( !$context->getUser()->getOption( 'translate-jsedit' ) ) {
return array();
}
@@ -251,7 +253,7 @@
return array(
'onclick' => $onclick,
- 'title' => wfMessage( 'translate-edit-title',
$title->getPrefixedText() )->text()
+ 'title' => $context->msg( 'translate-edit-title',
$title->getPrefixedText() )->text()
);
}
diff --git a/utils/TranslationHelpers.php b/utils/TranslationHelpers.php
index bb69cf0..002da3a 100644
--- a/utils/TranslationHelpers.php
+++ b/utils/TranslationHelpers.php
@@ -187,8 +187,8 @@
array( 'lazy' )
);
} elseif ( $suggestions === 'checks' ) {
- global $wgRequest;
- $this->translation = $wgRequest->getText( 'translation'
);
+ $request = RequestContext::getMain()->getRequest();
+ $this->translation = $request->getText( 'translation' );
return (string)$this->callBox( 'check', $all['check'] );
}
@@ -477,9 +477,10 @@
}
protected static function makeGoogleQueryParams( $definition, $pair,
$config ) {
- global $wgSitename, $wgVersion, $wgProxyKey, $wgUser;
+ global $wgSitename, $wgVersion, $wgProxyKey;
$app = "$wgSitename (MediaWiki $wgVersion; Translate " .
TRANSLATE_VERSION . ")";
+ $context = RequestContext::getMain();
$options = array();
$options['timeout'] = $config['timeout'];
@@ -488,7 +489,7 @@
'v' => '1.0',
'langpair' => $pair,
// Unique but not identifiable
- 'userip' => sha1( $wgProxyKey . $wgUser->getName() ),
+ 'userip' => sha1( $wgProxyKey .
$context->getUser()->getName() ),
'x-application' => $app,
);
@@ -843,12 +844,13 @@
public function getCheckBox() {
$this->mustBeKnownMessage();
- global $wgTranslateDocumentationLanguageCode, $wgRequest,
$wgOut;
+ global $wgTranslateDocumentationLanguageCode;
- $title = $wgOut->getTitle();
+ $context = RequestContext::getMain();
+ $title = $context->getOutput()->getTitle();
list( $alias, ) = SpecialPageFactory::resolveAlias(
$title->getText() );
- $tux = SpecialTranslate::isBeta( $wgRequest )
+ $tux = SpecialTranslate::isBeta( $context->getRequest() )
&& $title->isSpecialPage()
&& ( $alias === 'Translate' );
@@ -887,25 +889,27 @@
foreach ( $checks as $checkParams ) {
$key = array_shift( $checkParams );
- $checkMessages[] = wfMessage( $key, $checkParams
)->parse();
+ $checkMessages[] = $context->msg( $key, $checkParams
)->parse();
}
if ( $tux ) {
$formattedChecks = FormatJson::encode( $checkMessages );
} else {
- $formattedChecks = Html::rawElement( 'div', array(
'class' => 'mw-translate-messagechecks' ),
+ $formattedChecks = Html::rawElement(
+ 'div',
+ array( 'class' => 'mw-translate-messagechecks'
),
TranslateUtils::fieldset(
- wfMessage( 'translate-edit-warnings'
)->escaped(), implode( '<hr />', $checkMessages ),
+ $context->msg(
'translate-edit-warnings' )->escaped(),
+ implode( '<hr />', $checkMessages ),
array( 'class' =>
'mw-sp-translate-edit-warnings' )
- ) );
+ )
+ );
}
return $formattedChecks;
}
public function getOtherLanguagesBox() {
- global $wgLang;
-
$code = $this->handle->getCode();
$page = $this->handle->getKey();
$ns = $this->handle->getTitle()->getNamespace();
@@ -917,10 +921,10 @@
continue;
}
- $label =
- TranslateUtils::getLanguageName( $fbcode,
$wgLang->getCode() ) .
- wfMessage( 'word-separator' )->text() .
- wfMessage( 'parentheses', wfBCP47(
$fbcode ) )->text();
+ $context = RequestContext::getMain();
+ $label = TranslateUtils::getLanguageName( $fbcode,
$context->getLanguage()->getCode() ) .
+ $context->msg( 'word-separator' )->text() .
+ $context->msg( 'parentheses', wfBCP47( $fbcode
) )->text();
$target = Title::makeTitleSafe( $ns, "$page/$fbcode" );
if ( $target ) {
@@ -967,17 +971,21 @@
}
public function getDocumentationBox() {
- global $wgTranslateDocumentationLanguageCode, $wgOut;
+ global $wgTranslateDocumentationLanguageCode;
if ( !$wgTranslateDocumentationLanguageCode ) {
throw new TranslationHelperException( 'Message
documentation language code is not defined' );
}
+ $context = RequestContext::getMain();
$page = $this->handle->getKey();
$ns = $this->handle->getTitle()->getNamespace();
$title = Title::makeTitle( $ns, $page . '/' .
$wgTranslateDocumentationLanguageCode );
- $edit = self::ajaxEditLink( $title, wfMessage(
'translate-edit-contribute' )->escaped() );
+ $edit = self::ajaxEditLink(
+ $title,
+ $context->msg( 'translate-edit-contribute' )->escaped()
+ );
$info = TranslateUtils::getMessageContent( $page,
$wgTranslateDocumentationLanguageCode, $ns );
$class = 'mw-sp-translate-edit-info';
@@ -992,20 +1000,20 @@
$divAttribs = array( 'dir' => 'ltr', 'lang' => 'en', 'class' =>
'mw-content-ltr' );
if ( strval( $info ) === '' ) {
- global $wgLang;
- $info = wfMessage( 'translate-edit-no-information'
)->text();
+ $info = $context->msg( 'translate-edit-no-information'
)->text();
$class = 'mw-sp-translate-edit-noinfo';
+ $lang = $context->getLanguage();
// The message saying that there's no info, should be
translated
- $divAttribs = array( 'dir' => $wgLang->getDir(), 'lang'
=> $wgLang->getCode() );
+ $divAttribs = array( 'dir' => $lang->getDir(), 'lang'
=> $lang->getCode() );
}
$class .= ' mw-sp-translate-message-documentation';
- $contents = $wgOut->parse( $info );
+ $contents = $context->getOutput()->parse( $info );
// Remove whatever block element wrapup the parser likes to add
$contents = preg_replace( '~^<([a-z]+)>(.*)</\1>$~us', '\2',
$contents );
return TranslateUtils::fieldset(
- wfMessage( 'translate-edit-information' )->rawParams(
$edit )->escaped(),
+ $context->msg( 'translate-edit-information'
)->rawParams( $edit )->escaped(),
Html::rawElement( 'div', $divAttribs, $contents ),
array( 'class' => $class )
);
}
@@ -1146,21 +1154,21 @@
return null;
}
- global $wgUser;
- $user = $latestRev->getUserText( Revision::FOR_THIS_USER,
$wgUser );
+ $context = RequestContext::getMain();
+ $user = $latestRev->getUserText( Revision::FOR_THIS_USER,
$context->getUser() );
$comment = $latestRev->getComment();
if ( $diffText === '' ) {
if ( strval( $comment ) !== '' ) {
- $text = wfMessage( 'translate-dynagroup-byc',
$user, $comment )->escaped();
+ $text = $context->msg(
'translate-dynagroup-byc', $user, $comment )->escaped();
} else {
- $text = wfMessage( 'translate-dynagroup-by',
$user )->escaped();
+ $text = $context->msg(
'translate-dynagroup-by', $user )->escaped();
}
} else {
if ( strval( $comment ) !== '' ) {
- $text = wfMessage( 'translate-dynagroup-lastc',
$user, $comment )->escaped();
+ $text = $context->msg(
'translate-dynagroup-lastc', $user, $comment )->escaped();
} else {
- $text = wfMessage( 'translate-dynagroup-last',
$user )->escaped();
+ $text = $context->msg(
'translate-dynagroup-last', $user )->escaped();
}
}
@@ -1192,10 +1200,11 @@
* @return array
*/
protected static function getFallbacks( $code ) {
- global $wgUser, $wgTranslateLanguageFallbacks;
+ global $wgTranslateLanguageFallbacks;
// User preference has the final say
- $preference = $wgUser->getOption( 'translate-editlangs' );
+ $user = RequestContext::getMain()->getUser();
+ $preference = $user->getOption( 'translate-editlangs' );
if ( $preference !== 'default' ) {
$fallbacks = array_map( 'trim', explode( ',',
$preference ) );
foreach ( $fallbacks as $k => $v ) {
diff --git a/utils/UserToggles.php b/utils/UserToggles.php
index 4ffc2ba..434d1ff 100644
--- a/utils/UserToggles.php
+++ b/utils/UserToggles.php
@@ -103,10 +103,9 @@
* @return JsSelectToInput
*/
protected static function languageSelector() {
- global $wgLang;
-
if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
- $languages = LanguageNames::getNames(
$wgLang->getCode(),
+ $lang = RequestContext::getMain()->getLanguage();
+ $languages = LanguageNames::getNames( $lang->getCode(),
LanguageNames::FALLBACK_NORMAL
);
} else {
--
To view, visit https://gerrit.wikimedia.org/r/65447
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If57556243b428faf987ba320d6438528746904e0
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits