Page MenuHomePhabricator

Attempting to edit MediaWiki.org page produces PHP fatal error: Call to undefined method LanguageCode::getCode()
Closed, ResolvedPublic

Description

Attempting to edit or preview Extension:DPLforum/code on MediaWiki.org, replacing the current content with {{#translation:}}, produces a PHP fatal error: Call to undefined method LanguageCode::getCode().

Details

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 30 2018, 4:18 AM
Dinoguy1000 updated the task description. (Show Details)Jun 30 2018, 4:29 AM
Dinoguy1000 updated the task description. (Show Details)
Dinoguy1000 updated the task description. (Show Details)Jun 30 2018, 4:32 AM
Ciencia_Al_Poder added a subscriber: Ciencia_Al_Poder.

The problem can be easily reproduced by simply placing {{#translation:}} on the page.

Looks like {{#translation:}} is taking the subpage name as a language, but it's not checking if it's a valid language code.

Dinoguy1000 updated the task description. (Show Details)Jun 30 2018, 5:55 PM
Nikerabbit added a subscriber: Nikerabbit.
#0 /srv/mediawiki/php-1.32.0-wmf.10/includes/cache/MessageCache.php(892): NO_FUNCTION_GIVEN()
#1 /srv/mediawiki/php-1.32.0-wmf.10/includes/cache/MessageCache.php(869): MessageCache->getMessageForLang(LanguageCode, string, boolean, array)
#2 /srv/mediawiki/php-1.32.0-wmf.10/includes/cache/MessageCache.php(810): MessageCache->getMessageFromFallbackChain(LanguageCode, string, boolean)
#3 /srv/mediawiki/php-1.32.0-wmf.10/includes/Message.php(1296): MessageCache->get(string, boolean, LanguageCode)
#4 /srv/mediawiki/php-1.32.0-wmf.10/includes/Message.php(848): Message->fetchMessage()
#5 /srv/mediawiki/php-1.32.0-wmf.10/includes/Message.php(952): Message->toString(string)
#6 /srv/mediawiki/php-1.32.0-wmf.10/extensions/Translate/TranslateHooks.php(472): Message->plain()
#7 /srv/mediawiki/php-1.32.0-wmf.10/includes/Hooks.php(174): TranslateHooks::translateMessageDocumentationLanguage(array, string)
#8 /srv/mediawiki/php-1.32.0-wmf.10/includes/Hooks.php(202): Hooks::callHook(string, array, array, NULL)
#9 /srv/mediawiki/php-1.32.0-wmf.10/languages/Language.php(838): Hooks::run(string, array)
#10 /srv/mediawiki/php-1.32.0-wmf.10/languages/Language.php(810): Language::fetchLanguageNamesUncached(string, string)
#11 /srv/mediawiki/php-1.32.0-wmf.10/languages/Language.php(896): Language::fetchLanguageNames(string, string)
#12 /srv/mediawiki/php-1.32.0-wmf.10/languages/Language.php(391): Language::fetchLanguageName(string, string)
#13 /srv/mediawiki/php-1.32.0-wmf.10/extensions/Translate/TranslateHooks.php(805): Language::isKnownLanguageTag(string)
#14 /srv/mediawiki/php-1.32.0-wmf.10/includes/parser/Parser.php(3434): TranslateHooks::translateRenderParserFunction(Parser, string)
#15 /srv/mediawiki/php-1.32.0-wmf.10/includes/parser/Parser.php(3138): Parser->callParserFunction(PPFrame_Hash, string, array)
#16 /srv/mediawiki/php-1.32.0-wmf.10/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPFrame_Hash)
#17 /srv/mediawiki/php-1.32.0-wmf.10/includes/parser/Parser.php(2953): PPFrame_Hash->expand(PPNode_Hash_Tree, integer)
#18 /srv/mediawiki/php-1.32.0-wmf.10/includes/parser/Parser.php(1297): Parser->replaceVariables(string)
#19 /srv/mediawiki/php-1.32.0-wmf.10/includes/parser/Parser.php(446): Parser->internalParse(string)
#20 /srv/mediawiki/php-1.32.0-wmf.10/includes/content/WikitextContent.php(323): Parser->parse(string, Title, ParserOptions, boolean, boolean, NULL)
#21 /srv/mediawiki/php-1.32.0-wmf.10/includes/content/AbstractContent.php(516): WikitextContent->fillParserOutput(Title, NULL, ParserOptions, boolean, ParserOutput)
#22 /srv/mediawiki/php-1.32.0-wmf.10/includes/EditPage.php(4000): AbstractContent->getParserOutput(Title, NULL, ParserOptions)
#23 /srv/mediawiki/php-1.32.0-wmf.10/includes/EditPage.php(3925): EditPage->doPreviewParse(WikitextContent)
#24 /srv/mediawiki/php-1.32.0-wmf.10/includes/EditPage.php(2708): EditPage->getPreviewText()
#25 /srv/mediawiki/php-1.32.0-wmf.10/includes/EditPage.php(684): EditPage->showEditForm()
#26 /srv/mediawiki/php-1.32.0-wmf.10/includes/actions/EditAction.php(60): EditPage->edit()
#27 /srv/mediawiki/php-1.32.0-wmf.10/includes/actions/SubmitAction.php(38): EditAction->show()
#28 /srv/mediawiki/php-1.32.0-wmf.10/includes/MediaWiki.php(500): SubmitAction->show()
#29 /srv/mediawiki/php-1.32.0-wmf.10/includes/MediaWiki.php(294): MediaWiki->performAction(Article, Title)
#30 /srv/mediawiki/php-1.32.0-wmf.10/includes/MediaWiki.php(867): MediaWiki->performRequest()
#31 /srv/mediawiki/php-1.32.0-wmf.10/includes/MediaWiki.php(524): MediaWiki->main()
#32 /srv/mediawiki/php-1.32.0-wmf.10/index.php(42): MediaWiki->run()
#33 /srv/mediawiki/w/index.php(3): include(string)
#34 {main}

That code in Translate last changed in 2015. At 6 we are still having a string, which unexpectedly turns into instance of LanguageCode by 3. Message::getLanguage is defined as return $this->language ?: RequestContext::getMain()->getLanguage();

I cannot find any constructors for LanguageCode in core, and Translate doesn't use that class at all.

Have to audit commits since last deployed branch.

Nikerabbit added subscribers: TTO, Legoktm.EditedJun 30 2018, 7:06 PM

This is a simple case of Language::newFromCode( 'code' ); which incorrectly assumes that LanguageCode is instance of Language. The most surprising part is that this has not been noticed before. It is probably too late rename the LanguageCode class so we should add an exception to Language::newFromCode. Class was introduced in 48ab87d0a37da80c2e2ae3a20f645548d2a787f9 (since REL1_29).

TTO added a comment.Jun 30 2018, 10:48 PM

Oh I see what you mean.,.. the class for en would be LanguageEn, and the class for he would be LanguageHe, so when you ask for a language with code code, it sees that a class LanguageCode exists and tries to construct that.

Sorry for naming the class that!

Change 443384 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/core@master] Prevent fatal error when {{#translation:}} is placed on subpage named code

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

Change 443384 merged by jenkins-bot:
[mediawiki/core@master] Prevent fatal error when {{#translation:}} is placed on subpage named code

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

Nikerabbit closed this task as Resolved.Jul 3 2018, 6:50 AM
Nikerabbit claimed this task.
Nikerabbit triaged this task as Normal priority.
Nikerabbit removed a project: Patch-For-Review.
mmodell changed the subtype of this task from "Task" to "Production Error".Aug 28 2019, 11:09 PM
Restricted Application added a subscriber: Liuxinyu970226. · View Herald TranscriptAug 28 2019, 11:09 PM