* Added rev_sha1 and ar_sha1 columns to revision/archive tables (useful for bug 25312)
[lhc/web/wiklou.git] / maintenance / namespaceDupes.php
index 4617ab9..b883ea6 100644 (file)
@@ -30,10 +30,10 @@ class NamespaceConflictChecker extends Maintenance {
                parent::__construct();
                $this->mDescription = "";
                $this->addOption( 'fix', 'Attempt to automatically fix errors' );
-               $this->addOption( 'suffix', "Dupes will be renamed with correct namespace with\n" .
-                                                                       "\t\t<text> Appended after the article name", false, true );
-               $this->addOption( 'prefix', "Do an explicit check for the given title prefix\n" .
-                                                                       "\t\tappended after the article name", false, true );
+               $this->addOption( 'suffix', "Dupes will be renamed with correct namespace with " .
+                                                                       "<text> appended after the article name", false, true );
+               $this->addOption( 'prefix', "Do an explicit check for the given title prefix " .
+                                                                       "appended after the article name", false, true );
        }
 
        public function execute() {
@@ -52,7 +52,7 @@ class NamespaceConflictChecker extends Maintenance {
                } else {
                        $retval = $this->checkAll( $fix, $suffix );
                }
-       
+
                if ( $retval ) {
                        $this->output( "\nLooks good!\n" );
                } else {
@@ -62,15 +62,14 @@ class NamespaceConflictChecker extends Maintenance {
 
        /**
         * @todo Document
-        * @param $fix bool Whether or not to fix broken entries
-        * @param $suffix String Suffix to append to renamed articles
+        * @param $fix Boolean: whether or not to fix broken entries
+        * @param $suffix String: suffix to append to renamed articles
         */
        private function checkAll( $fix, $suffix = '' ) {
-               global $wgContLang, $wgNamespaceAliases, $wgCanonicalNamespaceNames;
-               global $wgCapitalLinks;
-               
+               global $wgContLang, $wgNamespaceAliases, $wgCapitalLinks;
+
                $spaces = array();
-               
+
                // List interwikis first, so they'll be overridden
                // by any conflicting local namespaces.
                foreach ( $this->getInterwikiList() as $prefix ) {
@@ -79,7 +78,7 @@ class NamespaceConflictChecker extends Maintenance {
                }
 
                // Now pull in all canonical and alias namespaces...
-               foreach ( $wgCanonicalNamespaceNames as $ns => $name ) {
+               foreach ( MWNamespace::getCanonicalNamespaces() as $ns => $name ) {
                        // This includes $wgExtraNamespaces
                        if ( $name !== '' ) {
                                $spaces[$name] = $ns;
@@ -96,7 +95,7 @@ class NamespaceConflictChecker extends Maintenance {
                foreach ( $wgContLang->getNamespaceAliases() as $name => $ns ) {
                        $spaces[$name] = $ns;
                }
-               
+
                // We'll need to check for lowercase keys as well,
                // since we're doing case-sensitive searches in the db.
                foreach ( $spaces as $name => $ns ) {
@@ -119,10 +118,10 @@ class NamespaceConflictChecker extends Maintenance {
                                }
                        }
                }
-               
+
                ksort( $spaces );
                asort( $spaces );
-               
+
                $ok = true;
                foreach ( $spaces as $name => $ns ) {
                        $ok = $this->checkNamespace( $ns, $name, $fix, $suffix ) && $ok;
@@ -132,8 +131,9 @@ class NamespaceConflictChecker extends Maintenance {
 
        /**
         * Get the interwiki list
+        *
         * @todo Needs to respect interwiki cache!
-        * @return array
+        * @return Array
         */
        private function getInterwikiList() {
                $result = $this->db->select( 'interwiki', array( 'iw_prefix' ) );
@@ -141,16 +141,15 @@ class NamespaceConflictChecker extends Maintenance {
                foreach ( $result as $row ) {
                        $prefixes[] = $row->iw_prefix;
                }
-               $this->db->freeResult( $result );
                return $prefixes;
        }
 
        /**
         * @todo Document
-        * @param $ns int A namespace id
+        * @param $ns Integer: a namespace id
         * @param $name String
-        * @param $fix bool Whether to fix broken entries
-        * @param $suffix String Suffix to append to renamed articles
+        * @param $fix Boolean: whether to fix broken entries
+        * @param $suffix String: suffix to append to renamed articles
         */
        private function checkNamespace( $ns, $name, $fix, $suffix = '' ) {
                $conflicts = $this->getConflicts( $ns, $name );
@@ -169,7 +168,7 @@ class NamespaceConflictChecker extends Maintenance {
                }
                return $ok;
        }
-       
+
        /**
         * @todo: do this for reals
         */
@@ -181,8 +180,9 @@ class NamespaceConflictChecker extends Maintenance {
        /**
         * Find pages in mainspace that have a prefix of the new namespace
         * so we know titles that will need migrating
-        * @param $ns int Namespace id (id for new namespace?)
-        * @param $name String Prefix that is being made a namespace
+        *
+        * @param $ns Integer: namespace id (id for new namespace?)
+        * @param $name String: prefix that is being made a namespace
         */
        private function getConflicts( $ns, $name ) {
                $page  = 'page';
@@ -196,15 +196,15 @@ class NamespaceConflictChecker extends Maintenance {
                        // An interwiki; try an alternate encoding with '-' for ':'
                        $titleSql = $this->db->buildConcat( array( "'$prefix-'", $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() );
+                                          {$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__ );
 
@@ -212,8 +212,6 @@ class NamespaceConflictChecker extends Maintenance {
                foreach ( $result as $row ) {
                        $set[] = $row;
                }
-               $this->db->freeResult( $result );
-
                return $set;
        }
 
@@ -252,9 +250,10 @@ class NamespaceConflictChecker extends Maintenance {
 
        /**
         * Resolve any conflicts
-        * @param $row Row from the page table to fix
-        * @param $resolveable bool 
-        * @param $suffix String Suffix to append to the fixed page
+        *
+        * @param $row Object: row from the page table to fix
+        * @param $resolvable Boolean
+        * @param $suffix String: suffix to append to the fixed page
         */
        private function resolveConflict( $row, $resolvable, $suffix ) {
                if ( !$resolvable ) {
@@ -263,11 +262,12 @@ class NamespaceConflictChecker extends Maintenance {
                                $row->title .= $suffix;
                                $this->output( "...  *** new title {$row->title}\n" );
                                $title = Title::makeTitleSafe( $row->namespace, $row->title );
-                               if ( ! $title ) {
+                               if ( !$title ) {
                                        $this->output( "... !!! invalid title\n" );
                                        return false;
                                }
-                               if ( $id = $title->getArticleId() ) {
+                               $id = $title->getArticleId();
+                               if ( $id ) {
                                        $this->output( "...  *** page exists with ID $id ***\n" );
                                } else {
                                        break;
@@ -281,9 +281,10 @@ class NamespaceConflictChecker extends Maintenance {
 
        /**
         * Resolve a given conflict
-        * @param $row Row from the old broken entry
-        * @param $table String Table to update
-        * @param $prefix String Prefix for column name, like page or ar
+        *
+        * @param $row Object: row from the old broken entry
+        * @param $table String: table to update
+        * @param $prefix String: prefix for column name, like page or ar
         */
        private function resolveConflictOn( $row, $table, $prefix ) {
                $this->output( "... resolving on $table... " );
@@ -305,4 +306,4 @@ class NamespaceConflictChecker extends Maintenance {
 }
 
 $maintClass = "NamespaceConflictChecker";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );