Page MenuHomePhabricator

Display categories in sorted order by default
Open, Needs TriagePublic

Description

Summary: If your wiki community has a consensus to change the default sorting order for how all categories are displayed on all pages on your wiki, you can request a change to set $wgSortedCategories=true


Original task description:

Logically the set of categories a given page is in is a *set* not a *list*, and the various internal data structures treat it that way (ie, they store the category name as the *key* of an associative array).

However, PHP tracks the insertion order in an associative array, and so even though logically categories are a set, in practice they tend to be listed in the order in which they happen to appear in the wikitext.

Sort the categories when they are added to OutputPage so that they always appear in sorted order for display purposes.

If there is editor pushback to this change, it means that categories are not actually a set but an ordered list, and we should refactor mediawiki internals to reflect that. But if this change agreed with editor intuition about categories, it means we can safely ignore category order internal to mediawiki core (for example, for selective updates).

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

The community, on the English Wikipedia at least, does have guidelines about category order: https://en.wikipedia.org/wiki/Wikipedia:Categorization#CATORDER.

That, of course, doesn't mean that the community would complain about this change, but it should at least go out in tech news and such before being done.

The very text in that link makes the point that ABC is not mandated, and eponymous categories always come first. In other words, there is frequently a "most relevant to least relevant" sorting, with the least relevant sometimes ABC and sometimes not.

Yes, there would be editor pushback to making all categories ABC everywhere.

Some questions: I suppose that is enforced by editors writing categories in the desired order at the end of the article? But, if a template in the middle of the article (or an infobox) adds a category, I imagine it shows up wherever it showed up in text, right? So, to Scott's question, it is not quite a set, but it an ordered list with the output being generate in textual order?

Change #1067420 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/core@master] Deprecate OutputPage::setCategoryLinks()

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

Change #1067421 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/core@master] Sort categories in OutputPage

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

enforced by editors writing categories in the desired order at the end of the article

Yes.

I imagine it shows up wherever it showed up in text, right

English Wikipedia at least has a separate guideline that says "no categories emitted from templates unless they're maintenance categories", which are usually hidden categories, at least for content namespaces (which for us is just the main space I guess). There are a handful of templates that don't follow it, but those are the exception. For non-content namespaces, more or less anything goes (a common pattern is to put categories in a "header" template for a specific page, such as WP:AN).

Otherwise yes, the list is defined by position in the page.

Regarding other wikis: de.wp's rule about category ordering is "generally, most specific to least". fr.wp has a similar rule to ours, which is "ABC is not necessary". On some the "English" non-Wikipedia wikis, meta basically has no rules, Commons has no rules along these dimensions though I know templates are used extensively there to categorize, Wikibooks, Wikivoyage, and Wiktionary seem to use templates instead of categories, and Wikinews and Wikiversity don't seem to have relevant rules. All these have little on the point of how ABC the list in a specific page is. Eyeballing Wiktionary particularly, they might even prefer to have a different sorting that was consistent but not ABC, something adjustable like the Javascript gadget on Wikidata that changes property orders to be consistent.

Latest version of the patch makes it a configuration option, $wgSortedCategories, which is false by default. It adds a query parameter &sortcat=1 which will sort the categories, which will facilitate the Content-Transform-Team's visualdiff testing by ensuring that differences in category order don't obscure other page differences.

Sorted categories could be turned on for individual wikis which want to opt in, perhaps meta for example, and others as discussion among their communities warrant.

Change #1067420 merged by jenkins-bot:

[mediawiki/core@master] Deprecate OutputPage::setCategoryLinks()

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

Change #1067421 merged by jenkins-bot:

[mediawiki/core@master] Add option to sort categories in OutputPage

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

For Tech News, IIUC from the above, this would be a suitable entry? Please confirm or suggest clarifications:

  • It is now possible for a wiki community to request changing the order in which all pages' categories are displayed, to show in alphabetical order. The default will remain the same as before, with categories being displayed in the order that they appear in the wikitext.

Just dropping this here as slightly related, because it actually asks for a 3rd type of sorting concept: https://meta.wikimedia.org/wiki/Community_Wishlist/Wishes/Sortering_av_kategorier_på_en_side/en

For Tech News, please confirm if this is ready to go and/or suggest clarifications to the proposed-draft above at T373480#10104154. Thanks.

@Quiddity That looks good, although maybe some more detail could be added about how exactly a community request would be made. I don't know the admin process here, but would they say "we want sorted categories" or would it be better to say "we want to set $wgSortedCategories=true"?

@TheDJ maybe open a separate phab task for that? I could imagine how that would work -- we already allow HIDDENCAT on category pages to introduce a new primary sort key, so you could have {{#categorysort:nnnnn}} on the Category page introduce another one... but there's a lot of design work needed, it's not 100% straightforward how it should work.