Page MenuHomePhabricator

nsText property of Title objects should contain spaces instead of underscores
Open, Needs TriagePublic

Description

When looking back at T180911, I did some coding and noticed the following inconsistency:

The following return the expected "Discussion utilisateur":

mw.title.new( 'User:Foobar' ).talkNsText
mw.title.new( 'User talk:Foobar' ).talkNsText
mw.title.new( 'User_talk:Foobar' ).talkNsText

… but the following returns "Discussion_utilisateur":

mw.title.new( 'User talk:Foobar' ).nsText

Because this underscore is rather unexcepted, and for consistency between text, nsText, talkNsText, etc. properties, nsText should use spaces instead.


Edit: I have made an exhaustive inspection of the mw.title objects, and case in point, all other properties use spaces:

  • subjectPageTitle
  • text
  • prefixedText
  • talkPageTitle
  • rootText
  • talkNsText
  • basePageTitle
  • baseText
  • subpageText
  • fullText
  • rootPageTitle
  • and the subPageTitle( text ) function

Event Timeline

For instance, two fixes I had to add because of this issue:

(These modules generate values to be fed to {{DISPLAYTITLE:}}, italicizing the subject but not the rest of the page title.)

update: I also made a fix on enwiki, in Module:Excerpt slideshow.

Code searches:

The underscores occur because the nsText property is obtained by just calling Title::getNsText, without further processing. It seems to be the only (to be confirmed) property with such underscores, for example the prefixedText property is already gsubbed to spaces.

This property is not much used, and checking its uses on wikis is quite manageable. Furthermore, at first glance, it seems that changing the property would actually fix things, without ever needing changes on wikis. These underscores were really not expected by module developers.

Change #1053882 had a related patch set uploaded (by Gerrit Patch Uploader; author: Francois Pignon):

[mediawiki/extensions/Scribunto@master] Spaces instead of underscores in nsText property of Title objects

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

Uploaded patch.

Thankfully, the use of spaces or underscores is well established (and docblock-documented) in the Title class, so it should be very future-proof.

(BTW, I noticed the getNsText() method isn't documented in the manual.)

No, the manual for the Title.php PHP class, not for the Title library in Scribunto.

edit - I have added it: https://www.mediawiki.org/w/index.php?title=Manual:Title.php&diff=prev&oldid=6635381

Here are 4 more modules on enwiki that are impacted by this issue:

I reviewed Module:Documentation module on frwiki:

As of now, the issue doesn't bring any bug to this module, but fixing the issue would bring more robustness, and slightly cleaner wikicode output.

I reviewed Module:Database report on enwiki: unaffected, fixing the issue would simply result in slightly cleaner wikicode output.

I've had found some modules on enwiki that needed fixing:

And for reference, some searches I have been using:

  • insource:nsText insource:/nsText *\.\. *['"]:/
  • insource:nsText insource:/nsText *[~=]+ *['"][A-Za-z]+_/

Another fixed module: https://en.wikipedia.org/w/index.php?title=Module:Automated_taxobox/sandbox&diff=prev&oldid=1244873944
(edit request for the module in production)

Again, the module developer expected that the property contains spaces.

On a related note, in TitleLibraryTests.lua there are tests for subjectNsText, and for talkNsText as well (T180911), but there are no tests for nsText.

The patch will have to be rebased after gerrit 1092899 is merged.