Replace deprecated cache-related functions

Some ObjectCache:: methods are soft deprecated since 1.28. Remove them
now, since the replacement is easy.

Change-Id: I713781d5e98238a1c194e97b5faae488a8ac190d
This commit is contained in:
Daimona Eaytoy 2018-10-18 19:30:15 +02:00
parent 3229ce5236
commit 90df3560b1
6 changed files with 24 additions and 15 deletions

View file

@ -591,7 +591,7 @@ class AbuseFilter {
$globalRulesKey = self::getGlobalRulesKey( $group );
$fname = __METHOD__;
$res = ObjectCache::getMainWANInstance()->getWithSetCallback(
$res = MediaWikiServices::getInstance()->getMainWANObjectCache()->getWithSetCallback(
$globalRulesKey,
WANObjectCache::TTL_INDEFINITE,
function () use ( $group, $fname, $fields ) {
@ -740,7 +740,7 @@ class AbuseFilter {
* @param int $filter
*/
private static function resetFilterProfile( $filter ) {
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
$countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' );
$totalKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'total' );
$condsKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'conds' );
@ -758,7 +758,7 @@ class AbuseFilter {
public static function recordProfilingResult( $filter, $time, $conds ) {
// Defer updates to avoid massive (~1 second) edit time increases
DeferredUpdates::addCallableUpdate( function () use ( $filter, $time, $conds ) {
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
$countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' );
$totalKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'total' );
$condsKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'conds' );
@ -784,7 +784,7 @@ class AbuseFilter {
* @return array
*/
public static function getFilterProfile( $filter ) {
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
$countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' );
$totalKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'total' );
$condsKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'conds' );
@ -1417,7 +1417,7 @@ class AbuseFilter {
// To distinguish from stuff stored directly
$var_dump = "stored-text:$var_dump";
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
// Increment trigger counter
$stash->incr( self::filterMatchesKey() );
@ -1749,7 +1749,7 @@ class AbuseFilter {
if ( !$user->isAnon() ) {
// Block for 3-7 days.
$blockPeriod = (int)mt_rand( 3 * 86400, 7 * 86400 );
ObjectCache::getMainStashInstance()->set(
MediaWikiServices::getInstance()->getMainObjectStash()->set(
self::autoPromoteBlockKey( $user ), true, $blockPeriod
);
@ -1916,7 +1916,7 @@ class AbuseFilter {
public static function isThrottled( $throttleId, $types, Title $title, $rateCount,
$ratePeriod, $global = false
) {
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
$key = self::throttleKey( $throttleId, $types, $title, $global );
$count = intval( $stash->get( $key ) );
@ -2050,7 +2050,7 @@ class AbuseFilter {
private static function recordStats( $filters, $group = 'default' ) {
global $wgAbuseFilterConditionLimit, $wgAbuseFilterProfileActionsCap;
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
// Figure out if we've triggered overflows and blocks.
$overflow_triggered = ( self::$condCount > $wgAbuseFilterConditionLimit );
@ -2106,7 +2106,8 @@ class AbuseFilter {
* @param string[] $filters The filters to check
*/
private static function checkEmergencyDisable( $group, $filters ) {
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
// @ToDo this is an amount between 1 and AbuseFilterProfileActionsCap, which means that the
// reliability of this number may strongly vary. We should instead use a fixed one.
$totalActions = $stash->get( self::filterUsedKey( $group ) );
@ -2648,7 +2649,7 @@ class AbuseFilter {
}
$globalRulesKey = self::getGlobalRulesKey( $group );
ObjectCache::getMainWANInstance()->touchCheckKey( $globalRulesKey );
MediaWikiServices::getInstance()->getMainWANObjectCache()->touchCheckKey( $globalRulesKey );
}
// Logging

View file

@ -317,7 +317,7 @@ class AbuseFilterHooks {
$key,
30,
function () use ( $key ) {
return (int)ObjectCache::getMainStashInstance()->get( $key );
return (int)MediaWikiServices::getInstance()->getMainObjectStash()->get( $key );
}
);

View file

@ -1,5 +1,7 @@
<?php
use MediaWiki\MediaWikiServices;
class AbuseFilterViewEdit extends AbuseFilterView {
public static $mLoadedRow = null, $mLoadedActions = null;
/**
@ -245,7 +247,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
if ( $filter !== 'new' ) {
// Statistics
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
$matches_count = (int)$stash->get( AbuseFilter::filterMatchesKey( $filter ) );
$total = (int)$stash->get( AbuseFilter::filterUsedKey( $row->af_group ) );

View file

@ -1,5 +1,7 @@
<?php
use MediaWiki\MediaWikiServices;
/**
* The default view used in Special:AbuseFilter
*/
@ -276,7 +278,7 @@ class AbuseFilterViewList extends AbuseFilterView {
* Show stats
*/
public function showStatus() {
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
$overflow_count = (int)$stash->get( AbuseFilter::filterLimitReachedKey() );
$match_count = (int)$stash->get( AbuseFilter::filterMatchesKey() );
$total_count = 0;

View file

@ -1,5 +1,7 @@
<?php
use MediaWiki\MediaWikiServices;
class AbuseFilterViewRevert extends AbuseFilterView {
public $origPeriodStart, $origPeriodEnd, $mPeriodStart, $mPeriodEnd;
public $mReason;
@ -275,7 +277,7 @@ class AbuseFilterViewRevert extends AbuseFilterView {
$logEntry->publish( $logEntry->insert() );
return true;
case 'blockautopromote':
ObjectCache::getMainStashInstance()->delete(
MediaWikiServices::getInstance()->getMainObjectStash()->delete(
AbuseFilter::autoPromoteBlockKey( User::newFromId( $result['userid'] ) )
);
return true;

View file

@ -1,5 +1,7 @@
<?php
use MediaWiki\MediaWikiServices;
class ApiAbuseFilterUnblockAutopromote extends ApiBase {
/**
* @see ApiBase::execute()
@ -19,7 +21,7 @@ class ApiAbuseFilterUnblockAutopromote extends ApiBase {
}
$key = AbuseFilter::autoPromoteBlockKey( $user );
$stash = ObjectCache::getMainStashInstance();
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
if ( !$stash->get( $key ) ) {
$this->dieWithError( [ 'abusefilter-reautoconfirm-none', $user->getName() ], 'notsuspended' );
}