wgUserLanguage in JS should be valid for API (Exception: Invalid language code "nl_nl")
Closed, ResolvedPublic

Description

2015-10-27 20:42:45 mw1222 enwiki exception ERROR: [27ba8a41] /w/api.php?notalertunreadfirst=&action=query&notformat=html&notmessagecontinue=&format=json&notprop=list&uselang=nl_nl&meta=notifications&notlimit=15   MWException from line 4420 of /srv/mediawiki/php-1.27.0-wmf.3/languages/Language.php: Invalid language code "nl_nl" {"exception_id":"27ba8a41"} 
[Exception MWException] (/srv/mediawiki/php-1.27.0-wmf.3/languages/Language.php:4420) Invalid language code "nl_nl"
  #0 /srv/mediawiki/php-1.27.0-wmf.3/extensions/cldr/CldrNames.php(28): Language::getFileName(string, string, string)
  #1 /srv/mediawiki/php-1.27.0-wmf.3/extensions/cldr/TimeUnits.body.php(66): CldrNames::getOverrideFileName(string)
  #2 /srv/mediawiki/php-1.27.0-wmf.3/extensions/cldr/TimeUnits.body.php(26): TimeUnits::loadLanguage(string)
  #3 /srv/mediawiki/php-1.27.0-wmf.3/extensions/cldr/TimeUnits.body.php(156): TimeUnits::getUnits(string)
  #4 /srv/mediawiki/php-1.27.0-wmf.3/includes/Hooks.php(204): TimeUnits::onGetHumanTimestamp(string, MWTimestamp, MWTimestamp, User, Language)
  #5 /srv/mediawiki/php-1.27.0-wmf.3/languages/Language.php(2573): Hooks::run(string, array)
  #6 /srv/mediawiki/php-1.27.0-wmf.3/includes/MWTimestamp.php(219): Language->getHumanTimestamp(MWTimestamp, MWTimestamp, User)
  #7 /srv/mediawiki/php-1.27.0-wmf.3/extensions/Echo/includes/formatters/NotificationFormatter.php(124): MWTimestamp->getHumanTimestamp()
  #8 /srv/mediawiki/php-1.27.0-wmf.3/extensions/Echo/includes/formatters/BasicFormatter.php(443): EchoNotificationFormatter->formatTimestamp(string)
  #9 /srv/mediawiki/php-1.27.0-wmf.3/extensions/Echo/includes/formatters/BasicFormatter.php(212): EchoBasicFormatter->formatFooter(EchoEvent, User)
  #10 /srv/mediawiki/php-1.27.0-wmf.3/extensions/Echo/includes/controller/NotificationController.php(379): EchoBasicFormatter->format(EchoEvent, User, string)
  #11 /srv/mediawiki/php-1.27.0-wmf.3/extensions/Echo/includes/DataOutputFormatter.php(109): EchoNotificationController::formatNotification(EchoEvent, User, string)
  #12 /srv/mediawiki/php-1.27.0-wmf.3/extensions/Echo/includes/api/ApiEchoNotifications.php(149): EchoDataOutputFormatter::formatOutput(EchoNotification, string, User)
  #13 /srv/mediawiki/php-1.27.0-wmf.3/extensions/Echo/includes/api/ApiEchoNotifications.php(46): ApiEchoNotifications->getPropList(User, array, integer, NULL, string)
  #14 /srv/mediawiki/php-1.27.0-wmf.3/includes/api/ApiQuery.php(287): ApiEchoNotifications->execute()
  #15 /srv/mediawiki/php-1.27.0-wmf.3/includes/api/ApiMain.php(1270): ApiQuery->execute()
  #16 /srv/mediawiki/php-1.27.0-wmf.3/includes/api/ApiMain.php(466): ApiMain->executeAction()
  #17 /srv/mediawiki/php-1.27.0-wmf.3/includes/api/ApiMain.php(438): ApiMain->executeActionWithErrorHandling()
  #18 /srv/mediawiki/php-1.27.0-wmf.3/api.php(88): ApiMain->execute()
  #19 /srv/mediawiki/w/api.php(3): include(string)
  #20 {main}

Not sure what's going on here, but we shouldn't throw exceptions for bad user input...

Legoktm created this task.Oct 28 2015, 6:39 AM
Legoktm updated the task description. (Show Details)
Legoktm raised the priority of this task from to Needs Triage.
Legoktm added a subscriber: Legoktm.
Restricted Application added a project: Collaboration-Team-Triage. · View Herald TranscriptOct 28 2015, 6:39 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
  1. User passes ?uselang=nl_nl to a normal pageview, it's not a known language code so core uses the content language
  2. $wgLang->getCode() will still return nl_nl because "This is to support uselang= hacks" (or so says Language::newFromCode())
  3. nl_nl is passed onto the RL startup module, which also does loose validation and exports it as 'wgUserLanguage' (related: {T102058})
  4. Echo passes on the language to its API requests so notifications appear in the page's language.
  5. cldr calls into Language stuff which throws an Exception because 'nl_nl' isn't a real language code!

Apparently the loose validation of language codes is a feature? So the only fix I see is to catch exceptions in cldr. CC'ing a few knowledgeable people to make sure my analysis is correct.

Do things like ?uselang=isownwork fail similarly? Commons uses those kinds of "language codes" for some of their hacks.

Do things like ?uselang=isownwork fail similarly? Commons uses those kinds of "language codes" for some of their hacks.

For whatever reason, it appears to work...

Part of this would be addressed by 3b829b4385eda5b986 / https://gerrit.wikimedia.org/r/249662.

In fact, that fixes this bug entirely because mw.config.get( 'wgUserLanguage' ) will always return a valid language code.

Restricted Application added a subscriber: StudiesWorld. · View Herald TranscriptNov 3 2015, 5:03 PM
Krinkle triaged this task as Normal priority.Nov 3 2015, 7:25 PM
Krinkle renamed this task from Invalid language code "nl_nl" to wgUserLanguage in JS should be valid for API (Exception: Invalid language code "nl_nl").
Krinkle closed this task as Resolved.
demon moved this task from Backlog to Done on the Wikimedia-log-errors board.Nov 3 2015, 10:45 PM

Checked in beta - using uselang in url for invalid lang options - e.g. http://en.wikipedia.beta.wmflabs.org/wiki/Talk:ET13?uselang=nl_nl

  • produces errors in Console:

[FLOW] Failed to getInstanceByElement: no $container.length
[FLOW] Error in component handler: makeContentInteractive TypeError: component.emitWithReturn is not a function

  • an empty Flow board is displayed ( the Board description is displayed correctly - nothing else),
  • a strange sequence of 1111... numbers is displayed

Checked in beta - using uselang in url for invalid lang options - e.g. http://en.wikipedia.beta.wmflabs.org/wiki/Talk:ET13?uselang=nl_nl

  • produces errors in Console: [FLOW] Failed to getInstanceByElement: no $container.length [FLOW] Error in component handler: makeContentInteractive TypeError: component.emitWithReturn is not a function
  • an empty Flow board is displayed ( the Board description is displayed correctly - nothing else),
  • a strange sequence of 1111... numbers is displayed

That looks like a related but different bug in Flow. Very strange...