Revert r78005, verified that r78009 seems to have fixed the problem.
[lhc/web/wiklou.git] / maintenance / updateCollation.php
index f842537..1066fe1 100644 (file)
@@ -15,29 +15,33 @@ class UpdateCollation extends Maintenance {
        public function __construct() {
                parent::__construct();
 
-               global $wgCollationVersion;
+               global $wgCategoryCollation;
                $this->mDescription = <<<TEXT
 This script will find all rows in the categorylinks table whose collation is
-out-of-date (cl_collation != $wgCollationVersion) and repopulate cl_sortkey
+out-of-date (cl_collation != '$wgCategoryCollation') and repopulate cl_sortkey
 using the page title and cl_sortkey_prefix.  If everything's collation is
 up-to-date, it will do nothing.
 TEXT;
 
                #$this->addOption( 'force', 'Run on all rows, even if the collation is supposed to be up-to-date.' );
        }
-       
+
        public function execute() {
-               global $wgCollationVersion, $wgContLang;
+               global $wgCategoryCollation, $wgContLang;
 
                $dbw = wfGetDB( DB_MASTER );
-               $count = $dbw->estimateRowCount(
+               $count = $dbw->selectField(
                        'categorylinks',
-                       array( 'cl_from', 'cl_to', 'cl_sortkey_prefix' ),
-                       'cl_collation != ' . $dbw->addQuotes( $wgCollationVersion ),
+                       'COUNT(*)',
+                       'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
                        __METHOD__
                );
 
-               $this->output( "Fixing around $count rows (estimate might be wrong).\n" );
+               if ( $count == 0 ) {
+                       $this->output( "Collations up-to-date.\n" );
+                       return;
+               }
+               $this->output( "Fixing collation for $count rows.\n" );
 
                $count = 0;
                do {
@@ -47,7 +51,7 @@ TEXT;
                                        'cl_sortkey', 'page_namespace', 'page_title'
                                ),
                                array(
-                                       'cl_collation != ' . $dbw->addQuotes( $wgCollationVersion ),
+                                       'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
                                        'cl_from = page_id'
                                ),
                                __METHOD__,
@@ -57,11 +61,11 @@ TEXT;
                        $dbw->begin();
                        foreach ( $res as $row ) {
                                $title = Title::newFromRow( $row );
-                               $rawSortkey = $title->getCategorySortkey();
                                if ( $row->cl_collation == 0 ) {
                                        # This is an old-style row, so the sortkey needs to be
                                        # converted.
-                                       if ( $row->cl_sortkey == $rawSortkey ) {
+                                       if ( $row->cl_sortkey == $title->getText()
+                                       || $row->cl_sortkey == $title->getPrefixedText() ) {
                                                $prefix = '';
                                        } else {
                                                # Custom sortkey, use it as a prefix
@@ -82,10 +86,12 @@ TEXT;
                                $dbw->update(
                                        'categorylinks',
                                        array(
-                                               'cl_sortkey' => $wgContLang->convertToSortkey( $prefix . $rawSortkey ),
+                                               'cl_sortkey' => $wgContLang->convertToSortkey(
+                                                       $title->getCategorySortkey( $prefix ) ),
                                                'cl_sortkey_prefix' => $prefix,
-                                               'cl_collation' => $wgCollationVersion,
+                                               'cl_collation' => $wgCategoryCollation,
                                                'cl_type' => $type,
+                                               'cl_timestamp = cl_timestamp',
                                        ),
                                        array( 'cl_from' => $row->cl_from, 'cl_to' => $row->cl_to ),
                                        __METHOD__