Undo previous commit. Schema changes are a no-no without permission first :-)
[lhc/web/wiklou.git] / maintenance / namespaceDupes.php
index 323aad5..92296eb 100644 (file)
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 # http://www.gnu.org/copyleft/gpl.html
 
+/**
+ * @file
+ * @ingroup Maintenance
+ */
+
 $options = array( 'fix', 'suffix', 'help' );
 
 /** */
 require_once( 'commandLine.inc' );
 
 if(isset( $options['help'] ) ) {
-print <<<END
+print <<<ENDS
 usage: namespaceDupes.php [--fix] [--suffix=<text>] [--help]
     --help          : this help message
     --fix           : attempt to automatically fix errors
@@ -33,7 +38,7 @@ usage: namespaceDupes.php [--fix] [--suffix=<text>] [--help]
                       in place of the standard namespace list.
     --verbose       : Display output for checked namespaces without conflicts
 
-END;
+ENDS;
 die;
 }
 
@@ -75,14 +80,29 @@ class NamespaceConflictChecker {
                        $spaces[$name] = $ns;
                }
                
-               if( !$wgCapitalLinks ) {
-                       // 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 ) {
-                               $lcname = $wgContLang->lcfirst( $name );
-                               $spaces[$lcname] = $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 ) {
+                       $moreNames = array();
+                       $moreNames[] = $wgContLang->uc( $name );
+                       $moreNames[] = $wgContLang->ucfirst( $wgContLang->lc( $name ) );
+                       $moreNames[] = $wgContLang->ucwords( $name );
+                       $moreNames[] = $wgContLang->ucwords( $wgContLang->lc( $name ) );
+                       $moreNames[] = $wgContLang->ucwordbreaks( $name );
+                       $moreNames[] = $wgContLang->ucwordbreaks( $wgContLang->lc( $name ) );
+                       if( !$wgCapitalLinks ) {
+                               foreach( $moreNames as $altName ) {
+                                       $moreNames[] = $wgContLang->lcfirst( $altName );
+                               }
+                               $moreNames[] = $wgContLang->lcfirst( $name );
+                       }
+                       foreach( array_unique( $moreNames ) as $altName ) {
+                               if( $altName !== $name ) {
+                                       $spaces[$altName] = $ns;
+                               }
                        }
                }
+               
                ksort( $spaces );
                asort( $spaces );
                
@@ -175,11 +195,21 @@ class NamespaceConflictChecker {
 
        function reportConflict( $row, $suffix ) {
                $newTitle = Title::makeTitleSafe( $row->namespace, $row->title );
+               if( !$newTitle ) {
+                       // Title is also an illegal title...
+                       // For the moment we'll let these slide to cleanupTitles or whoever.
+                       printf( "... %d (0,\"%s\")\n",
+                               $row->id,
+                               $row->oldtitle );
+                       echo "...  *** cannot resolve automatically; illegal title ***\n";
+                       return false;
+               }
+               
                printf( "... %d (0,\"%s\") -> (%d,\"%s\") [[%s]]\n",
                        $row->id,
                        $row->oldtitle,
                        $newTitle->getNamespace(),
-                       $newTitle->getDbKey(),
+                       $newTitle->getDBkey(),
                        $newTitle->getPrefixedText() );
 
                $id = $newTitle->getArticleId();
@@ -193,8 +223,14 @@ class NamespaceConflictChecker {
 
        function resolveConflict( $row, $resolvable, $suffix ) {
                if( !$resolvable ) {
+                       echo "...  *** old title {$row->title}\n";
                        $row->title .= $suffix;
+                       echo "...  *** new title {$row->title}\n";
                        $title = Title::makeTitleSafe( $row->namespace, $row->title );
+                       if ( ! $title ) {
+                               echo "... !!! invalid title\n";
+                               return false;
+                       }
                        echo "...  *** using suffixed form [[" . $title->getPrefixedText() . "]] ***\n";
                }
                $tables = array( 'page' );
@@ -210,7 +246,7 @@ class NamespaceConflictChecker {
                $this->db->update( $table,
                        array(
                                "{$table}_namespace" => $newTitle->getNamespace(),
-                               "{$table}_title"     => $newTitle->getDbKey(),
+                               "{$table}_title"     => $newTitle->getDBkey(),
                        ),
                        array(
                                "{$table}_namespace" => 0,