[MediaWiki-commits] [Gerrit] mediawiki...GlobalBlocking[master]: Use Database::buildLike() and Database::anyString() in queries
jenkins-bot has submitted this change and it was merged. Change subject: Use Database::buildLike() and Database::anyString() in queries .. Use Database::buildLike() and Database::anyString() in queries Also use addQuotes() instead of ''. Bug: T147643 Change-Id: I86a30709fc73b9f9e53d217e0d485f115bebf5f3 --- M includes/GlobalBlocking.class.php M includes/api/ApiQueryGlobalBlocks.php 2 files changed, 11 insertions(+), 8 deletions(-) Approvals: Umherirrender: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/GlobalBlocking.class.php b/includes/GlobalBlocking.class.php index 3ce8e83..1330a70 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 ); + $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 ' . $dbr->buildLike( $ipPattern, $dbr->anyString() ), + '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..ede610e 100644 --- a/includes/api/ApiQueryGlobalBlocks.php +++ b/includes/api/ApiQueryGlobalBlocks.php @@ -95,9 +95,9 @@ } $prefix = substr( $lower, 0, 4 ); $this->addWhere( [ - "gb_range_start LIKE '$prefix%'", - "gb_range_start <= '$lower'", - "gb_range_end >= '$upper'" + 'gb_range_start ' . $dbr->buildLike( $prefix, $dbr->anyString() ), + 'gb_range_start <= ' . $dbr->addQuotes( $lower ), + 'gb_range_end >= ' . $dbr->addQuotes( $upper ) ] ); } -- To view, visit https://gerrit.wikimedia.org/r/316226 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I86a30709fc73b9f9e53d217e0d485f115bebf5f3 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/GlobalBlocking Gerrit-Branch: master Gerrit-Owner: GlaisherGerrit-Reviewer: Glaisher Gerrit-Reviewer: Umherirrender Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...GlobalBlocking[master]: Use Database::buildLike() and Database::anyString() in queries
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___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits