Add option to populateChangeTagDef not to update the count
[lhc/web/wiklou.git] / maintenance / cleanupTitles.php
index 8c782d9..7f0e340 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();
@@ -155,7 +156,12 @@ class TitleCleanup extends TableCleanup {
                                $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;