(bug 28020) Moving pages causes the cl_sortkey thats appropriate for one of the categ...
authorBrian Wolff <bawolff@users.mediawiki.org>
Mon, 14 Mar 2011 02:19:28 +0000 (02:19 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Mon, 14 Mar 2011 02:19:28 +0000 (02:19 +0000)
But the cl_sortkey_prefix are kept to the right value for the cl_sortkey's that are set to the wrong value, totally messing things up.

End result is: Have a page, with some categories having different sortkeys, move that page, now all the categories have the same
sortkey, but still have their original prefix, so linksupdate things the sortkey is correct. End result is null edits don't fix
the sortkey, nothing but removing and re-adding category will reset sortkey to correct value.

includes/Title.php

index a48cbae..635c759 100644 (file)
@@ -3111,19 +3111,26 @@ class Title {
 
                // Refresh the sortkey for this row.  Be careful to avoid resetting
                // cl_timestamp, which may disturb time-based lists on some sites.
-               $prefix = $dbw->selectField(
+               $prefixes = $dbw->select(
                        'categorylinks',
-                       'cl_sortkey_prefix',
+                       array( 'cl_sortkey_prefix', 'cl_to' ),
                        array( 'cl_from' => $pageid ),
                        __METHOD__
                );
-               $dbw->update( 'categorylinks',
-                       array(
-                               'cl_sortkey' => Collation::singleton()->getSortKey(
-                                       $nt->getCategorySortkey( $prefix ) ),
-                               'cl_timestamp=cl_timestamp' ),
-                       array( 'cl_from' => $pageid ),
-                       __METHOD__ );
+               foreach ( $prefixes as $prefixRow ) {
+                       $prefix = $prefixRow->cl_sortkey_prefix;
+                       $catTo = $prefixRow->cl_to;
+                       $dbw->update( 'categorylinks',
+                               array(
+                                       'cl_sortkey' => Collation::singleton()->getSortKey(
+                                               $nt->getCategorySortkey( $prefix ) ),
+                                       'cl_timestamp=cl_timestamp' ),
+                               array(
+                                       'cl_from' => $pageid,
+                                       'cl_to' => $catTo ),
+                               __METHOD__
+                       );
+               }
 
                if ( $protected ) {
                        # Protect the redirect title as the title used to be...