Glaisher has uploaded a new change for review.

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

Change subject: Use Database::buildLike() and Database::anyString() in queries
......................................................................

Use Database::buildLike() and Database::anyString() in queries

Bug: T147643
Change-Id: I86a30709fc73b9f9e53d217e0d485f115bebf5f3
---
M includes/GlobalBlocking.class.php
M includes/api/ApiQueryGlobalBlocks.php
2 files changed, 10 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GlobalBlocking 
refs/changes/26/316226/1

diff --git a/includes/GlobalBlocking.class.php 
b/includes/GlobalBlocking.class.php
index 3ce8e83..f74d21d 100644
--- a/includes/GlobalBlocking.class.php
+++ b/includes/GlobalBlocking.class.php
@@ -169,13 +169,16 @@
        static function getRangeCondition( $ip ) {
                $dbr = GlobalBlocking::getGlobalBlockingDatabase( DB_SLAVE );
 
-               $hex_ip = IP::toHex( $ip );
-               $ip_pattern = substr( $hex_ip, 0, 4 ) . '%'; // Don't bother 
checking blocks out of this /16.
-
+               $hexIp = IP::toHex( $ip );
+               // Don't bother checking blocks out of this /16.
+               // @todo Make the range limit configurable
+               $ipPattern = substr( $hexIp, 0, 4 );
+               $ipPattern = $dbr->buildLike( $ipPattern, $dbr->anyString() );
+               $quotedHex = $dbr->addQuotes( $hexIp );
                $cond = [
-                       'gb_range_start like ' . $dbr->addQuotes( $ip_pattern ),
-                       'gb_range_start <= ' . $dbr->addQuotes( $hex_ip ),
-                       'gb_range_end >= ' . $dbr->addQuotes( $hex_ip ), // 
This block in the given range.
+                       "gb_range_start $ipPattern",
+                       "gb_range_start <= $quotedHex",
+                       "gb_range_end >= $quotedHex", // This block in the 
given range.
                        // @todo expiry shouldn't be in this function
                        'gb_expiry > ' . $dbr->addQuotes( $dbr->timestamp( 
wfTimestampNow() ) )
                ];
diff --git a/includes/api/ApiQueryGlobalBlocks.php 
b/includes/api/ApiQueryGlobalBlocks.php
index c1d6a99..4ad794e 100644
--- a/includes/api/ApiQueryGlobalBlocks.php
+++ b/includes/api/ApiQueryGlobalBlocks.php
@@ -95,7 +95,7 @@
                        }
                        $prefix = substr( $lower, 0, 4 );
                        $this->addWhere( [
-                                       "gb_range_start LIKE '$prefix%'",
+                                       'gb_range_start ' . $dbr->buildLike( 
$prefix, $dbr->anyString() ),
                                        "gb_range_start <= '$lower'",
                                        "gb_range_end >= '$upper'"
                                ]

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I86a30709fc73b9f9e53d217e0d485f115bebf5f3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GlobalBlocking
Gerrit-Branch: master
Gerrit-Owner: Glaisher <glaisher.w...@gmail.com>

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

Reply via email to