Merge "API: Warn about POST without Content-Type"
[lhc/web/wiklou.git] / maintenance / cleanupTitles.php
index 50e17d8..cad6122 100644 (file)
@@ -38,15 +38,15 @@ class TitleCleanup extends TableCleanup {
        public function __construct() {
                parent::__construct();
                $this->addDescription( 'Script to clean up broken, unparseable titles' );
+               $this->batchSize = 1000;
        }
 
        /**
         * @param object $row
         */
        protected function processRow( $row ) {
-               global $wgContLang;
                $display = Title::makeName( $row->page_namespace, $row->page_title );
-               $verified = $wgContLang->normalize( $display );
+               $verified = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $display );
                $title = Title::newFromText( $verified );
 
                if ( !is_null( $title )
@@ -137,7 +137,8 @@ class TitleCleanup extends TableCleanup {
                        || $title->getInterwiki()
                        || !$title->canExist()
                ) {
-                       if ( $title->getInterwiki() || !$title->canExist() ) {
+                       $titleImpossible = $title->getInterwiki() || !$title->canExist();
+                       if ( $titleImpossible ) {
                                $prior = $title->getPrefixedDBkey();
                        } else {
                                $prior = $title->getDBkey();
@@ -151,11 +152,16 @@ class TitleCleanup extends TableCleanup {
 
                        # Namespace which no longer exists. Put the page in the main namespace
                        # since we don't have any idea of the old namespace name. See T70501.
-                       if ( !MWNamespace::exists( $ns ) ) {
+                       if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $ns ) ) {
                                $ns = 0;
                        }
 
-                       $clean = 'Broken/' . $prior;
+                       if ( !$titleImpossible && !$title->exists() ) {
+                               // Looks like the current title, after cleaning it up, is valid and available
+                               $clean = $prior;
+                       } else {
+                               $clean = 'Broken/' . $prior;
+                       }
                        $verified = Title::makeTitleSafe( $ns, $clean );
                        if ( !$verified || $verified->exists() ) {
                                $blah = "Broken/id:" . $row->page_id;
@@ -165,7 +171,7 @@ class TitleCleanup extends TableCleanup {
                        $title = $verified;
                }
                if ( is_null( $title ) ) {
-                       $this->error( "Something awry; empty title.", true );
+                       $this->fatalError( "Something awry; empty title." );
                }
                $ns = $title->getNamespace();
                $dest = $title->getDBkey();
@@ -189,5 +195,5 @@ class TitleCleanup extends TableCleanup {
        }
 }
 
-$maintClass = "TitleCleanup";
+$maintClass = TitleCleanup::class;
 require_once RUN_MAINTENANCE_IF_MAIN;