Page MenuHomePhabricator

For categories whose titles begin with a local interwiki prefix, CategoryTree displays the wrong category
Open, MediumPublic

Description

Author: md5

Description:
On English Wiktionary, there is a convention of using language codes as prefixes for topical category names in languages other than English. For example, there is a category called "Category:Fruits" for English words related to fruits, but it also has subcategories like "Category:es:Fruits" and "Category:la:Fruits" for Spanish and Latin respectively. You'll notice that these name prefixes generally match the interwiki names for the other language Wiktionaries.

The issue that I'm seeing is that when using the AJAX-based category expansion, the wrong set of categories is being returned when expanding something like "Category:la:Fruits". It effectively returns the subcategories for "Category:Fruits" instead of "Category:la:Fruits".

I tracked the issue down to the "makeTitle" function in CategoryTreeFunctions.php, but I'm not sure what the right fix is. What seems to be happening is that there is a call to Title::newFromText that looks like this:

$t = Title::newFromText( $title, NS_CATEGORY );

In the case of "Category:la:Fruits", the value of $title is "la:Fruits". Inside of "newFromText", this is passed to Title::secureAndSplit which interprets the the "la:" as an interwiki prefix and strips it, giving us "Category:Fruits" instead of "Category:la:Fruits".

In this particular case, I think it would work correctly to pass "Category:$title" to Title::newFromText, but that would end up showing weird behavior if $title already had a "Category:" or ":Category" prefix. Like I said, I'm not sure whether the right fix is in the "makeTitle" function of CategoryTreeFunctions.php or if something needs to be done in the Title class (e.g. taking mNamespace into account in the interwiki portion of secureAndSplit since "iw:PAGENAME" shouldn't actually be an interwiki link unless the default namespace is NS_MAIN). It seems like it's hard for me actually test a fix without bringing up a full MediaWiki installation that has the same interwiki map as English Wiktionary.

Here is an example URL that is used when expanding "Category:la:Fruits" in a category tree:
http://en.wiktionary.org/w/index.php?action=ajax&rs=efCategoryTreeAjaxWrapper&rsargs[]=la:Fruits&rsargs[]=0


Version: unspecified
Severity: normal
URL: http://en.wiktionary.org/wiki/Category:Latin_language

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:50 PM
bzimport set Reference to bz10883.
bzimport added a subscriber: Unknown Object (MLST).

The fix works correctly _most_ of the time, but not always. If the interwiki prefix in question is specifically $wgLocalInterwiki, the “Redundant interwiki prefix to the local wiki” is automatically discarded in Title::secureAndSplit(), and Title::getInterWiki() is empty afterwards. So, trying to expand e.g. Category:en:Fruits on the English Wiktionary results in expansion of Category:Fruits instead. See

http://en.wiktionary.org/w/index.php?action=ajax&rs=efCategoryTreeAjaxWrapper&rsargs[]=en:Fruits&rsargs[]=0

I am still not sure why CategoryTree::makeTitle() is so complicated, instead of just using something like
$t = Title::newFromText( "Category:$title" );

Or, passing the _whole_ title (including the Category: prefix) from the client, and not doing any magic whatsoever. (I think this is not the first bug caused by trusting Title::newFromText() would always use $defaultNamespace.)

Change 381290 had a related patch set uploaded (by Fomafix; owner: Fomafix):
[mediawiki/extensions/CategoryTree@master] Always use title without prefix "Category:"

https://gerrit.wikimedia.org/r/381290

Update regarding topic category structure, as it is no longer true, as the original post states, that Category:Fruits contains English words related to fruit. The category structure has changed so that Category:Topicname is an umbrella category that only contains categories: language-specific categories prefixed by a language code (Category:languagecode:Topicname) as well as other umbrella categories (Category:Subtopicname). Here, replace "Topicname", "topicname", and "Subtopicname" with things like "Fruits", "fruits" and "Apple cultivars". To use the example in the original post, now Category:Fruits only contains categories such as Category:en:Fruits, Category:fr:Fruits, Category:Apple cultivars, Category:Banana cultivars. English words related to fruit are now found in Category:en:Fruits.