Page MenuHomePhabricator

API: Change default ordering of page titles namespace
Closed, ResolvedPublic3 Estimated Story Points

Description

Instead of ordering by title, we should change It so that pages get ordered in the following way:

  • Firstly by namespace. e.g. NS_MAIN articles first, followed by NS_TALK, NS_USER etc.. ...
  • Secondly by title

FYI: Note ideally we would sort by time they were added to the collection but we'll do that later. See T95786

Event Timeline

Jdlrobson raised the priority of this task from to Needs Triage.
Jdlrobson updated the task description. (Show Details)
Jdlrobson added a project: Gather.
Jdlrobson added subscribers: Aklapper, Yurik, Jdlrobson.
Jdlrobson renamed this task from API: Support ordering by namespace to API: Change default ordering of page titles namespace.Apr 16 2015, 5:47 PM
Jdlrobson updated the task description. (Show Details)
Jdlrobson set Security to None.
Jdlrobson edited a custom field.

@Yurik this should be trivial to do right?

Which query? please provide a sample api call

@Yurik query would be like http://localhost:8888/w/api.php?action=query&list=listpages&lspid=18
Current response

{
    "query": {
        "listpages": [
            {
                "ns": 2,
                "title": "User:Jdlrobson"
            },
            {
                "ns": 0,
                "title": "Headings"
            },
            {
                "ns": 3,
                "title": "User talk:Jdlrobson"
            },
            {
                "ns": 8,
                "title": "MediaWiki:Jdlrobson"
            },
            {
                "ns": 14,
                "title": "Category:Jdlrobson"
            },
            {
                "ns": 14,
                "title": "Category:Jdlrobson 2"
            },
            {
                "ns": 1,
                "title": "Talk:Jdlrobson"
            }
        ]
    }
}

Expected response:

{
    "query": {
        "listpages": [
            {
                "ns": 0,
                "title": "Headings"
            },
            {
                "ns": 1,
                "title": "Talk:Jdlrobson"
            }
            {
                "ns": 2,
                "title": "User:Jdlrobson"
            },
            {
                "ns": 3,
                "title": "User talk:Jdlrobson"
            },
            {
                "ns": 8,
                "title": "MediaWiki:Jdlrobson"
            },
            {
                "ns": 14,
                "title": "Category:Jdlrobson"
            },
            {
                "ns": 14,
                "title": "Category:Jdlrobson 2"
            }
        ]
    }
}

I was hoping https://gist.github.com/jdlrobson/cc3ed6592b3334d66a57 would do it but it seems the API takes over sorting of the results... what am I doing wrong?

When used as a generator, there is no real sorting. Just like it doesn't
matter in what order you give the "titles" parameter. Your approach would
work for non generator use, and for generator, the "sets" of pages it will
return will be in the right order, but not the titles themselves inside one
result. In other words, simply sort them on the client.

You will have to fix the patch to also order by title, because gli_order is
a unique field, but namespace is not. So continuation is broken

sigh.
Why does the generator not have a concept of sorting? I'd need to do this both on frontend and client and that just sounds horrible.

Generator does have a concept of sorting - it yields batches of page titles
in the given order. The output's <pages> xml/JSON element is a dictionary
of

{pageid:{page properties}, ...}``` elements, so they get sorted by the
numeric ID of the page.

Change 209123 had a related patch set uploaded (by Gergő Tisza):
Add sort "namespace,title" sort option for listpages

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

Why does the generator not have a concept of sorting? I'd need to do this both on frontend and client and that just sounds horrible.

Filed as T98205.

Patch could use more tests, I'll get back to that.

Moving out of sprint. Seems close to completion though so hopefully with those tests we can get this merged sometime soon.

Change 209123 merged by jenkins-bot:
Add sort "namespace,title" sort option for listpages

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

phuedx added a subscriber: phuedx.

I verified this locally.