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;
+               if ( $wgThrottleOverrideCentralWiki === false ) {
+                       $wgThrottleOverrideCentralWiki = wfWikiId();
+               }
+       }
+
+       public static function onSpecialPageInitList( array &$specialPages ) {
+               if ( ThrottleOverrideUtils::isCentralWiki() ) {
+                       $specialPages['OverrideThrottle'] = 
SpecialOverrideThrottle::class;
+                       $specialPages['ThrottleOverrideList'] = 
SpecialThrottleOverrideList::class;
+               }
+       }
 }
diff --git a/ThrottleOverrideUtils.php b/ThrottleOverrideUtils.php
new file mode 100644
index 0000000..8205252
--- /dev/null
+++ b/ThrottleOverrideUtils.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @section LICENSE
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @copyright © 2017 Wikimedia Foundation and contributors
+ */
+
+class ThrottleOverrideUtils {
+       /**
+        * @return bool
+        */
+       public static function isCentralWiki() {
+               global $wgThrottleOverrideCentralWiki;
+               return wfWikiId() === $wgThrottleOverrideCentralWiki;
+       }
+
+       /**
+        * @param int $index DB_MASTER/DB_REPLICA
+        * @return DBConnRef
+        */
+       public static function getCentraDB( $index ) {
+               global $wgThrottleOverrideCentralWiki;
+               return wfGetLB( $wgThrottleOverrideCentralWiki 
)->getLazyConnectionRef(
+                       $index, [], $wgThrottleOverrideCentralWiki );
+       }
+}
diff --git a/extension.json b/extension.json
index 877be67..75c26da 100644
--- a/extension.json
+++ b/extension.json
@@ -9,10 +9,6 @@
        "AvailableRights": [
                "throttleoverride"
        ],
-       "SpecialPages": {
-               "OverrideThrottle": "SpecialOverrideThrottle",
-               "ThrottleOverrideList": "SpecialThrottleOverrideList"
-       },
        "LogTypes": [
                "throttleoverride"
        ],
@@ -28,6 +24,12 @@
                ],
                "LoadExtensionSchemaUpdates": [
                        "ThrottleOverrideHooks::onLoadExtensionSchemaUpdates"
+               ],
+               "SetupAfterCache": [
+                       "ThrottleOverrideHooks::onSetupAfterCache"
+               ],
+               "SpecialPage_initList": [
+                       "ThrottleOverrideHooks::onSpecialPageInitList"
                ]
        },
        "MessagesDirs": {
@@ -43,9 +45,13 @@
                "SpecialOverrideThrottle": "SpecialOverrideThrottle.php",
                "SpecialThrottleOverrideList": 
"SpecialThrottleOverrideList.php",
                "ThrottleOverridePager": "ThrottleOverridePager.php",
-               "ThrottleOverrideLogFormatter": 
"ThrottleOverrideLogFormatter.php"
+               "ThrottleOverrideLogFormatter": 
"ThrottleOverrideLogFormatter.php",
+               "ThrottleOverrideUtils": "ThrottleOverrideUtils.php"
        },
        "config": {
+               "ThrottleOverrideCentralWiki": {
+                       "value": false
+               },
                "ThrottleOverrideCIDRLimit": {
                        "value": {
                                "IPv4": 16,

-- 
To view, visit https://gerrit.wikimedia.org/r/392577
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I56fa0866133668a2151ce04510e0021f0ae3cbdd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ThrottleOverride
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <bda...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to