From 855b1794b6b7761260702a394414876eefc6cc0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Thu, 7 Mar 2019 12:34:26 +0100 Subject: [PATCH] Unstub $wgLang for PageContentLanguage hook This is to avoid annoying fatal errors when someone annotated their hook handler to only expect Language objects, but that expectation is violated due to this code possibly passing StubUserLang to hooks, some of which may also assign it to $pageLang. Even with this in place, it is probably a good idea for hook handlers to refrain from type hinting parameters that are passed by reference because their types cannot be guaranteed. Bug: T214358 Change-Id: I88405a8de4b13675eb5a9d11e9ddc87e20a85fb4 --- docs/hooks.txt | 2 +- includes/content/ContentHandler.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index e90468dfee..1419d0a9d9 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2448,7 +2448,7 @@ $title: Title object &$pageLang: the page content language. Input can be anything (under control of hook subscribers), but hooks should return Language objects. Language code strings are deprecated. -$userLang: the user language (Language or StubUserLang object) +$userLang: the user language (Language object) 'PageContentSave': Before an article is saved. $wikiPage: the WikiPage (object) being saved diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index cc73dd2064..b62737d5bb 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -691,6 +691,10 @@ abstract class ContentHandler { $pageLang = Language::factory( $lang ); } + // Simplify hook handlers by only passing objects of one type, in case nothing + // else has unstubbed the StubUserLang object by now. + StubObject::unstub( $wgLang ); + Hooks::run( 'PageContentLanguage', [ $title, &$pageLang, $wgLang ] ); return wfGetLangObj( $pageLang ); -- 2.20.1