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
This commit is contained in:
parent
41e63e71e8
commit
a2100e39c1
2 changed files with 17 additions and 2 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
7
load.php
7
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 );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue