From: Timo Tijhof Date: Thu, 10 Mar 2016 23:33:58 +0000 (+0000) Subject: resourceloader: Create ResourceLoaderContext::msg() method X-Git-Tag: 1.31.0-rc.0~7652^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=a2100e39c1f18d3dd48460eed85246263a3f3db6;p=lhc%2Fweb%2Fwiklou.git resourceloader: Create ResourceLoaderContext::msg() method This makes it easier to fetch messages without having to manually call inLanguage() on each wfMessage() call, which is currently causing some code forget this and use plain wfMessage() which defaults to MediaWiki user language from session. I've considered setting $wgLang or RequestContext::getMain(), but that's still bad since modules get passed a context in their methods and shouldn't be using global context either. The warnings provided by MW_NO_SESSION are exactly what we want. Change-Id: I1288fa5622d9f82d21bb66c8eb6518b90e7cddb4 --- diff --git a/includes/resourceloader/ResourceLoaderContext.php b/includes/resourceloader/ResourceLoaderContext.php index 6458e71e7e..8e0239a530 100644 --- a/includes/resourceloader/ResourceLoaderContext.php +++ b/includes/resourceloader/ResourceLoaderContext.php @@ -211,6 +211,18 @@ class ResourceLoaderContext { return $this->user; } + /** + * Get a Message object with context set. See wfMessage for parameters. + * + * @since 1.27 + * @param mixed ... + * @return Message + */ + public function msg() { + return call_user_func_array( 'wfMessage', func_get_args() ) + ->inLanguage( $this->getLanguage() ); + } + /** * Get the possibly-cached User object for the specified username * diff --git a/load.php b/load.php index d30a34836c..2b97f7aa2a 100644 --- a/load.php +++ b/load.php @@ -36,12 +36,15 @@ if ( !$wgRequest->checkUrlExtension() ) { return; } -// Respond to ResourceLoader request +// Set up ResourceLoader $resourceLoader = new ResourceLoader( ConfigFactory::getDefaultInstance()->makeConfig( 'main' ), LoggerFactory::getInstance( 'resourceloader' ) ); -$resourceLoader->respond( new ResourceLoaderContext( $resourceLoader, $wgRequest ) ); +$context = new ResourceLoaderContext( $resourceLoader, $wgRequest ); + +// Respond to ResourceLoader request +$resourceLoader->respond( $context ); Profiler::instance()->setTemplated( true );