Page MenuHomePhabricator

TitleWidget lacks sorting-indices for redirect pages
Closed, ResolvedPublic

Description

For each page in a TitleWidget result list (e.g. for a TitleInputWidget) is sorted according to the index value that's returned by the prefix-search API. This works fine for most search results, because each page has its own value, but for redirects it's different. Redirects have a separate section of the API response where the from and to titles are listed along with the index value of the to (target). This is the value that's not being used correctly in TitleWidget.

This is an example of the API response:

{
   "query": {
       "redirects":[
           {"index":3,"from":"Redirect","to":"Redirect target"},
           {"index":4,"from":"Redirect two","to":"Redirect target"}
        ],
        "pages":{
            "-1":{
                "ns":0,"title":"Redirect target","missing":"","contentmodel":"wikitext",
                "pagelanguage":"it","pagelanguagehtmlcode":"it","pagelanguagedir":"ltr"},
            "133":{
                "pageid":133,"ns":0,"title":"Redirect, not a","index":1,
                "contentmodel":"wikitext","pagelanguage":"it","pagelanguagehtmlcode":"it","pagelanguagedir":"ltr",
                "touched":"2021-10-05T09:34:41Z","lastrevid":334,"length":1,"new":""
            }
        }
    }
}

And this is an example of the pageData variable that's built form it in resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js is as follows:

  "Redirect, not a": {
    "known": false,
    "missing": false,
    "redirect": false,
    "disambiguation": false,
    "index": 1,
    "originalData": {}
  },
  "Redirect target": {
    "known": false,
    "missing": true,
    "redirect": false,
    "disambiguation": false,
    "index": NaN,
    "originalData": { …. }
  },
  "Redirect": {
    "missing": false,
    "known": true,
    "redirect": true,
    "disambiguation": false,
    "description": "redirect to Redirect target",
    "index": null,
    "originalData": {}
  },
  "Redirect two": {
    "missing": false,
    "known": true,
    "redirect": true,
    "disambiguation": false,
    "description": "redirect to Redirect target",
    "index": null,
    "originalData": {}
  }
}

Note the non-integer values for index keys.

Event Timeline

Change 726740 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/core@master] Correctly use sort index for redirects in TitleWidget

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

Patch merged, does this need QA?

Change 726740 merged by jenkins-bot:

[mediawiki/core@master] Correctly use sort index for redirects in TitleWidget

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

Samwilson added a subscriber: NRodriguez.

does this need QA?

I'm not sure. I'd sort of think not, as it is a pretty minor change (there aren't that many search results that are going to be reordered by this). @NRodriguez what do you think?

Change 728488 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/core@master] Fix bad calculation in TitleWidget

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

Change 728488 merged by jenkins-bot:

[mediawiki/core@master] Fix bad calculation in TitleWidget

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