From b43ac16fcc5718424c0c3e3d7ae59ad0c0620080 Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Mon, 2 Jun 2014 00:47:10 -0400 Subject: [PATCH] Remove use of strencode() outside Database classes Change-Id: Idbc38d8089541e5154b2601297b429f7433fd59e --- includes/installer/MysqlUpdater.php | 26 ++++++++-------- includes/search/SearchMssql.php | 4 +-- includes/search/SearchMySQL.php | 4 +-- includes/search/SearchSqlite.php | 4 +-- maintenance/namespaceDupes.php | 44 ++++++++++++---------------- maintenance/rebuildrecentchanges.php | 9 +----- 6 files changed, 38 insertions(+), 53 deletions(-) diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 8b77cb102f..c5389213a5 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -647,25 +647,23 @@ class MysqlUpdater extends DatabaseUpdater { ); global $wgContLang; - foreach ( MWNamespace::getCanonicalNamespaces() as $ns => $name ) { + foreach ( $wgContLang->getNamespaces() as $ns => $name ) { if ( $ns == 0 ) { continue; } $this->output( "Cleaning up broken links for namespace $ns... " ); - - $pagelinks = $this->db->tableName( 'pagelinks' ); - $name = $wgContLang->getNsText( $ns ); - $prefix = $this->db->strencode( $name ); - $likeprefix = str_replace( '_', '\\_', $prefix ); - - $sql = "UPDATE $pagelinks - SET pl_namespace=$ns, - pl_title=TRIM(LEADING '$prefix:' FROM pl_title) - WHERE pl_namespace=0 - AND pl_title LIKE '$likeprefix:%'"; - - $this->db->query( $sql, __METHOD__ ); + $this->db->update( 'pagelinks', + array( + 'pl_namespace' => $ns, + "pl_title = TRIM(LEADING {$this->db->addQuotes( "$name:" )} FROM pl_title)", + ), + array( + 'pl_namespace' => 0, + 'pl_title' . $this->db->buildLike( "$name:", $this->db->anyString() ), + ), + __METHOD__ + ); $this->output( "done.\n" ); } } diff --git a/includes/search/SearchMssql.php b/includes/search/SearchMssql.php index 4960c42462..0d1663f1f4 100644 --- a/includes/search/SearchMssql.php +++ b/includes/search/SearchMssql.php @@ -162,9 +162,9 @@ class SearchMssql extends SearchDatabase { } } - $searchon = $this->db->strencode( join( ',', $q ) ); + $searchon = $this->db->addQuotes( join( ',', $q ) ); $field = $this->getIndexField( $fulltext ); - return "$field, '$searchon'"; + return "$field, $searchon"; } /** diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index 77a0c43431..8ff2640c57 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -125,9 +125,9 @@ class SearchMySQL extends SearchDatabase { wfDebug( __METHOD__ . ": Can't understand search query '{$filteredText}'\n" ); } - $searchon = $this->db->strencode( $searchon ); + $searchon = $this->db->addQuotes( $searchon ); $field = $this->getIndexField( $fulltext ); - return " MATCH($field) AGAINST('$searchon' IN BOOLEAN MODE) "; + return " MATCH($field) AGAINST($searchon IN BOOLEAN MODE) "; } function regexTerm( $string, $wildcard ) { diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index 62fb2364a8..8e820f373d 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -115,9 +115,9 @@ class SearchSqlite extends SearchDatabase { wfDebug( __METHOD__ . ": Can't understand search query '{$filteredText}'\n" ); } - $searchon = $this->db->strencode( $searchon ); + $searchon = $this->db->addQuotes( $searchon ); $field = $this->getIndexField( $fulltext ); - return " $field MATCH '$searchon' "; + return " $field MATCH $searchon "; } function regexTerm( $string, $wildcard ) { diff --git a/maintenance/namespaceDupes.php b/maintenance/namespaceDupes.php index a1520916ec..ea86e880dd 100644 --- a/maintenance/namespaceDupes.php +++ b/maintenance/namespaceDupes.php @@ -208,35 +208,29 @@ class NamespaceConflictChecker extends Maintenance { * @return array */ private function getConflicts( $ns, $name ) { - $page = 'page'; - $table = $this->db->tableName( $page ); - - $prefix = $this->db->strencode( $name ); - $encNamespace = $this->db->addQuotes( $ns ); - - $titleSql = "TRIM(LEADING '$prefix:' FROM {$page}_title)"; + $titleSql = "TRIM(LEADING {$this->db->addQuotes( "$name:" )} FROM page_title)"; if ( $ns == 0 ) { // An interwiki; try an alternate encoding with '-' for ':' - $titleSql = $this->db->buildConcat( array( "'$prefix-'", $titleSql ) ); + $titleSql = $this->db->buildConcat( array( + $this->db->addQuotes( "$name-" ), + $titleSql, + ) ); } - $sql = "SELECT {$page}_id AS id, - {$page}_title AS oldtitle, - $encNamespace + {$page}_namespace AS namespace, - $titleSql AS title, - {$page}_namespace AS oldnamespace - FROM {$table} - WHERE ( {$page}_namespace=0 OR {$page}_namespace=1 ) - AND {$page}_title " . $this->db->buildLike( $name . ':', $this->db->anyString() ); - - $result = $this->db->query( $sql, __METHOD__ ); - - $set = array(); - foreach ( $result as $row ) { - $set[] = $row; - } - - return $set; + return iterator_to_array( $this->db->select( 'page', + array( + 'id' => 'page_id', + 'oldtitle' => 'page_title', + 'namespace' => $this->db->addQuotes( $ns ) . ' + page_namespace', + 'title' => $titleSql, + 'oldnamespace' => 'page_namespace', + ), + array( + 'page_namespace' => array( 0, 1 ), + 'page_title' . $this->db->buildLike( "$name:", $this->db->anyString() ), + ), + __METHOD__ + ) ); } /** diff --git a/maintenance/rebuildrecentchanges.php b/maintenance/rebuildrecentchanges.php index 203d79567b..f4b0505e8b 100644 --- a/maintenance/rebuildrecentchanges.php +++ b/maintenance/rebuildrecentchanges.php @@ -179,13 +179,6 @@ class RebuildRecentchanges extends Maintenance { // Some logs don't go in RC. This should check for that $basicRCLogs = array_diff( $wgLogTypes, array_keys( $wgLogRestrictions ) ); - // Escape...blah blah - $selectLogs = array(); - foreach ( $basicRCLogs as $logtype ) { - $safetype = $dbw->strencode( $logtype ); - $selectLogs[] = "'$safetype'"; - } - $cutoff = time() - $wgRCMaxAge; list( $logging, $page ) = $dbw->tableNamesN( 'logging', 'page' ); $dbw->insertSelect( @@ -219,7 +212,7 @@ class RebuildRecentchanges extends Maintenance { array( 'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ), 'log_user=user_id', - 'log_type IN(' . implode( ',', $selectLogs ) . ')' + 'log_type' => $basicRCLogs, ), __METHOD__, array(), // INSERT options -- 2.20.1