Page MenuHomePhabricator

Display more than one character of the sort key
Closed, DuplicatePublic

Description

Author: thomasV1

Description:
If all articles in a given category have sort keys that begin with the same
letter, only this letter will be displayed when the category is rendered. It
would be better to display more letters, until sort keys are different.

The following patch determines the length of the longest common substring, and
it displays this length+1 characters. I was tested with mediawiki 1.4.

Proposed patch: In file CategoryPage.php, around line 137, replace existing code
with:

				// Page in this category
				array_push( $articles, $sk->makeKnownLinkObj( $title ) ) ;
				array_push( $articles_start_char, $x->cl_sortkey )  ;
			}
		}
		$root_length = 0;
		for ($index = 0 ; $index < count($articles) - 1; $index++){
			if

($articles_start_char[$index][$root_length]!=$articles_start_char[$index+1][$root_length])
{

			   break;			   
			}
			else{
				if($index == count($articles) - 2)	{
				  $root_length = $root_length+1;
				  $index=0;
				}
			}
		}
		for ($index = 0 ; $index < count($articles) ; $index++){		
			$articles_start_char[$index] =

substr($articles_start_char[$index],0,$root_length+1);

		}

		$dbr->freeResult( $res );

Version: unspecified
Severity: enhancement

Details

Reference
bz2802

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 8:41 PM
bzimport set Reference to bz2802.
bzimport added a subscriber: Unknown Object (MLST).

thomasV1 wrote:

Here is an actual patch. it works with 1.5beta3

Attached:

thomasV1 wrote:

patch generated with diff -u.

patch for 1.5beta3.

also, minor fix: $index has to be reset to -1 inside the loop (was 0)

Attached:

avarab wrote:

(In reply to comment #2)

Created an attachment (id=701) [edit]
patch generated with diff -u.

patch for 1.5beta3.

also, minor fix: $index has to be reset to -1 inside the loop (was 0)

Applied to HEAD after some fixes, namely using $wgContLang->truncate() instead
of substr() and formatting.

Marking this as FIXED.

This fix caused bug 2835, so I've backed out the change (revision 1.24 of CategoryPage.php).

Reopening.

thomasV1 wrote:

new patch for utf8 strings

the regression was caused by incorrect handling of utf8 strings.
it should be fixed with this new patch.
(I *know* this code is ugly. please bear with me)

Attached:

it might be better to use the firstChar() and trim() methods on Language, to avoid duplicating ugly UTF-8 code.

thomasV1 wrote:

ok, new patch using firstChar.

I hope ugliness went down to an acceptable level,
although I don't see how to use trim here.

Attached:

rm need-review, the patch is obsolete.

happy.melon.wiki wrote:

Is this rendered obsolete by the 1.17 collation rewrite?

ayg wrote:

The patch might not apply anymore, but the bug is certainly still relevant.

sumanah wrote:

ThomasV, if you're interested in updating your patch to work with current trunk, please join us in the MediaWiki-General channel on freenode IRC to ask for feedback and discuss your approach. Thanks!

btw, a while back I made an extension that does something similar to what this bug requests (but not quite the same thing) - [[mw:extension:CategorySortHeaders]] in case anyone is interested.