From 51120e51c5a349fff1c07aa5a521824d274d4b25 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sun, 14 Oct 2018 11:39:36 +0200 Subject: [PATCH] Don't use wgLang and wgContLang For wgLang, there's a Language object available in the proximity, so just pass it. For wgContLang, use MediaWikiServices. Change-Id: Ic492007f2d5eeb8048d0919a4b9b7dd98c15c350 --- .phpcs.xml | 4 +--- includes/AbuseFilter.php | 24 ++++++++++----------- includes/Views/AbuseFilterViewDiff.php | 6 +++--- includes/pagers/AbuseFilterHistoryPager.php | 4 ++-- includes/parser/AbuseFilterParser.php | 9 ++++---- tests/phpunit/AbuseFilterTest.php | 3 +-- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/.phpcs.xml b/.phpcs.xml index c32362800..9fa770ba5 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -1,8 +1,6 @@ - - - + AbuseFilter\.alias\.php AbuseFilterParserTest\.php diff --git a/includes/AbuseFilter.php b/includes/AbuseFilter.php index 38492476e..9d84c2a52 100644 --- a/includes/AbuseFilter.php +++ b/includes/AbuseFilter.php @@ -3053,11 +3053,10 @@ class AbuseFilter { /** * @param string $action * @param string[] $parameters + * @param Language $lang * @return string */ - public static function formatAction( $action, $parameters ) { - /** @var $wgLang Language */ - global $wgLang; + public static function formatAction( $action, $parameters, $lang ) { if ( count( $parameters ) === 0 || ( $action === 'block' && count( $parameters ) !== 3 ) ) { $displayAction = self::getActionDisplay( $action ); @@ -3067,15 +3066,15 @@ class AbuseFilter { $messages = [ wfMessage( 'abusefilter-block-anon' )->escaped() . wfMessage( 'colon-separator' )->escaped() . - $wgLang->translateBlockExpiry( $parameters[1] ), + $lang->translateBlockExpiry( $parameters[1] ), wfMessage( 'abusefilter-block-user' )->escaped() . wfMessage( 'colon-separator' )->escaped() . - $wgLang->translateBlockExpiry( $parameters[2] ) + $lang->translateBlockExpiry( $parameters[2] ) ]; if ( $parameters[0] === 'blocktalk' ) { $messages[] = wfMessage( 'abusefilter-block-talk' )->escaped(); } - $displayAction = $wgLang->commaList( $messages ); + $displayAction = $lang->commaList( $messages ); } elseif ( $action === 'throttle' ) { array_shift( $parameters ); list( $actions, $time ) = explode( ',', array_shift( $parameters ) ); @@ -3102,14 +3101,14 @@ class AbuseFilter { $group = $msg->exists() ? $msg->text() : $group; } unset( $group ); - $val = $wgLang->listToText( $subGroups ); + $val = $lang->listToText( $subGroups ); } else { $msg = wfMessage( "abusefilter-throttle-$val" ); $val = $msg->exists() ? $msg->text() : $val; } } unset( $val ); - $groups = $wgLang->semicolonList( $parameters ); + $groups = $lang->semicolonList( $parameters ); } $displayAction = self::getActionDisplay( $action ) . wfMessage( 'colon-separator' )->escaped() . @@ -3117,7 +3116,7 @@ class AbuseFilter { } else { $displayAction = self::getActionDisplay( $action ) . wfMessage( 'colon-separator' )->escaped() . - $wgLang->semicolonList( array_map( 'htmlspecialchars', $parameters ) ); + $lang->semicolonList( array_map( 'htmlspecialchars', $parameters ) ); } } @@ -3126,18 +3125,17 @@ class AbuseFilter { /** * @param string $value + * @param Language $lang * @return string */ - public static function formatFlags( $value ) { - /** @var $wgLang Language */ - global $wgLang; + public static function formatFlags( $value, $lang ) { $flags = array_filter( explode( ',', $value ) ); $flags_display = []; foreach ( $flags as $flag ) { $flags_display[] = wfMessage( "abusefilter-history-$flag" )->escaped(); } - return $wgLang->commaList( $flags_display ); + return $lang->commaList( $flags_display ); } /** diff --git a/includes/Views/AbuseFilterViewDiff.php b/includes/Views/AbuseFilterViewDiff.php index 0dedbfebe..86480a8a8 100644 --- a/includes/Views/AbuseFilterViewDiff.php +++ b/includes/Views/AbuseFilterViewDiff.php @@ -311,8 +311,8 @@ class AbuseFilterViewDiff extends AbuseFilterView { } $info .= $this->getDiffRow( 'abusefilter-edit-flags', - AbuseFilter::formatFlags( $oldVersion['info']['flags'] ), - AbuseFilter::formatFlags( $newVersion['info']['flags'] ) + AbuseFilter::formatFlags( $oldVersion['info']['flags'], $this->getLanguage() ), + AbuseFilter::formatFlags( $newVersion['info']['flags'], $this->getLanguage() ) ); $info .= $this->getDiffRow( @@ -374,7 +374,7 @@ class AbuseFilterViewDiff extends AbuseFilterView { ksort( $actions ); foreach ( $actions as $action => $parameters ) { - $lines[] = AbuseFilter::formatAction( $action, $parameters ); + $lines[] = AbuseFilter::formatAction( $action, $parameters, $this->getLanguage() ); } if ( !count( $lines ) ) { diff --git a/includes/pagers/AbuseFilterHistoryPager.php b/includes/pagers/AbuseFilterHistoryPager.php index 9613568cd..fc1a8facb 100644 --- a/includes/pagers/AbuseFilterHistoryPager.php +++ b/includes/pagers/AbuseFilterHistoryPager.php @@ -89,7 +89,7 @@ class AbuseFilterHistoryPager extends TablePager { $formatted = htmlspecialchars( $value, ENT_QUOTES, 'UTF-8', false ); break; case 'afh_flags': - $formatted = AbuseFilter::formatFlags( $value ); + $formatted = AbuseFilter::formatFlags( $value, $lang ); break; case 'afh_actions': $actions = unserialize( $value ); @@ -97,7 +97,7 @@ class AbuseFilterHistoryPager extends TablePager { $display_actions = ''; foreach ( $actions as $action => $parameters ) { - $displayAction = AbuseFilter::formatAction( $action, $parameters ); + $displayAction = AbuseFilter::formatAction( $action, $parameters, $lang ); $display_actions .= Xml::tags( 'li', null, $displayAction ); } $display_actions = Xml::tags( 'ul', null, $display_actions ); diff --git a/includes/parser/AbuseFilterParser.php b/includes/parser/AbuseFilterParser.php index 635222567..2b7e55413 100644 --- a/includes/parser/AbuseFilterParser.php +++ b/includes/parser/AbuseFilterParser.php @@ -2,6 +2,7 @@ use Wikimedia\Equivset\Equivset; use MediaWiki\Logger\LoggerFactory; +use MediaWiki\MediaWikiServices; class AbuseFilterParser { public $mTokens, $mPos, $mShortCircuit, $mAllowShort; @@ -899,11 +900,11 @@ class AbuseFilterParser { * @return AFPData */ protected function funcLc( $args ) { - global $wgContLang; + $contLang = MediaWikiServices::getInstance()->getContentLanguage(); $this->checkEnoughArguments( $args, 'lc', 1 ); $s = $args[0]->toString(); - return new AFPData( AFPData::DSTRING, $wgContLang->lc( $s ) ); + return new AFPData( AFPData::DSTRING, $contLang->lc( $s ) ); } /** @@ -911,11 +912,11 @@ class AbuseFilterParser { * @return AFPData */ protected function funcUc( $args ) { - global $wgContLang; + $contLang = MediaWikiServices::getInstance()->getContentLanguage(); $this->checkEnoughArguments( $args, 'uc', 1 ); $s = $args[0]->toString(); - return new AFPData( AFPData::DSTRING, $wgContLang->uc( $s ) ); + return new AFPData( AFPData::DSTRING, $contLang->uc( $s ) ); } /** diff --git a/tests/phpunit/AbuseFilterTest.php b/tests/phpunit/AbuseFilterTest.php index 827b71342..3d57dcd1c 100644 --- a/tests/phpunit/AbuseFilterTest.php +++ b/tests/phpunit/AbuseFilterTest.php @@ -1330,7 +1330,6 @@ class AbuseFilterTest extends MediaWikiTestCase { * @dataProvider provideEditVars */ public function testGetEditVars( $oldText, $newText ) { - global $wgLang; self::$mTitle = Title::makeTitle( 0, 'AbuseFilter test' ); self::$mPage = WikiPage::factory( self::$mTitle ); @@ -1378,7 +1377,7 @@ class AbuseFilterTest extends MediaWikiTestCase { $this->assertCount( 0, $differences, - 'The following AbuseFilter variables are computed wrongly: ' . $wgLang->commaList( $differences ) + 'The following AbuseFilter variables are computed wrongly: ' . implode( ', ', $differences ) ); }