Page MenuHomePhabricator

SqliteLike-2.1.patch

Authored By
bzimport
Nov 21 2014, 10:51 PM
Size
26 KB
Referenced Files
None
Subscribers
None

SqliteLike-2.1.patch

Index: includes/api/ApiQueryAllCategories.php
===================================================================
--- includes/api/ApiQueryAllCategories.php (revision 55817)
+++ includes/api/ApiQueryAllCategories.php (working copy)
@@ -60,7 +60,7 @@
$from = (is_null($params['from']) ? null : $this->titlePartToKey($params['from']));
$this->addWhereRange('cat_title', $dir, $from, null);
if (isset ($params['prefix']))
- $this->addWhere("cat_title LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
+ $this->addWhere('cat_title' . $db->like( $this->titlePartToKey($params['prefix']), MATCH_STRING ) );
$this->addOption('LIMIT', $params['limit']+1);
$this->addOption('ORDER BY', 'cat_title' . ($params['dir'] == 'descending' ? ' DESC' : ''));
Index: includes/api/ApiQueryAllimages.php
===================================================================
--- includes/api/ApiQueryAllimages.php (revision 55817)
+++ includes/api/ApiQueryAllimages.php (working copy)
@@ -76,7 +76,7 @@
$from = (is_null($params['from']) ? null : $this->titlePartToKey($params['from']));
$this->addWhereRange('img_name', $dir, $from, null);
if (isset ($params['prefix']))
- $this->addWhere("img_name LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
+ $this->addWhere('img_name' . $db->like( $this->titlePartToKey($params['prefix']), MATCH_STRING ) );
if (isset ($params['minsize'])) {
$this->addWhere('img_size>=' . intval($params['minsize']));
Index: includes/api/ApiQueryAllLinks.php
===================================================================
--- includes/api/ApiQueryAllLinks.php (revision 55817)
+++ includes/api/ApiQueryAllLinks.php (working copy)
@@ -84,7 +84,7 @@
if (!is_null($params['from']))
$this->addWhere('pl_title>=' . $db->addQuotes($this->titlePartToKey($params['from'])));
if (isset ($params['prefix']))
- $this->addWhere("pl_title LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
+ $this->addWhere('pl_title' . $db->like( $this->titlePartToKey($params['prefix']), MATCH_STRING ) );
$this->addFields(array (
'pl_title',
Index: includes/api/ApiQueryAllpages.php
===================================================================
--- includes/api/ApiQueryAllpages.php (revision 55817)
+++ includes/api/ApiQueryAllpages.php (working copy)
@@ -65,7 +65,7 @@
$from = (is_null($params['from']) ? null : $this->titlePartToKey($params['from']));
$this->addWhereRange('page_title', $dir, $from, null);
if (isset ($params['prefix']))
- $this->addWhere("page_title LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
+ $this->addWhere('page_title' . $db->like($this->titlePartToKey($params['prefix']), MATCH_STRING));
if (is_null($resultPageSet)) {
$selectFields = array (
Index: includes/api/ApiQueryAllUsers.php
===================================================================
--- includes/api/ApiQueryAllUsers.php (revision 55817)
+++ includes/api/ApiQueryAllUsers.php (working copy)
@@ -61,7 +61,7 @@
$this->addWhere('u1.user_name >= ' . $db->addQuotes($this->keyToTitle($params['from'])));
if (!is_null($params['prefix']))
- $this->addWhere('u1.user_name LIKE "' . $db->escapeLike($this->keyToTitle( $params['prefix'])) . '%"');
+ $this->addWhere('u1.user_name' . $db->like($this->keyToTitle($params['prefix']), MATCH_STRING));
if (!is_null($params['group'])) {
// Filter only users that belong to a given group
Index: includes/api/ApiQueryBlocks.php
===================================================================
--- includes/api/ApiQueryBlocks.php (revision 55817)
+++ includes/api/ApiQueryBlocks.php (working copy)
@@ -109,8 +109,10 @@
else
$lower = $upper = IP::toHex($params['ip']);
$prefix = substr($lower, 0, 4);
+
+ $db = $this->getDB();
$this->addWhere(array(
- "ipb_range_start LIKE '$prefix%'",
+ 'ipb_range_start' . $db->like($prefix, MATCH_STRING),
"ipb_range_start <= '$lower'",
"ipb_range_end >= '$upper'"
));
Index: includes/api/ApiQueryExtLinksUsage.php
===================================================================
--- includes/api/ApiQueryExtLinksUsage.php (revision 55817)
+++ includes/api/ApiQueryExtLinksUsage.php (working copy)
@@ -77,14 +77,15 @@
if(is_null($protocol))
$protocol = 'http://';
- $likeQuery = LinkFilter::makeLike($query, $protocol);
+ $likeQuery = LinkFilter::makeLikeArray($query, $protocol);
if (!$likeQuery)
$this->dieUsage('Invalid query', 'bad_query');
- $likeQuery = substr($likeQuery, 0, strpos($likeQuery,'%')+1);
- $this->addWhere('el_index LIKE ' . $db->addQuotes( $likeQuery ));
+
+ $likeQuery = LinkFilter::keepOneWildcard($likeQuery);
+ $this->addWhere('el_index ' . $db->like( $likeQuery ));
}
else if(!is_null($protocol))
- $this->addWhere('el_index LIKE ' . $db->addQuotes( "$protocol%" ));
+ $this->addWhere('el_index ' . $db->like( "$protocol", MATCH_STRING ));
$prop = array_flip($params['prop']);
$fld_ids = isset($prop['ids']);
Index: includes/api/ApiQueryUserContributions.php
===================================================================
--- includes/api/ApiQueryUserContributions.php (revision 55817)
+++ includes/api/ApiQueryUserContributions.php (working copy)
@@ -165,7 +165,7 @@
$this->addWhere($this->getDB()->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0');
// We only want pages by the specified users.
if($this->prefixMode)
- $this->addWhere("rev_user_text LIKE '" . $this->getDB()->escapeLike($this->userprefix) . "%'");
+ $this->addWhere('rev_user_text' . $this->getDB()->like($this->userprefix, MATCH_STRING));
else
$this->addWhereFld('rev_user_text', $this->usernames);
// ... and in the specified timeframe.
Index: includes/Block.php
===================================================================
--- includes/Block.php (revision 55817)
+++ includes/Block.php (working copy)
@@ -286,7 +286,7 @@
$options = array();
$db =& $this->getDBOptions( $options );
$conds = array(
- "ipb_range_start LIKE '$range%'",
+ 'ipb_range_start' . $db->like( $range, MATCH_STRING ),
"ipb_range_start <= '$iaddr'",
"ipb_range_end >= '$iaddr'"
);
Index: includes/db/Database.php
===================================================================
--- includes/db/Database.php (revision 55817)
+++ includes/db/Database.php (working copy)
@@ -1500,6 +1500,33 @@
}
/**
+ * LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match
+ * containing either string literals that will be escaped or predefined constants
+ * MATCH_CHAR and MATCH_STRING that correspond to wildcards '_' and '%', respectively.
+ * Alternatively, the function could be provided with an array of aforementioned parameters.
+ * @ return String: fully built LIKE statement
+ */
+ function like() {
+ $params = func_get_args();
+ if (count($params) > 0 && is_array($params[0])) {
+ $params = $params[0];
+ }
+
+ $s = '';
+ foreach( $params as $value) {
+ // can't use switch here, as it performs loose comparison
+ if( $value === MATCH_CHAR ) {
+ $s .= '_';
+ } elseif( $value === MATCH_STRING ) {
+ $s .= '%';
+ } else {
+ $s .= $this->escapeLike( $value );
+ }
+ }
+ return " LIKE '" . $s . "' ";
+ }
+
+ /**
* Returns an appropriately quoted sequence value for inserting a new row.
* MySQL has autoincrement fields, so this is just NULL. But the PostgreSQL
* subclass will return an integer, and save the value for insertId()
Index: includes/db/DatabaseSqlite.php
===================================================================
--- includes/db/DatabaseSqlite.php (revision 55817)
+++ includes/db/DatabaseSqlite.php (working copy)
@@ -371,6 +371,14 @@
function quote_ident($s) { return $s; }
+ function like() {
+ $params = func_get_args();
+ if ( count( $params ) > 0 && is_array( $params[0] ) ) {
+ $params = $params[0];
+ }
+ return parent::like( $params ) . "ESCAPE '\' ";
+ }
+
/**
* How lagged is this slave?
*/
Index: includes/Defines.php
===================================================================
--- includes/Defines.php (revision 55817)
+++ includes/Defines.php (working copy)
@@ -31,6 +31,9 @@
define( 'DB_READ', -1 );
define( 'DB_WRITE', -2 );
+# Constants for Database::like()
+define( 'MATCH_CHAR', 1 );
+define( 'MATCH_STRING', 2 );
/**#@+
* Virtual namespaces; don't appear in the page database
Index: includes/filerepo/LocalRepo.php
===================================================================
--- includes/filerepo/LocalRepo.php (revision 55817)
+++ includes/filerepo/LocalRepo.php (working copy)
@@ -49,7 +49,7 @@
$ext = File::normalizeExtension($ext);
$inuse = $dbw->selectField( 'oldimage', '1',
array( 'oi_sha1' => $sha1,
- "oi_archive_name LIKE '%.{$ext}'",
+ 'oi_archive_name ' . $dbw->like( MATCH_STRING, ".$ext" ),
$dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE ),
__METHOD__, array( 'FOR UPDATE' ) );
}
Index: includes/LinkFilter.php
===================================================================
--- includes/LinkFilter.php (revision 55817)
+++ includes/LinkFilter.php (working copy)
@@ -49,8 +49,10 @@
* @static
* @param $filterEntry String: domainparts
* @param $prot String: protocol
+ * @deprecated Use makeLikeArray() and pass result to Database::like() instead
*/
public static function makeLike( $filterEntry , $prot = 'http://' ) {
+ wfDeprecated( __METHOD__ );
$db = wfGetDB( DB_MASTER );
if ( substr( $filterEntry, 0, 2 ) == '*.' ) {
$subdomains = true;
@@ -105,4 +107,98 @@
}
return $like;
}
+
+ /**
+ * Make an array to be used for calls to Database::like(), which will match the specified
+ * string. There are several kinds of filter entry:
+ * *.domain.com - Produces http://com.domain.%, matches domain.com
+ * and www.domain.com
+ * domain.com - Produces http://com.domain./%, matches domain.com
+ * or domain.com/ but not www.domain.com
+ * *.domain.com/x - Produces http://com.domain.%/x%, matches
+ * www.domain.com/xy
+ * domain.com/x - Produces http://com.domain./x%, matches
+ * domain.com/xy but not www.domain.com/xy
+ *
+ * Asterisks in any other location are considered invalid.
+ *
+ * @static
+ * @param $filterEntry String: domainparts
+ * @param $prot String: protocol
+ */
+ public static function makeLikeArray( $filterEntry , $prot = 'http://' ) {
+ $db = wfGetDB( DB_MASTER );
+ if ( substr( $filterEntry, 0, 2 ) == '*.' ) {
+ $subdomains = true;
+ $filterEntry = substr( $filterEntry, 2 );
+ if ( $filterEntry == '' ) {
+ // We don't want to make a clause that will match everything,
+ // that could be dangerous
+ return false;
+ }
+ } else {
+ $subdomains = false;
+ }
+ // No stray asterisks, that could cause confusion
+ // It's not simple or efficient to handle it properly so we don't
+ // handle it at all.
+ if ( strpos( $filterEntry, '*' ) !== false ) {
+ return false;
+ }
+ $slash = strpos( $filterEntry, '/' );
+ if ( $slash !== false ) {
+ $path = substr( $filterEntry, $slash );
+ $host = substr( $filterEntry, 0, $slash );
+ } else {
+ $path = '/';
+ $host = $filterEntry;
+ }
+ // Reverse the labels in the hostname, convert to lower case
+ // For emails reverse domainpart only
+ if ( $prot == 'mailto:' && strpos($host, '@') ) {
+ // complete email adress
+ $mailparts = explode( '@', $host );
+ $domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) );
+ $host = $domainpart . '@' . $mailparts[0];
+ $like = array( "$prot$host", MATCH_STRING );
+ } elseif ( $prot == 'mailto:' ) {
+ // domainpart of email adress only. do not add '.'
+ $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) );
+ $like = array( "$prot$host", MATCH_STRING );
+ } else {
+ $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) );
+ if ( substr( $host, -1, 1 ) !== '.' ) {
+ $host .= '.';
+ }
+ $like = array( "$prot$host" );
+
+ if ( $subdomains ) {
+ $like[] = MATCH_STRING;
+ }
+ if ( !$subdomains || $path !== '/' ) {
+ $like[] = $path;
+ $like[] = MATCH_STRING;
+ }
+ }
+ return $like;
+ }
+
+ /**
+ * Filters an array returned by makeLikeArray(), removing everything past first MATCH_STRING.
+ * @static
+ * @param $arr array: array to filter
+ * @return filtered array
+ */
+ public static function keepOneWildcard( $arr ) {
+ if( !is_array( $arr ) ) {
+ return $arr;
+ }
+
+ $pos = array_search( MATCH_STRING, $arr, TRUE );
+ if ( $pos === FALSE ) { // strict comparison must be used here
+ return $arr;
+ }
+
+ return array_slice( $arr, 0, $pos + 1 );
+ }
}
Index: includes/LogEventsList.php
===================================================================
--- includes/LogEventsList.php (revision 55817)
+++ includes/LogEventsList.php (working copy)
@@ -752,6 +752,7 @@
$this->title = $title->getPrefixedText();
$ns = $title->getNamespace();
+ $db = $this->mDb;
# Using the (log_namespace, log_title, log_timestamp) index with a
# range scan (LIKE) on the first two parts, instead of simple equality,
# makes it unusable for sorting. Sorted retrieval using another index
@@ -764,10 +765,8 @@
# log entries for even the busiest pages, so it can be safely scanned
# in full to satisfy an impossible condition on user or similar.
if( $pattern && !$wgMiserMode ) {
- # use escapeLike to avoid expensive search patterns like 't%st%'
- $safetitle = $this->mDb->escapeLike( $title->getDBkey() );
$this->mConds['log_namespace'] = $ns;
- $this->mConds[] = "log_title LIKE '$safetitle%'";
+ $this->mConds[] = 'log_title ' . $db->like( $title->getDBkey(), MATCH_STRING );
$this->pattern = $pattern;
} else {
$this->mConds['log_namespace'] = $ns;
@@ -775,9 +774,9 @@
}
// Paranoia: avoid brute force searches (bug 17342)
if( !$wgUser->isAllowed( 'deleterevision' ) ) {
- $this->mConds[] = $this->mDb->bitAnd('log_deleted', LogPage::DELETED_ACTION) . ' = 0';
+ $this->mConds[] = $db->bitAnd('log_deleted', LogPage::DELETED_ACTION) . ' = 0';
} else if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
- $this->mConds[] = $this->mDb->bitAnd('log_deleted', LogPage::SUPPRESSED_ACTION) .
+ $this->mConds[] = $db->bitAnd('log_deleted', LogPage::SUPPRESSED_ACTION) .
' != ' . LogPage::SUPPRESSED_ACTION;
}
}
Index: includes/MessageCache.php
===================================================================
--- includes/MessageCache.php (revision 55817)
+++ includes/MessageCache.php (working copy)
@@ -318,12 +318,11 @@
# database or in code.
if ( $code !== $wgContLanguageCode ) {
# Messages for particular language
- $escapedCode = $dbr->escapeLike( $code );
- $conds[] = "page_title like '%%/$escapedCode'";
+ $conds[] = 'page_title' . $dbr->like( MATCH_STRING, "/$code" );
} else {
# Effectively disallows use of '/' character in NS_MEDIAWIKI for uses
# other than language code.
- $conds[] = "page_title not like '%%/%%'";
+ $conds[] = 'page_title NOT' . $dbr->like( MATCH_STRING, '/', MATCH_STRING );
}
}
Index: includes/specials/SpecialIpblocklist.php
===================================================================
--- includes/specials/SpecialIpblocklist.php (revision 55817)
+++ includes/specials/SpecialIpblocklist.php (working copy)
@@ -262,10 +262,9 @@
// Fixme -- encapsulate this sort of query-building.
$dbr = wfGetDB( DB_SLAVE );
$encIp = $dbr->addQuotes( IP::sanitizeIP($this->ip) );
- $encRange = $dbr->addQuotes( "$range%" );
$encAddr = $dbr->addQuotes( $iaddr );
$conds[] = "(ipb_address = $encIp) OR
- (ipb_range_start LIKE $encRange AND
+ (ipb_range_start" . $dbr->like( $range, MATCH_STRING ) . " AND
ipb_range_start <= $encAddr
AND ipb_range_end >= $encAddr)";
} else {
Index: includes/specials/SpecialLinkSearch.php
===================================================================
--- includes/specials/SpecialLinkSearch.php (revision 55817)
+++ includes/specials/SpecialLinkSearch.php (working copy)
@@ -96,11 +96,11 @@
*/
static function mungeQuery( $query , $prot ) {
$field = 'el_index';
- $rv = LinkFilter::makeLike( $query , $prot );
+ $rv = LinkFilter::makeLikeArray( $query , $prot );
if ($rv === false) {
//makeLike doesn't handle wildcard in IP, so we'll have to munge here.
if (preg_match('/^(:?[0-9]{1,3}\.)+\*\s*$|^(:?[0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]*\*\s*$/', $query)) {
- $rv = $prot . rtrim($query, " \t*") . '%';
+ $rv = array( $prot . rtrim($query, " \t*"), MATCH_STRING );
$field = 'el_to';
}
}
@@ -125,8 +125,8 @@
/* strip everything past first wildcard, so that index-based-only lookup would be done */
list( $munged, $clause ) = self::mungeQuery( $this->mQuery, $this->mProt );
- $stripped = substr($munged,0,strpos($munged,'%')+1);
- $encSearch = $dbr->addQuotes( $stripped );
+ $stripped = LinkFilter::keepOneWildcard( $munged );
+ $like = $dbr->like( $stripped );
$encSQL = '';
if ( isset ($this->mNs) && !$wgMiserMode )
@@ -144,7 +144,7 @@
$externallinks $use_index
WHERE
page_id=el_from
- AND $clause LIKE $encSearch
+ AND $clause $like
$encSQL";
}
Index: includes/specials/SpecialListfiles.php
===================================================================
--- includes/specials/SpecialListfiles.php (revision 55817)
+++ includes/specials/SpecialListfiles.php (working copy)
@@ -37,10 +37,7 @@
$nt = Title::newFromUrl( $search );
if( $nt ) {
$dbr = wfGetDB( DB_SLAVE );
- $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
- $m = str_replace( "%", "\\%", $m );
- $m = str_replace( "_", "\\_", $m );
- $this->mQueryConds = array( "LOWER(img_name) LIKE '%{$m}%'" );
+ $this->mQueryConds = array( 'LOWER(img_name)' . $dbr->like( MATCH_STRING, strtolower( $nt->getDBkey() ), MATCH_STRING ) );
}
}
Index: includes/specials/SpecialMovepage.php
===================================================================
--- includes/specials/SpecialMovepage.php (revision 55817)
+++ includes/specials/SpecialMovepage.php (working copy)
@@ -416,7 +416,7 @@
)
) ) {
$conds = array(
- 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
+ 'page_title' . $dbr->like( $ot->getDBkey() . '/', MATCH_STRING )
.' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
);
$conds['page_namespace'] = array();
Index: includes/specials/SpecialNewimages.php
===================================================================
--- includes/specials/SpecialNewimages.php (revision 55817)
+++ includes/specials/SpecialNewimages.php (working copy)
@@ -69,8 +69,7 @@
if ( $wpIlMatch != '' && !$wgMiserMode) {
$nt = Title::newFromUrl( $wpIlMatch );
if( $nt ) {
- $m = $dbr->escapeLike( strtolower( $nt->getDBkey() ) );
- $where[] = "LOWER(img_name) LIKE '%{$m}%'";
+ $where[] = 'LOWER(img_name) ' . $dbr->like( MATCH_STRING, strtolower( $nt->getDBkey() ), MATCH_STRING );
$searchpar['wpIlMatch'] = $wpIlMatch;
}
}
Index: includes/specials/SpecialPrefixindex.php
===================================================================
--- includes/specials/SpecialPrefixindex.php (revision 55817)
+++ includes/specials/SpecialPrefixindex.php (working copy)
@@ -115,7 +115,7 @@
array( 'page_namespace', 'page_title', 'page_is_redirect' ),
array(
'page_namespace' => $namespace,
- 'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
+ 'page_title' . $dbr->like( $prefixKey, MATCH_STRING ),
'page_title >= ' . $dbr->addQuotes( $fromKey ),
),
__METHOD__,
Index: includes/specials/SpecialUndelete.php
===================================================================
--- includes/specials/SpecialUndelete.php (revision 55817)
+++ includes/specials/SpecialUndelete.php (working copy)
@@ -58,16 +58,15 @@
$title = Title::newFromText( $prefix );
if( $title ) {
$ns = $title->getNamespace();
- $encPrefix = $dbr->escapeLike( $title->getDBkey() );
+ $prefix = $title->getDBkey();
} else {
// Prolly won't work too good
// @todo handle bare namespace names cleanly?
$ns = 0;
- $encPrefix = $dbr->escapeLike( $prefix );
}
$conds = array(
'ar_namespace' => $ns,
- "ar_title LIKE '$encPrefix%'",
+ 'ar_title' . $dbr->like( $prefix, MATCH_STRING ),
);
return self::listPages( $dbr, $conds );
}
Index: includes/specials/SpecialWithoutinterwiki.php
===================================================================
--- includes/specials/SpecialWithoutinterwiki.php (revision 55817)
+++ includes/specials/SpecialWithoutinterwiki.php (working copy)
@@ -53,7 +53,7 @@
function getSQL() {
$dbr = wfGetDB( DB_SLAVE );
list( $page, $langlinks ) = $dbr->tableNamesN( 'page', 'langlinks' );
- $prefix = $this->prefix ? "AND page_title LIKE '" . $dbr->escapeLike( $this->prefix ) . "%'" : '';
+ $prefix = $this->prefix ? 'AND page_title' . $dbr->like( $this->prefix , MATCH_STRING ) : '';
return
"SELECT 'Withoutinterwiki' AS type,
page_namespace AS namespace,
Index: includes/Title.php
===================================================================
--- includes/Title.php (revision 55817)
+++ includes/Title.php (working copy)
@@ -1656,8 +1656,7 @@
$dbr = wfGetDB( DB_SLAVE );
$conds['page_namespace'] = $this->getNamespace();
- $conds[] = 'page_title LIKE ' . $dbr->addQuotes(
- $dbr->escapeLike( $this->getDBkey() ) . '/%' );
+ $conds[] = 'page_title ' . $dbr->like( $this->getDBkey() . '/', MATCH_STRING );
$options = array();
if( $limit > -1 )
$options['LIMIT'] = $limit;
Index: maintenance/cleanupSpam.php
===================================================================
--- maintenance/cleanupSpam.php (revision 55817)
+++ maintenance/cleanupSpam.php (working copy)
@@ -40,7 +40,7 @@
$wgUser->addToDatabase();
}
$spec = $this->getArg();
- $like = LinkFilter::makeLike( $spec );
+ $like = LinkFilter::makeLikeArray( $spec );
if ( !$like ) {
$this->error( "Not a valid hostname specification: $spec", true );
}
@@ -53,7 +53,7 @@
$dbr = wfGetDB( DB_SLAVE, array(), $wikiID );
$count = $dbr->selectField( 'externallinks', 'COUNT(*)',
- array( 'el_index LIKE ' . $dbr->addQuotes( $like ) ), __METHOD__ );
+ array( 'el_index' . $dbr->like( $like ) ), __METHOD__ );
if ( $count ) {
$found = true;
passthru( "php cleanupSpam.php --wiki='$wikiID' $spec | sed 's/^/$wikiID: /'" );
@@ -69,7 +69,7 @@
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'externallinks', array( 'DISTINCT el_from' ),
- array( 'el_index LIKE ' . $dbr->addQuotes( $like ) ), __METHOD__ );
+ array( 'el_index' . $dbr->like( $like ) ), __METHOD__ );
$count = $dbr->numRows( $res );
$this->output( "Found $count articles containing $spec\n" );
foreach ( $res as $row ) {
Index: maintenance/namespaceDupes.php
===================================================================
--- maintenance/namespaceDupes.php (revision 55817)
+++ maintenance/namespaceDupes.php (working copy)
@@ -197,7 +197,6 @@
$table = $this->db->tableName( $page );
$prefix = $this->db->strencode( $name );
- $likeprefix = str_replace( '_', '\\_', $prefix);
$encNamespace = $this->db->addQuotes( $ns );
$titleSql = "TRIM(LEADING '$prefix:' FROM {$page}_title)";
@@ -212,7 +211,7 @@
$titleSql AS title
FROM {$table}
WHERE {$page}_namespace=0
- AND {$page}_title LIKE '$likeprefix:%'";
+ AND {$page}_title " . $this->db->like( $name . ':', MATCH_STRING );
$result = $this->db->query( $sql, __METHOD__ );
Index: maintenance/storage/compressOld.inc
===================================================================
--- maintenance/storage/compressOld.inc (revision 55817)
+++ maintenance/storage/compressOld.inc (working copy)
@@ -105,7 +105,8 @@
# overwriting bulk storage concat rows. Don't compress external references, because
# the script doesn't yet delete rows from external storage.
$conds = array(
- "old_flags NOT LIKE '%object%' AND old_flags NOT LIKE '%external%'");
+ 'old_flags NOT ' . $dbr->like( MATCH_STRING, 'object', MATCH_STRING ) . ' AND old_flags NOT '
+ . $dbr->like( MATCH_STRING, 'external', MATCH_STRING ) );
if ( $beginDate ) {
if ( !preg_match( '/^\d{14}$/', $beginDate ) ) {
Index: maintenance/storage/moveToExternal.php
===================================================================
--- maintenance/storage/moveToExternal.php (revision 55817)
+++ maintenance/storage/moveToExternal.php (working copy)
@@ -62,7 +62,7 @@
$res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ),
array(
"old_id BETWEEN $blockStart AND $blockEnd",
- "old_flags NOT LIKE '%external%'",
+ 'old_flags NOT ' . $dbr->like( MATCH_STRING, 'external', MATCH_STRING ),
), $fname );
while ( $row = $dbr->fetchObject( $res ) ) {
# Resolve stubs
Index: maintenance/storage/resolveStubs.php
===================================================================
--- maintenance/storage/resolveStubs.php (revision 55817)
+++ maintenance/storage/resolveStubs.php (working copy)
@@ -69,7 +69,7 @@
# Get the (maybe) external row
$externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
- array( 'old_id' => $stub->mOldId, "old_flags LIKE '%external%'" ),
+ array( 'old_id' => $stub->mOldId, 'old_flags' . $dbr->like( MATCH_STRING, 'external', MATCH_STRING ) ),
$fname
);
Index: maintenance/storage/trackBlobs.php
===================================================================
--- maintenance/storage/trackBlobs.php (revision 55817)
+++ maintenance/storage/trackBlobs.php (working copy)
@@ -60,7 +60,7 @@
if ( $this->textClause != '' ) {
$this->textClause .= ' OR ';
}
- $this->textClause .= 'old_text LIKE ' . $dbr->addQuotes( $dbr->escapeLike( "DB://$cluster/" ) . '%' );
+ $this->textClause .= 'old_text' . $dbr->like( "DB://$cluster/", MATCH_STRING );
}
}
return $this->textClause;
@@ -99,7 +99,7 @@
'rev_id > ' . $dbr->addQuotes( $startId ),
'rev_text_id=old_id',
$textClause,
- "old_flags LIKE '%external%'",
+ 'old_flags ' . $dbr->like( MATCH_STRING, 'external', MATCH_STRING ),
),
__METHOD__,
array(
@@ -175,7 +175,7 @@
array(
'old_id>' . $dbr->addQuotes( $startId ),
$textClause,
- "old_flags LIKE '%external%'",
+ 'old_flags ' . $dbr->like( MATCH_STRING, 'external', MATCH_STRING ),
'bt_text_id IS NULL'
),
__METHOD__,

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5728
Default Alt Text
SqliteLike-2.1.patch (26 KB)

Event Timeline