Use context when parsing messages in Article::setOldSubtitle
[lhc/web/wiklou.git] / maintenance / namespaceDupes.php
index a152091..27102ad 100644 (file)
@@ -172,22 +172,31 @@ class NamespaceConflictChecker extends Maintenance {
                        return true;
                }
 
+               $resolveableCount = 0;
+
                $ok = true;
                foreach ( $conflicts as $row ) {
                        $resolvable = $this->reportConflict( $row, $suffix );
                        $ok = $ok && $resolvable;
+
+                       if ( $resolvable ) {
+                               $resolveableCount++;
+                       }
+
                        if ( $fix && ( $resolvable || $suffix != '' ) ) {
                                $ok = $this->resolveConflict( $row, $resolvable, $suffix ) && $ok;
                        }
                }
 
+               $this->output( "{$count} conflicts. {$resolveableCount} are resolveable." );
+
                return $ok;
        }
 
        /**
         * @todo Do this for real
-        * @param int $ns
-        * @param string $name
+        * @param int $key
+        * @param string $prefix
         * @param bool $fix
         * @param string $suffix
         * @return bool
@@ -208,35 +217,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__
+               ) );
        }
 
        /**
@@ -266,7 +269,8 @@ class NamespaceConflictChecker extends Maintenance {
                        $row->oldtitle,
                        $newTitle->getNamespace(),
                        $newTitle->getDBkey(),
-                       $newTitle->getPrefixedText() ) );
+                       $newTitle->getPrefixedText() )
+               );
 
                $id = $newTitle->getArticleID();
                if ( $id ) {
@@ -281,7 +285,7 @@ class NamespaceConflictChecker extends Maintenance {
        /**
         * Resolve any conflicts
         *
-        * @param stClass $row Row from the page table to fix
+        * @param stdClass $row Row from the page table to fix
         * @param bool $resolvable
         * @param string $suffix Suffix to append to the fixed page
         * @return bool