Page MenuHomePhabricator

Preview shows categories in alphabetical order instead of original one
Closed, ResolvedPublic

Description

Steps to reproduce:

  1. Find an article with several categories.
  2. Open it for editing in NWE.
  3. Change something.
  4. Preview.

Expected:
The categories should be shown in source order.

Actual:
The categories are shown in alphabetical order.

Event Timeline

Schnark created this task.Jun 20 2018, 7:40 AM
Restricted Application added a project: VisualEditor. · View Herald TranscriptJun 20 2018, 7:40 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Deskana added a subscriber: Deskana.

A problem with the preview HTML, i.e. Parsoid?

Vvjjkkii renamed this task from Preview shows categories in alphabetical order instead of original one to 0laaaaaaaa.Jul 1 2018, 1:03 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from 0laaaaaaaa to Preview shows categories in alphabetical order instead of original one.Jul 2 2018, 9:47 AM
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.
ssastry added a subscriber: ssastry.Jul 9 2018, 3:45 AM

A problem with the preview HTML, i.e. Parsoid?

I don't think so. Parsoid preserves source order.

[subbu@earth:~/work/wmf/parsoid] echo "a [[Category:Foo]] [[Category:Bar]]" | parse.js --normalize=parsoid

<p>a</p>
<link rel="mw:PageProp/Category" href="./Category:Foo"/> <link rel="mw:PageProp/Category" href="./Category:Bar"/>

See the output order when fed HTML.

[subbu@earth:~/work/wmf/parsoid] echo "a [[Category:Foo]] [[Category:Bar]]" | parse.js --normalize=parsoid | parse.js --html2wt

a
[[Category:Foo]] 
[[Category:Bar]]

Indeed, ve.init.mw.ArticleTarget.prototype.renderCategories does the sorting, and actually seems to do so on purpose, though I don't really understand why (since the hidden cat flag is determined async, the categories might be in random order after the promises are all done, but sorting according to either the sortkey or the category name just doesn't make sense).

Change 444599 had a related patch set uploaded (by DLynch; owner: DLynch):
[mediawiki/extensions/VisualEditor@master] init.mw.ArticleTarget: sort categories correctly in renderCategories

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

DLynch claimed this task.Jul 9 2018, 2:27 PM
DLynch edited projects, added VisualEditor (Current work); removed VisualEditor.
DLynch moved this task from Incoming to Code review on the VisualEditor (Current work) board.

Change 444599 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] init.mw.ArticleTarget: sort categories correctly in renderCategories

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

Change 444920 had a related patch set uploaded (by DLynch; owner: DLynch):
[mediawiki/extensions/VisualEditor@master] init.mw.ArticleTarget: make sure renderCategories preserves order

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

Change 444920 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] init.mw.ArticleTarget: make sure renderCategories preserves order

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

Deskana closed this task as Resolved.Jul 12 2018, 2:53 PM
Deskana triaged this task as Medium priority.