From: Niklas Laxström Date: Wed, 6 Mar 2019 12:23:06 +0000 (+0100) Subject: Improve documentation of the PageContentLanguage hook X-Git-Tag: 1.34.0-rc.0~2552^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%2C%22id_auteur=%24connecte%22%29%20.%20%22?a=commitdiff_plain;h=a08fc9eed6355976da7233dbf60b8f985ecd45ce;p=lhc%2Fweb%2Fwiklou.git Improve documentation of the PageContentLanguage hook Clarify that the type of second parameter that is being passed to the hooks can be anything because one hook can change it and then it is passed to another hook without the hook caller having possibility to check or modify the value. Clarify that hooks should only return Language objects. Rename $wgLang to $userLang in the hook parameter documentation to avoid false posivite matches for the global. Fix some typos, use Title::inNamespace and add a test assertion. Also, the $content parameter is unused by all implementations of this method, and on quick look never passed by any caller. I kept it for now, however. Bug: T214358 Change-Id: Iae49d2998c2b762565d232c0337d84d43a4a900c --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 8b5e4d7a70..645c0cdb15 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2441,10 +2441,12 @@ $flags: Flags passed to WikiPage::doEditContent() $revision: New Revision of the article 'PageContentLanguage': Allows changing the language in which the content of a -page is written. Defaults to the wiki content language ($wgContLang). +page is written. Defaults to the wiki content language. $title: Title object -&$pageLang: the page content language (either an object or a language code) -$wgLang: the user language +&$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) '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 49e3132275..decbb0c5d8 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -667,7 +667,7 @@ abstract class ContentHandler { * This default implementation just returns the content language (except for pages * in the MediaWiki namespace) * - * Note that the pages language is not cacheable, since it may in some + * Note that the page's language is not cacheable, since it may in some * cases depend on user settings. * * Also note that the page language may or may not depend on the actual content of the page, @@ -684,7 +684,7 @@ abstract class ContentHandler { global $wgLang; $pageLang = MediaWikiServices::getInstance()->getContentLanguage(); - if ( $title->getNamespace() == NS_MEDIAWIKI ) { + if ( $title->inNamespace( NS_MEDIAWIKI ) ) { // Parse mediawiki messages with correct target language list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() ); $pageLang = Language::factory( $lang ); diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index a8ea3f0af3..f42f8b49f9 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -158,6 +158,7 @@ class ContentHandlerTest extends MediaWikiTestCase { $handler = ContentHandler::getForTitle( $title ); $lang = $handler->getPageLanguage( $title ); + $this->assertInstanceOf( Language::class, $lang ); $this->assertEquals( $expected->getCode(), $lang->getCode() ); }