From 13bb571b11663aaa51c28e39ae345ac1bafd8e06 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sat, 5 Feb 2011 02:16:13 +0000 Subject: [PATCH] (follow up r79706 to address CR comments) Simplify some of the logic in LinksUpdate.php Make it so that by default, the parser consdiers categories to have a sortkey of "" unless specified otherwise. Before, the parser said the sortkey was the page name, and then in LinksUpdate we reset the sortkey (prefix) to "" if it was the same as the page name. This way, the parser uniformly outputs the sortkey prefix, instead of a mix between prefix or pagename. It should be noted, this changes the output of api.php?action=parse for categories that do not have a sortkey. --- includes/LinksUpdate.php | 36 ++++++++++++------------------------ includes/parser/Parser.php | 8 ++++++-- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index 1d07349731..b86ea56581 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -72,7 +72,10 @@ class LinksUpdate { # 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; } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 89bd76d2e0..b18b4336d5 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -5072,7 +5072,11 @@ class Parser { /** * Accessor for $mDefaultSort - * Will use the title/prefixed title if none is set + * Will use the empty string if none is set. + * + * This value is treated as a prefix, so the + * empty string is equivalent to sorting by + * page name. * * @return string */ @@ -5080,7 +5084,7 @@ class Parser { if ( $this->mDefaultSort !== false ) { return $this->mDefaultSort; } else { - return $this->mTitle->getCategorySortkey(); + return ''; } } -- 2.20.1