[MediaWiki-commits] [Gerrit] mediawiki...ThrottleOverride[master]: Add multi-wiki support
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/392577 ) Change subject: Add multi-wiki support .. Add multi-wiki support Add a $wgThrottleOverrideCentralWiki configuration setting which can be used to designate a single wiki in a wiki farm as the location for managing ThrottleOverride exemptions. Bug: T147364 Change-Id: I56fa0866133668a2151ce04510e0021f0ae3cbdd --- M SpecialOverrideThrottle.php M SpecialThrottleOverrideList.php M ThrottleOverride.hooks.php A ThrottleOverrideUtils.php M extension.json 5 files changed, 104 insertions(+), 34 deletions(-) Approvals: Aaron Schulz: Looks good to me, approved jenkins-bot: Verified diff --git a/SpecialOverrideThrottle.php b/SpecialOverrideThrottle.php index a9e1f7b..20109a4 100644 --- a/SpecialOverrideThrottle.php +++ b/SpecialOverrideThrottle.php @@ -125,7 +125,7 @@ $data['Target']['default'] = $this->par; // We need the most recent data here, we're about to change the throttle. - $dbw = wfGetDB( DB_MASTER ); + $dbw = ThrottleOverrideUtils::getCentralDB( DB_MASTER ); $row = $dbw->selectRow( 'throttle_override', [ 'thr_expiry', 'thr_reason', 'thr_type' ], @@ -184,7 +184,7 @@ list( $rangeStart, $rangeEnd ) = $parsedRange; // Save the new exemption - $dbw = wfGetDB( DB_MASTER ); + $dbw = ThrottleOverrideUtils::getCentralDB( DB_MASTER ); $row = [ 'thr_target' => $this->target, 'thr_expiry' => $dbw->encodeExpiry( $data['Expiry'] ), @@ -207,7 +207,7 @@ // Purge the cache $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); - $cache->touchCheckKey( ThrottleOverrideHooks::getBucketKey( $cache, $rangeStart ) ); + $cache->touchCheckKey( ThrottleOverrideUtils::getBucketKey( $cache, $rangeStart ) ); return true; } @@ -221,7 +221,7 @@ * @return int */ public static function getThrottleOverrideId( $ip, $dbtype = DB_REPLICA ) { - $db = wfGetDB( $dbtype ); + $db = ThrottleOverrideUtils::getCentralDB( $dbtype ); $field = $db->selectField( 'throttle_override', 'thr_id', diff --git a/SpecialThrottleOverrideList.php b/SpecialThrottleOverrideList.php index 7113ce3..72e6819 100644 --- a/SpecialThrottleOverrideList.php +++ b/SpecialThrottleOverrideList.php @@ -67,7 +67,7 @@ function onSubmit( array $data, HTMLForm $form = null ) { if ( !wfReadOnly() && !mt_rand( 0, 10 ) ) { // Purge expired entries on one in every 10 queries - $dbw = wfGetDB( DB_MASTER ); + $dbw = ThrottleOverrideUtils::getCentralDB( DB_MASTER ); $method = __METHOD__; $dbw->onTransactionIdle( function () use ( $dbw, $method ) { $dbw->delete( diff --git a/ThrottleOverride.hooks.php b/ThrottleOverride.hooks.php index a08e8ce..40dc2cd 100644 --- a/ThrottleOverride.hooks.php +++ b/ThrottleOverride.hooks.php @@ -45,7 +45,7 @@ * @return bool */ public static function onPingLimiter( User &$user, $action, &$result, $ip = null ) { - global $wgRateLimits; + global $wgRateLimits, $wgThrottleOverrideCentralWiki; if ( $action !== 'actcreate' && !isset( $wgRateLimits[$action] ) ) { return true; @@ -60,10 +60,15 @@ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $expiry = $cache->getWithSetCallback( - $cache->makeKey( 'throttle_override', $action, $hexIp ), + $cache->makeGlobalKey( + 'throttle_override', + $wgThrottleOverrideCentralWiki, + $action, + $hexIp + ), $cache::TTL_HOUR, function ( $cValue, &$ttl, &$setOpts, $asOf ) use ( $ip, $hexIp, $action ) { - $dbr = wfGetDB( DB_REPLICA ); + $dbr = ThrottleOverrideUtils::getCentralDB( DB_REPLICA ); $setOpts += Database::getCacheSetOptions( $dbr ); $expiry = $dbr->selectField( @@ -95,7 +100,7 @@ return ( $expiry === false ) ? self::NO_OVERRIDE : $expiry; }, [ -
[MediaWiki-commits] [Gerrit] mediawiki...ThrottleOverride[master]: Add multi-wiki support
BryanDavis has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392577 ) Change subject: Add multi-wiki support .. Add multi-wiki support Add a $wgThrottleOverrideCentralWiki configuration setting that can be used to designate a single wiki in a wiki farm as the location for managing ThrottleOverride exemptions. Bug: T147364 Change-Id: I56fa0866133668a2151ce04510e0021f0ae3cbdd --- M SpecialOverrideThrottle.php M SpecialThrottleOverrideList.php M ThrottleOverride.hooks.php A ThrottleOverrideUtils.php M extension.json 5 files changed, 77 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ThrottleOverride refs/changes/77/392577/1 diff --git a/SpecialOverrideThrottle.php b/SpecialOverrideThrottle.php index 7599ece..0785f9a 100644 --- a/SpecialOverrideThrottle.php +++ b/SpecialOverrideThrottle.php @@ -124,7 +124,7 @@ $data['Target']['default'] = $this->par; // We need the most recent data here, we're about to change the throttle. - $dbw = wfGetDB( DB_MASTER ); + $dbw = ThrottleOverrideUtils::getCentraDB( DB_MASTER ); $row = $dbw->selectRow( 'throttle_override', [ 'thr_expiry', 'thr_reason', 'thr_type' ], @@ -181,7 +181,7 @@ $logEntry->publish( $logId ); // Save the new exemption - $dbw = wfGetDB( DB_MASTER ); + $dbw = ThrottleOverrideUtils::getCentraDB( DB_MASTER ); $row = [ 'thr_target' => $this->target, 'thr_expiry' => $dbw->encodeExpiry( $data['Expiry'] ), @@ -214,7 +214,7 @@ * @return int */ public static function getThrottleOverrideId( $ip, $dbtype = DB_REPLICA ) { - $db = wfGetDB( $dbtype ); + $db = ThrottleOverrideUtils::getCentraDB( $dbtype ); $field = $db->selectField( 'throttle_override', 'thr_id', diff --git a/SpecialThrottleOverrideList.php b/SpecialThrottleOverrideList.php index 7113ce3..6edfe93 100644 --- a/SpecialThrottleOverrideList.php +++ b/SpecialThrottleOverrideList.php @@ -67,7 +67,7 @@ function onSubmit( array $data, HTMLForm $form = null ) { if ( !wfReadOnly() && !mt_rand( 0, 10 ) ) { // Purge expired entries on one in every 10 queries - $dbw = wfGetDB( DB_MASTER ); + $dbw = ThrottleOverrideUtils::getCentraDB( DB_MASTER ); $method = __METHOD__; $dbw->onTransactionIdle( function () use ( $dbw, $method ) { $dbw->delete( diff --git a/ThrottleOverride.hooks.php b/ThrottleOverride.hooks.php index 6db4026..1dc4e59 100644 --- a/ThrottleOverride.hooks.php +++ b/ThrottleOverride.hooks.php @@ -44,7 +44,7 @@ * @return bool */ public static function onPingLimiter( User &$user, $action, &$result, $ip = null ) { - global $wgRateLimits; + global $wgRateLimits, $wgThrottleOverrideCentralWiki; if ( $action !== 'actcreate' && !isset( $wgRateLimits[$action] ) ) { return true; @@ -59,10 +59,13 @@ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $expiry = $cache->getWithSetCallback( - $cache->makeKey( 'throttle_override', $action, $hexIp ), + $cache->makeKey( + 'throttle_override', + $wgThrottleOverrideCentralWiki, $action, $hexIp + ), $cache::TTL_HOUR, function ( $cValue, &$ttl, &$setOpts, $asOf ) use ( $hexIp, $action ) { - $dbr = wfGetDB( DB_REPLICA ); + $dbr = ThrottleOverrideUtils::getCentraDB( DB_REPLICA ); $setOpts += Database::getCacheSetOptions( $dbr ); $expiry = $dbr->selectField( @@ -111,7 +114,7 @@ return false; } elseif ( $expiry !== false ) { // Expired exemption. Delete it from the DB. - $dbw = wfGetDB( DB_MASTER ); + $dbw = ThrottleOverrideUtils::getCentraDB( DB_MASTER ); $dbw->delete( 'throttle_override', self::makeConds( $dbw, $hexIp, $action ), @@ -162,4 +165,18 @@ return true; } + + public static function onSetupAfterCache() { + global $wgThrottleOverrideCentralWiki; +