Remove wgParser and wgRequest

As part of the deprecation process of non-config globals.

Change-Id: Ia84ddc20adbfda72347cf256601050b055b87ecf
This commit is contained in:
Daimona Eaytoy 2018-10-21 11:42:48 +02:00
parent 2b5fb86f97
commit 4480c9493a
3 changed files with 16 additions and 11 deletions

View file

@ -36,11 +36,11 @@ class AFComputedVariable {
return $cache[$cacheKey];
}
global $wgParser;
$edit = (object)[];
$options = new ParserOptions;
$options->setTidy( true );
$edit->output = $wgParser->parse( $wikitext, $article->getTitle(), $options );
$parser = MediaWikiServices::getInstance()->getParser();
$edit->output = $parser->parse( $wikitext, $article->getTitle(), $options );
$cache[$cacheKey] = $edit;
return $edit;

View file

@ -1106,7 +1106,7 @@ class AbuseFilter {
public static function filterAction(
AbuseFilterVariableHolder $vars, $title, $group, User $user, $mode = 'execute'
) {
global $wgRequest, $wgAbuseFilterRuntimeProfile, $wgAbuseFilterLogIP;
global $wgAbuseFilterRuntimeProfile, $wgAbuseFilterLogIP;
$logger = LoggerFactory::getInstance( 'StashEdit' );
$statsd = MediaWikiServices::getInstance()->getStatsdDataFactory();
@ -1191,6 +1191,7 @@ class AbuseFilter {
// If $user isn't safe to load (e.g. a failure during
// AbortAutoAccount), create a dummy anonymous user instead.
$user = $user->isSafeToLoad() ? $user : new User;
$request = RequestContext::getMain()->getRequest();
// Create a template
$log_template = [
@ -1201,7 +1202,7 @@ class AbuseFilter {
'afl_title' => $title->getDBkey(),
'afl_action' => $action,
// DB field is not null, so nothing
'afl_ip' => ( $wgAbuseFilterLogIP ) ? $wgRequest->getIP() : ""
'afl_ip' => ( $wgAbuseFilterLogIP ) ? $request->getIP() : ""
];
// Hack to avoid revealing IPs of people creating accounts
@ -1598,7 +1599,7 @@ class AbuseFilter {
$rule_number,
User $user
) {
global $wgAbuseFilterCustomActionsHandlers, $wgRequest;
global $wgAbuseFilterCustomActionsHandlers;
$message = null;
@ -1618,7 +1619,7 @@ class AbuseFilter {
case 'rangeblock':
global $wgAbuseFilterRangeBlockSize, $wgBlockCIDRLimit;
$ip = $wgRequest->getIP();
$ip = RequestContext::getMain()->getRequest()->getIP();
if ( IP::isIPv6( $ip ) ) {
$CIDRsize = max( $wgAbuseFilterRangeBlockSize['IPv6'], $wgBlockCIDRLimit['IPv6'] );
} else {
@ -1864,17 +1865,18 @@ class AbuseFilter {
* @return int|string
*/
public static function throttleIdentifier( $type, Title $title ) {
global $wgUser, $wgRequest;
global $wgUser;
$request = RequestContext::getMain()->getRequest();
switch ( $type ) {
case 'ip':
$identifier = $wgRequest->getIP();
$identifier = $request->getIP();
break;
case 'user':
$identifier = $wgUser->getId();
break;
case 'range':
$identifier = substr( IP::toHex( $wgRequest->getIP() ), 0, 4 );
$identifier = substr( IP::toHex( $request->getIP() ), 0, 4 );
break;
case 'creationdate':
$reg = $wgUser->getRegistration();

View file

@ -1,4 +1,7 @@
<?php
use MediaWiki\MediaWikiServices;
/**
* Generic tests for utility functions in AbuseFilter
*
@ -1201,7 +1204,6 @@ class AbuseFilterTest extends MediaWikiTestCase {
* @return array
*/
private static function computeExpectedEditVariable( $old, $new ) {
global $wgParser;
$popts = ParserOptions::newFromUser( self::$mUser );
// Order matters here. Some variables rely on other ones.
$variables = [
@ -1291,7 +1293,8 @@ class AbuseFilterTest extends MediaWikiTestCase {
case 'old_links':
$article = self::$mPage;
$popts->setTidy( true );
$edit = $wgParser->parse( $oldText, $article->getTitle(), $popts );
$parser = MediaWikiServices::getInstance()->getParser();
$edit = $parser->parse( $oldText, $article->getTitle(), $popts );
$result = array_keys( $edit->getExternalLinks() );
break;
case 'added_links':