diff --git a/.phpcs.xml b/.phpcs.xml index b46ac9661..078cb66c1 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -1,8 +1,6 @@ - - - + AbuseFilter\.alias\.php diff --git a/includes/AbuseFilter.php b/includes/AbuseFilter.php index 9d150ff35..268392620 100644 --- a/includes/AbuseFilter.php +++ b/includes/AbuseFilter.php @@ -3073,11 +3073,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 ); @@ -3087,15 +3086,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 ) ); @@ -3122,14 +3121,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() . @@ -3137,7 +3136,7 @@ class AbuseFilter { } else { $displayAction = self::getActionDisplay( $action ) . wfMessage( 'colon-separator' )->escaped() . - $wgLang->semicolonList( array_map( 'htmlspecialchars', $parameters ) ); + $lang->semicolonList( array_map( 'htmlspecialchars', $parameters ) ); } } @@ -3146,18 +3145,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 1f5ea3a5a..5a4bbbfdc 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 a2e7d3d49..b1b324ce8 100644 --- a/tests/phpunit/AbuseFilterTest.php +++ b/tests/phpunit/AbuseFilterTest.php @@ -1331,7 +1331,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 ); @@ -1379,7 +1378,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 ) ); }