Page MenuHomePhabricator

Fatal error: Uncaught TypeError: Argument 2 passed to TranslateHooks::onPageContentLanguage() must be an instance of Language, string given
Closed, ResolvedPublic

Description

Setup

  • MediaWiki 1.31.1 (632c3b6) 16:10, 16 January 2019
  • PHP 7.0.32-0ubuntu0.16.04.1 (apache2handler)
  • MySQL 5.7.24-0ubuntu0.16.04.1
  • Translate 2019.01 5f8b699

Issue
When upgrading to the latest version of Translate I get the following fatal:

Fatal error: Uncaught TypeError: Argument 2 passed to TranslateHooks::onPageContentLanguage() must be an instance of Language, string given, called in /../w/includes/Hooks.php on line 177 and defined in /../w/extensions/Translate/TranslateHooks.php:475

Stack Trace

#0 /../w/includes/Hooks.php(177): TranslateHooks::onPageContentLanguage(Object(Title), 'en', Object(LanguageEn))
#1 /../w/includes/Hooks.php(205): Hooks::callHook('PageContentLang...', Array, Array, NULL)
#2 /../w/includes/content/ContentHandler.php(671): Hooks::run('PageContentLang...', Array)
#3 /../w/includes/content/ContentHandler.php(697): ContentHandler->getPageLanguage(Object(Title), NULL)
#4 /../w/includes/Title.php(5032): ContentHandler->getPageViewLanguage(Object(Title))
#5 /../w/includes/skins/SkinTemplate.php(279): Title->getPageViewLanguage()
#6 /../w/includes/skins/SkinTemplate.php(464): SkinTemplate->wrap in /../w/extensions/Translate/TranslateHooks.php on line 475

Details

Related Gerrit Patches:
mediawiki/core : masterUnstub $wgLang for PageContentLanguage hook
mediawiki/core : masterImprove documentation of the PageContentLanguage hook
mediawiki/extensions/LiquidThreads : masterUpdate PageContentLanguage hook handler
mediawiki/extensions/WikiLexicalData : masterUpdate PageContentLanguage hook handler
mediawiki/extensions/CirrusSearch : masterUse Language objects in PageContentLanguage hook
mediawiki/extensions/Translate : masterExpanded param doctype further for PageContentLanguage hook
mediawiki/extensions/Translate : wmf/1.33.0-wmf.14Fix fatal error on PageContentLanguage hook subscriber
mediawiki/extensions/Translate : masterFix fatal error on PageContentLanguage hook subscriber

Event Timeline

Kghbln created this task.Jan 22 2019, 10:04 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJan 22 2019, 10:04 AM
Kghbln updated the task description. (Show Details)Jan 22 2019, 10:05 AM
Nikerabbit added subscribers: D3r1ck01, Fomafix, Arrbee and 3 others.

Introduced in f6e5fced (CC @D3r1ck01 ), but the incorrect documentation (and typehint) was introduced in d800005 (CC @Fomafix) but (only partially) reverted in 626f6373a547 (CC @Krinkle).

It is not clear to me why this issue has not occured in translatewiki.net or WMF production or in our testing.

We really need to stop going back and forth on this. I suggest the following:

  • Fix MediaWiki core to always pass objects. Two different types only causes troubles like this.
  • Fix the current code to say Language|string and remove the explicit type hints.

To be decided whether we need a bugfix MLEB release or whether the fix can wait for regular 2019.04 (CC @KartikMistry @Arrbee).

@Nikerabbit We can do quick bug fix release for MLEB if needed.

Nikerabbit triaged this task as Unbreak Now! priority.Jan 23 2019, 2:58 PM

This breaks posting on LiquidThreads on translatewiki.net.

Restricted Application added subscribers: Liuxinyu970226, TerraCodes. · View Herald TranscriptJan 23 2019, 2:58 PM

Change 486081 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/extensions/Translate@master] Fix fatal error on PageContentLanguage hook subscriber

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

Change 486081 merged by jenkins-bot:
[mediawiki/extensions/Translate@master] Fix fatal error on PageContentLanguage hook subscriber

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

I just fetched the fix and I am now on Translate (8269ba6) 15:59, 23 January 2019. Thus I can confirm that this issue no longer happens.

Nikerabbit lowered the priority of this task from Unbreak Now! to High.
Nikerabbit moved this task from Backlog to 2019.01 on the MediaWiki Language Extension Bundle board.

I also confirm translatewiki.net is okay now. Leaving open until we release the fix.

Change 486167 had a related patch set uploaded (by Jforrester; owner: Nikerabbit):
[mediawiki/extensions/Translate@wmf/1.33.0-wmf.14] Fix fatal error on PageContentLanguage hook subscriber

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

Change 486167 merged by jenkins-bot:
[mediawiki/extensions/Translate@wmf/1.33.0-wmf.14] Fix fatal error on PageContentLanguage hook subscriber

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

Mentioned in SAL (#wikimedia-operations) [2019-01-23T23:13:16Z] <jforrester@deploy1001> Synchronized php-1.33.0-wmf.14/extensions/Translate/TranslateHooks.php: T214517 T214358 Hot-deploy Ic9d85fec1 to un-block train, hopefully (duration: 00m 53s)

Change 486312 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/extensions/Translate@master] Expanded param doctype further for PageContentLanguage hook

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

Change 486312 merged by jenkins-bot:
[mediawiki/extensions/Translate@master] Expanded param doctype further for PageContentLanguage hook

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

I thought that I would fix this in core, but it seems the "bad" values are coming from other hook subscribers and hence are completely out of control. I'll improve some small things and documentation and see if I can identify some extensions producing these "bad" values.

Kghbln added a comment.Mar 6 2019, 2:52 PM

I thought that I would fix this in core, but it seems the "bad" values are coming from other hook subscribers and hence are completely out of control. I'll improve some small things and documentation and see if I can identify some extensions producing these "bad" values.

Ouch, this sounds bad. To help you a bit with the extensions. This is the wiki that gave me the error. So it must be one of them. The only other extension not part of MLEB concerned with language appears to be Semantic Interlanguage Links.

Krinkle removed a subscriber: Krinkle.Mar 6 2019, 3:07 PM

Change 494748 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/core@master] Improve documentation of PageContentLanguageHook

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

Doing an audit on: https://codesearch.wmflabs.org/search/?q=%5B%27%22%5DPageContentLanguage%5B%27%22%5D&i=nope&files=&repos=

  • MediaWiki core (hook runner) -> Language object (Language::factory or MediaWikiServices::getInstance()->getContentLanguage())
  • TranslateHooks::onPageContentLanguage -> Language object (wfGetLangObj or $wgContLang)
  • PageTranslationHooks::onPageContentLanguage -> Language object (Language::factory)
  • SemanticInterlanguageLinks -> string!
  • CirrusSearch\Jenkins\Jenkins::setLanguage -> string! (but only used for tests)
  • LqtDispatch::onPageContentLanguage -> Language or StubUserLang! ($wgLang passed as hook parameter)
  • PageLanguage::onPageContentLanguage -> Language (Language::factory)
  • WikiLexicalDataHooks::onPageContentLanguage -> Language or StubUserLang! (global $wgLang)
  • WikimediaIncubator::onPageContentLanguage -> Language or StubUserLang! (Language::factory or global $wgLang)
  • SemanticMediaWiki -> string!

@Kghbln Can I ask you to ask changes in SemanticInterlanguageLinks and SemanticMediaWiki?

I can attempt submitting patches for CirrusSearch , WikiLexicalData and WikimediaIncubator.

That still leaves the possibility of the $wgLang which is passed as hook parameter to be a StubUserLang. I should investigate whether it is okay to unstub it before passing it to the hooks.

Change 494901 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/extensions/CirrusSearch@master] Use Language objects in PageContentLanguage hook

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

Change 494902 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/extensions/LiquidThreads@master] Update PageContentLanguage hook handler

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

Change 494904 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/extensions/WikiLexicalData@master] Update PageContentLanguage hook handler

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

Change 494908 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/core@master] Unstub $wgLang for PageContentLanguage hook

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

Change 494901 merged by jenkins-bot:
[mediawiki/extensions/CirrusSearch@master] Use Language objects in PageContentLanguage hook

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

Kghbln added a comment.Mar 7 2019, 9:30 PM

Can I ask you to ask changes in SemanticInterlanguageLinks and SemanticMediaWiki?

I created the respective issues:

Change 494904 merged by jenkins-bot:
[mediawiki/extensions/WikiLexicalData@master] Update PageContentLanguage hook handler

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

Change 494902 merged by jenkins-bot:
[mediawiki/extensions/LiquidThreads@master] Update PageContentLanguage hook handler

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

Change 494748 merged by jenkins-bot:
[mediawiki/core@master] Improve documentation of the PageContentLanguage hook

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

If there is no progress on the last open patch by end of the sprint (next Tuesday I believe), I propose to abandon it and resolve this task.

Change 494908 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/core@master] Unstub $wgLang for PageContentLanguage hook

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

Change 494908 merged by jenkins-bot:
[mediawiki/core@master] Unstub $wgLang for PageContentLanguage hook

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

Note about QA: there isn't any good way to manually test this besides that the errors are gone when running in production. The original fix was confirmed in T214358#4902560 and the follow-ups mostly updated documentation and are low risk.

Arrbee closed this task as Resolved.May 20 2019, 8:16 AM