* Remove manual query building in search mysql
[lhc/web/wiklou.git] / includes / LinksUpdate.php
index 1d07349..a800fdf 100644 (file)
@@ -67,12 +67,15 @@ class LinksUpdate {
                        $this->mInterlangs[$key] = $title;
                }
 
-               foreach ( $this->mCategories as $cat => &$sortkey ) {
+               foreach ( $this->mCategories as &$sortkey ) {
                        # If the sortkey is longer then 255 bytes,
                        # it truncated by DB, and then doesn't get
                        # matched when comparing existing vs current
                        # categories, causing bug 25254.
-                       $sortkey = substr( $sortkey, 0, 255 );
+                       # Also. substr behaves weird when given "".
+                       if ( $sortkey !== '' ) {
+                               $sortkey = substr( $sortkey, 0, 255 );
+                       }
                }
 
                $this->mRecursive = $recursive;
@@ -435,7 +438,7 @@ class LinksUpdate {
                global $wgContLang, $wgCategoryCollation;
                $diffs = array_diff_assoc( $this->mCategories, $existing );
                $arr = array();
-               foreach ( $diffs as $name => $sortkey ) {
+               foreach ( $diffs as $name => $prefix ) {
                        $nt = Title::makeTitleSafe( NS_CATEGORY, $name );
                        $wgContLang->findVariantLink( $name, $nt, true );
 
@@ -447,23 +450,12 @@ class LinksUpdate {
                                $type = 'page';
                        }
 
-                       # TODO: This is kind of wrong, because someone might set a sort
-                       # key prefix that's the same as the default sortkey for the
-                       # title.  This should be fixed by refactoring code to replace
-                       # $sortkey in this array by a prefix, but it's basically harmless
-                       # (Title::moveTo() has had the same issue for a long time).
-                       if ( $this->mTitle->getCategorySortkey() == $sortkey ) {
-                               $prefix = '';
-                               $sortkey = Collation::singleton()->getSortKey( $sortkey );
-                       } else {
-                               # Treat custom sortkeys as a prefix, so that if multiple
-                               # things are forced to sort as '*' or something, they'll
-                               # sort properly in the category rather than in page_id
-                               # order or such.
-                               $prefix = $sortkey;
-                               $sortkey = Collation::singleton()->getSortKey(
-                                       $this->mTitle->getCategorySortkey( $prefix ) );
-                       }
+                       # Treat custom sortkeys as a prefix, so that if multiple
+                       # things are forced to sort as '*' or something, they'll
+                       # sort properly in the category rather than in page_id
+                       # order or such.
+                       $sortkey = Collation::singleton()->getSortKey(
+                               $this->mTitle->getCategorySortkey( $prefix ) );
 
                        $arr[] = array(
                                'cl_from'    => $this->mId,
@@ -699,11 +691,7 @@ class LinksUpdate {
                        array( 'cl_from' => $this->mId ), __METHOD__, $this->mOptions );
                $arr = array();
                foreach ( $res as $row ) {
-                       if ( $row->cl_sortkey_prefix !== '' ) {
-                               $arr[$row->cl_to] = $row->cl_sortkey_prefix;
-                       } else {
-                               $arr[$row->cl_to] = $this->mTitle->getCategorySortkey();
-                       }
+                       $arr[$row->cl_to] = $row->cl_sortkey_prefix;
                }
                return $arr;
        }