Parent5446 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/109444


Change subject: Cleanup to ThrottleOverrideHooks::onPingLimiter
......................................................................

Cleanup to ThrottleOverrideHooks::onPingLimiter

* Replaced assert() with an exception
* Removed excess makeList() call
* Made use of supplied User object to get IP address

Bug: 25000
Change-Id: I7545444e0cf71802ae41312e6ff1453020349270
---
M ThrottleOverride.hooks.php
1 file changed, 20 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ThrottleOverride 
refs/changes/44/109444/1

diff --git a/ThrottleOverride.hooks.php b/ThrottleOverride.hooks.php
index 17f0ce3..1e850da 100644
--- a/ThrottleOverride.hooks.php
+++ b/ThrottleOverride.hooks.php
@@ -30,35 +30,40 @@
        }
 
        /**
+        * @throws InvalidArgumentException If $action is invalid
+        *
         * @param User $user
         * @param string $action
         * @param $result
         * @param null|string $ip
+        *
         * @return bool
         */
        public static function onPingLimiter( User &$user, $action, &$result, 
$ip = null ) {
                global $wgRateLimits;
-               assert( $action == 'actcreate' || isset( $wgRateLimits[$action] 
) );
+
+               if ( $action !== 'actcreate' && !isset( $wgRateLimits[$action] 
) ) {
+                       throw new InvalidArgumentException( 'Invalid action 
passed to ' . __METHOD__ );
+               }
 
                $dbr = wfGetDB( DB_SLAVE );
 
-               if( $ip === null ) {
+               if ( $user->isAnon() && IP::isValid( $user->getName() ) ) {
+                       $ip = $user->getName();
+               } elseif ( $ip === null ) {
                        $ip = RequestContext::getMain()->getRequest()->getIP();
                }
+
                $quotedIp = $dbr->addQuotes( IP::toHex( $ip ) );
-               $cond = $dbr->makeList(
+
+               $expiry = $dbr->selectField(
+                       'throttle_override',
+                       'thr_expiry',
                        array(
                                "thr_range_start <= $quotedIp",
                                "thr_range_end >= $quotedIp",
                                'thr_type' . $dbr->buildLike( 
$dbr->anyString(), $action, $dbr->anyString() )
                        ),
-                       LIST_AND
-               );
-
-               $expiry = $dbr->selectField(
-                       'throttle_override',
-                       'thr_expiry',
-                       $cond,
                        __METHOD__,
                        array( 'ORDER BY' => 'thr_expiry DESC' )
                );
@@ -71,7 +76,11 @@
                        // Expired exemption. Delete it from the DB.
                        wfGetDB( DB_MASTER )->delete(
                                'throttle_override',
-                               $cond,
+                               array(
+                                       "thr_range_start <= $quotedIp",
+                                       "thr_range_end >= $quotedIp",
+                                       'thr_type' . $dbr->buildLike( 
$dbr->anyString(), $action, $dbr->anyString() )
+                               ),
                                __METHOD__
                        );
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7545444e0cf71802ae41312e6ff1453020349270
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ThrottleOverride
Gerrit-Branch: master
Gerrit-Owner: Parent5446 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to