Update categorylinks.cl_type when moving a page
authorBartosz Dziewoński <matma.rex@gmail.com>
Sat, 6 Sep 2014 15:17:20 +0000 (17:17 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 15 Sep 2014 00:17:02 +0000 (00:17 +0000)
cl_type might need to be changed if the page was moved between
special-cased namespaces (Category ↔ File ↔ (other)).

Also update cl_collation, which also might have changed in the
meantime.

Bug: 69740
Change-Id: I46032a8ba04d77005731c02680f77a8808974087

includes/Title.php

index ca292ee..7959860 100644 (file)
@@ -3748,7 +3748,7 @@ class Title {
         * @return array|bool True on success, getUserPermissionsErrors()-like array on failure
         */
        public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
-               global $wgUser;
+               global $wgUser, $wgCategoryCollation;
                $err = $this->isValidMoveOperation( $nt, $auth, $reason );
                if ( is_array( $err ) ) {
                        // Auto-block user's IP if the account was "hard" blocked
@@ -3787,12 +3787,21 @@ class Title {
 
                // Refresh the sortkey for this row.  Be careful to avoid resetting
                // cl_timestamp, which may disturb time-based lists on some sites.
+               // @todo This block should be killed, it's duplicating code
+               // from LinksUpdate::getCategoryInsertions() and friends.
                $prefixes = $dbw->select(
                        'categorylinks',
                        array( 'cl_sortkey_prefix', 'cl_to' ),
                        array( 'cl_from' => $pageid ),
                        __METHOD__
                );
+               if ( $nt->getNamespace() == NS_CATEGORY ) {
+                       $type = 'subcat';
+               } elseif ( $nt->getNamespace() == NS_FILE ) {
+                       $type = 'file';
+               } else {
+                       $type = 'page';
+               }
                foreach ( $prefixes as $prefixRow ) {
                        $prefix = $prefixRow->cl_sortkey_prefix;
                        $catTo = $prefixRow->cl_to;
@@ -3800,6 +3809,8 @@ class Title {
                                array(
                                        'cl_sortkey' => Collation::singleton()->getSortKey(
                                                $nt->getCategorySortkey( $prefix ) ),
+                                       'cl_collation' => $wgCategoryCollation,
+                                       'cl_type' => $type,
                                        'cl_timestamp=cl_timestamp' ),
                                array(
                                        'cl_from' => $pageid,