Remove use of strencode() outside Database classes
authorKevin Israel <pleasestand@live.com>
Mon, 2 Jun 2014 04:47:10 +0000 (00:47 -0400)
committerKevin Israel <pleasestand@live.com>
Mon, 2 Jun 2014 17:45:26 +0000 (13:45 -0400)
Change-Id: Idbc38d8089541e5154b2601297b429f7433fd59e

includes/installer/MysqlUpdater.php
includes/search/SearchMssql.php
includes/search/SearchMySQL.php
includes/search/SearchSqlite.php
maintenance/namespaceDupes.php
maintenance/rebuildrecentchanges.php

index 8b77cb1..c538921 100644 (file)
@@ -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" );
                }
        }
index 4960c42..0d1663f 100644 (file)
@@ -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";
        }
 
        /**
index 77a0c43..8ff2640 100644 (file)
@@ -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 ) {
index 62fb236..8e820f3 100644 (file)
@@ -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 ) {
index a152091..ea86e88 100644 (file)
@@ -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__
+               ) );
        }
 
        /**
index 203d795..f4b0505 100644 (file)
@@ -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