Page MenuHomePhabricator

Translate throws exception from hook called from Language::isKnownLanguageTag() if code is invalid
Closed, ResolvedPublic

Description

It should return false.

Note that the underlying error may be in Language::isKnownLanguageTag.

Here's a test page: https://test.wikipedia.org/wiki/Foo%27s_bar
And here's the module: https://test.wikipedia.org/wiki/Module:IsKnownLanguageTag

You can just test this with mw.language.isKnownLanguageTag("'") or something like that.

Obviously, it should return false -- it's not a known language code!


Version: unspecified
Severity: minor
URL: https://test.wikipedia.org/wiki/Foo%27s_bar

Details

Reference
bz49423

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 2:07 AM
bzimport set Reference to bz49423.

It appears to be due to the Translate extension, one of its hooks is throwing an exception. Reassigning accordingly.

Backtrace: (note the Translate extension hook call at #2)

2013-06-11 13:55:49 srv193 testwiki: [c959ea77] /wiki/Foo%27s_bar Exception from line 217 of /usr/local/apache/common-local/php-1.22wmf6/languages/Language.php: Invalid language code "Foo's bar"
#0 /usr/local/apache/common-local/php-1.22wmf6/languages/Language.php(196): Language::newFromCode('Foo's bar')
#1 /usr/local/apache/common-local/php-1.22wmf6/includes/Message.php(381): Language::factory('Foo's bar')
#2 /usr/local/apache/common-local/php-1.22wmf6/extensions/Translate/TranslateHooks.php(254): Message->inLanguage('Foo's bar')
#3 [internal function]: TranslateHooks::translateMessageDocumentationLanguage(Array, 'Foo's bar')
#4 /usr/local/apache/common-local/php-1.22wmf6/includes/Hooks.php(196): call_user_func_array('TranslateHooks:...', Array)
#5 /usr/local/apache/common-local/php-1.22wmf6/includes/GlobalFunctions.php(3834): Hooks::run('LanguageGetTran...', Array)
#6 /usr/local/apache/common-local/php-1.22wmf6/languages/Language.php(867): wfRunHooks('LanguageGetTran...', Array)
#7 /usr/local/apache/common-local/php-1.22wmf6/languages/Language.php(912): Language::fetchLanguageNames('Foo's bar', 'all')
#8 /usr/local/apache/common-local/php-1.22wmf6/languages/Language.php(393): Language::fetchLanguageName('Foo's bar', 'Foo's bar')
#9 /usr/local/apache/common-local/php-1.22wmf6/extensions/Scribunto/engines/LuaCommon/LanguageLibrary.php(66): Language::isKnownLanguageTag('Foo's bar')
#10 [internal function]: Scribunto_LuaLanguageLibrary->isKnownLanguageTag('Foo's bar')
#11 /usr/local/apache/common-local/php-1.22wmf6/extensions/Scribunto/engines/LuaSandbox/Engine.php(237): call_user_func_array(Array, Array)
#12 [internal function]: Scribunto_LuaSandboxCallback->__call('isKnownLanguage...', Array)
#13 [internal function]: Scribunto_LuaSandboxCallback->isKnownLanguageTag('Foo's bar')
#14 [internal function]: LuaSandboxFunction->call(Object(LuaSandboxFunction))
#15 /usr/local/apache/common-local/php-1.22wmf6/extensions/Scribunto/engines/LuaSandbox/Engine.php(158): call_user_func_array(Array, Array)
#16 /usr/local/apache/common-local/php-1.22wmf6/extensions/Scribunto/engines/LuaCommon/LuaCommon.php(186): Scribunto_LuaSandboxInterpreter->callFunction(Object(LuaSandboxFunction), Object(LuaSandboxFunction))
#17 /usr/local/apache/common-local/php-1.22wmf6/extensions/Scribunto/engines/LuaCommon/LuaCommon.php(643): Scribunto_LuaEngine->executeFunctionChunk(Object(LuaSandboxFunction), Object(PPTemplateFrame_DOM))
#18 /usr/local/apache/common-local/php-1.22wmf6/extensions/Scribunto/common/Hooks.php(108): Scribunto_LuaModule->invoke('isKnownLanguage...', Object(PPTemplateFrame_DOM))
#19 [internal function]: ScribuntoHooks::invokeHook(Object(Parser), Object(PPFrame_DOM), Array)
#20 /usr/local/apache/common-local/php-1.22wmf6/includes/parser/Parser.php(3560): call_user_func_array('ScribuntoHooks:...', Array)
#21 /usr/local/apache/common-local/php-1.22wmf6/includes/parser/Parser.php(3278): Parser->callParserFunction(Object(PPFrame_DOM), '#invoke', Array)
#22 /usr/local/apache/common-local/php-1.22wmf6/includes/parser/Preprocessor_DOM.php(1085): Parser->braceSubstitution(Array, Object(PPFrame_DOM))
#23 /usr/local/apache/common-local/php-1.22wmf6/includes/parser/Parser.php(3101): PPFrame_DOM->expand(Object(PPNode_DOM), 0)
#24 /usr/local/apache/common-local/php-1.22wmf6/includes/parser/Parser.php(1157): Parser->replaceVariables('{{#invoke:isKno...')
#25 /usr/local/apache/common-local/php-1.22wmf6/includes/parser/Parser.php(386): Parser->internalParse('{{#invoke:isKno...')
#26 /usr/local/apache/common-local/php-1.22wmf6/includes/content/WikitextContent.php(300): Parser->parse('{{#invoke:isKno...', Object(Title), Object(ParserOptions), true, true, 174375)
#27 /usr/local/apache/common-local/php-1.22wmf6/includes/WikiPage.php(3424): WikitextContent->getParserOutput(Object(Title), 174375, Object(ParserOptions))
#28 /usr/local/apache/common-local/php-1.22wmf6/includes/PoolCounter.php(222): PoolWorkArticleView->doWork()
#29 /usr/local/apache/common-local/php-1.22wmf6/includes/Article.php(708): PoolCounterWork->execute()
#30 /usr/local/apache/common-local/php-1.22wmf6/includes/actions/ViewAction.php(44): Article->view()
#31 /usr/local/apache/common-local/php-1.22wmf6/includes/Wiki.php(439): ViewAction->show()
#32 /usr/local/apache/common-local/php-1.22wmf6/includes/Wiki.php(305): MediaWiki->performAction(Object(Article), Object(Title))
#33 /usr/local/apache/common-local/php-1.22wmf6/includes/Wiki.php(565): MediaWiki->performRequest()
#34 /usr/local/apache/common-local/php-1.22wmf6/includes/Wiki.php(458): MediaWiki->main()
#35 /usr/local/apache/common-local/php-1.22wmf6/index.php(55): MediaWiki->run()
#36 /usr/local/apache/common-local/w/index.php(3): require('/usr/local/apac...')
#37 {main}

Garbage in, garbage out.

To me, the (minor) problem here seems rather to be that an error in using a module/function shouldn't make the page explode in the user's face. I had to delete the failing template in order to be able to *save* an edit removing it.

I can fix this, but the fix will be in core.

(In reply to comment #3)

Garbage in, garbage out.

Isn't the point of isKnownLanguageTag() for something to be able to determine whether the code is "garbage in"?

Related URL: https://gerrit.wikimedia.org/r/68004 (Gerrit Change I3fd98ba08393856311a48fa40769027460c72ef9)

(In reply to comment #6)

(In reply to comment #3)

Garbage in, garbage out.

Isn't the point of isKnownLanguageTag() for something to be able to determine
whether the code is "garbage in"?

That's exactly the point.

Yes, but the point was that it should not pass clearly invalid language codes to other parts of the system which expects valid language codes. See the patch.