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.
Compare with:
Version: 1.23.0
Severity: minor
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.
Compare with:
Version: 1.23.0
Severity: minor
Subject | Repo | Branch | Lines +/- | |
---|---|---|---|---|
Normalize message name in Allmessages | mediawiki/core | master | +23 -7 |
Change 224438 had a related patch set uploaded (by Sn1per):
[WIP] Normalize message name in Allmessages
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.
The easiest thing to do might be to leave 'name' as it is and add 'normalizedname' as the normalized version.
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.