Page MenuHomePhabricator

Allmessages returns un-normalized name
Closed, ResolvedPublic

Description

The API's pages section always returns a normalized name, while the allmessages section returns whatever you passed (i.e., the unnormalized name). The following query demonstrates the issue.

http://en.wikipedia.org/w/api.php?titles=MediaWiki:1movedto2_redir&action=query&prop=info&meta=allmessages&ammessages=1movedto2_redir&format=jsonfm

Compare with:

http://en.wikipedia.org/w/api.php?titles=MediaWiki:1movedto2%20redir&action=query&prop=info&meta=allmessages&ammessages=1movedto2%20redir&format=jsonfm


Version: 1.23.0
Severity: minor

Details

Reference
bz61894

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:53 AM
bzimport added a project: MediaWiki-API.
bzimport set Reference to bz61894.
bzimport added a subscriber: Unknown Object (MLST).
Anomie moved this task from Unsorted to Needs Code on the MediaWiki-API board.Feb 19 2015, 6:39 PM
Sn1per claimed this task.Jul 11 2015, 1:42 PM

Change 224438 had a related patch set uploaded (by Sn1per):
[WIP] Normalize message name in Allmessages

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

I'm not sure if normalizing on its own is sufficient. There might need to be a "normalized" block as well, like there is with a page query, so you can map the input value to the output value.

You mean like a separate block outside of the allmessages array? e.g.

{
    "batchcomplete": "",
    "query": {
        "normalized": [
            {
                "from": "MediaWiki:1movedto2_redir",
                "to": "MediaWiki:1movedto2 redir"
            }
        ],
        "allmessagesNormalized": [
            {
                "from": "1movedto2_redir",
                "to": "1movedto2 redir"
            }
        ],
        "allmessages": [
            {
                "name": "1movedto2 redir",
                "*": "moved [[$1]] to [[$2]] over redirect"
            },
            {
                "name": "mainpage",
                "*": "Main Page"
            }
        ]
    }
}

Also, is the way I'm normalizing (Title::newFromText) acceptable? beacause it feels inelegant or like misappropriation.

I'm not sure if normalizing on its own is sufficient. There might need to be a "normalized" block as well, like there is with a page query, so you can map the input value to the output value.

The easiest thing to do might be to leave 'name' as it is and add 'normalizedname' as the normalized version.

Also, is the way I'm normalizing (Title::newFromText) acceptable? beacause it feels inelegant or like misappropriation.

I'd say not to use Title::newFromText, mainly because MessageCache doesn't actually do that when processing message keys.

What it really does is

$lckey = strtr( $key, ' ', '_' );
if ( ord( $lckey ) < 128 ) {
    $lckey[0] = strtolower( $lckey[0] );
} else {
    $lckey = $wgContLang->lcfirst( $lckey );
}

Not sure whether it's worth trying to abstract that out or just duplicate the code.

As of Patch 2: I put the key normalization code as a static function under MessageCache (there may be a better place to put it). I temporarily don't have a way to test the code but it looks like it should run fine. The normalized name now goes under normalizedname per @Anomie's suggestion.

Change 224438 merged by jenkins-bot:
Normalize message name in Allmessages

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

Sn1per closed this task as Resolved.Jul 16 2015, 2:16 PM

Thanks @Anomie :)