* of a specific loader request.
*/
class ResourceLoaderContext implements MessageLocalizer {
+ const DEFAULT_LANG = 'qqx';
+ const DEFAULT_SKIN = 'fallback';
+
protected $resourceLoader;
protected $request;
protected $logger;
// List of modules
$modules = $request->getRawVal( 'modules' );
- $this->modules = $modules ? self::expandModuleNames( $modules ) : [];
+ $this->modules = $modules ? ResourceLoader::expandModuleNames( $modules ) : [];
// Various parameters
$this->user = $request->getRawVal( 'user' );
$this->skin = $request->getRawVal( 'skin' );
$skinnames = Skin::getSkinNames();
- // If no skin is specified, or we don't recognize the skin, use the default skin
if ( !$this->skin || !isset( $skinnames[$this->skin] ) ) {
- $this->skin = $this->getConfig()->get( 'DefaultSkin' );
+ // The 'skin' parameter is required. (Not yet enforced.)
+ // For requests without a known skin specified,
+ // use MediaWiki's 'fallback' skin for skin-specific decisions.
+ $this->skin = self::DEFAULT_SKIN;
}
}
/**
- * Expand a string of the form `jquery.foo,bar|jquery.ui.baz,quux` to
- * an array of module names like `[ 'jquery.foo', 'jquery.bar',
- * 'jquery.ui.baz', 'jquery.ui.quux' ]`.
- *
- * This process is reversed by ResourceLoader::makePackedModulesString().
+ * Reverse the process done by ResourceLoader::makePackedModulesString().
*
+ * @deprecated since 1.33 Use ResourceLoader::expandModuleNames instead.
* @param string $modules Packed module name list
* @return array Array of module names
+ * @codeCoverageIgnore
*/
public static function expandModuleNames( $modules ) {
- $retval = [];
- $exploded = explode( '|', $modules );
- foreach ( $exploded as $group ) {
- if ( strpos( $group, ',' ) === false ) {
- // This is not a set of modules in foo.bar,baz notation
- // but a single module
- $retval[] = $group;
- } else {
- // This is a set of modules in foo.bar,baz notation
- $pos = strrpos( $group, '.' );
- if ( $pos === false ) {
- // Prefixless modules, i.e. without dots
- $retval = array_merge( $retval, explode( ',', $group ) );
- } else {
- // We have a prefix and a bunch of suffixes
- $prefix = substr( $group, 0, $pos ); // 'foo'
- $suffixes = explode( ',', substr( $group, $pos + 1 ) ); // [ 'bar', 'baz' ]
- foreach ( $suffixes as $suffix ) {
- $retval[] = "$prefix.$suffix";
- }
- }
- }
- }
- return $retval;
+ wfDeprecated( __METHOD__, '1.33' );
+ return ResourceLoader::expandModuleNames( $modules );
}
/**
}
/**
+ * @deprecated since 1.34 Use ResourceLoaderModule::getConfig instead
+ * inside module methods. Use ResourceLoader::getConfig elsewhere.
* @return Config
*/
public function getConfig() {
}
/**
+ * @deprecated since 1.34 Use ResourceLoaderModule::getLogger instead
+ * inside module methods. Use ResourceLoader::getLogger elsewhere.
* @since 1.27
* @return \Psr\Log\LoggerInterface
*/
$lang = $this->getRequest()->getRawVal( 'lang', '' );
// Stricter version of RequestContext::sanitizeLangCode()
if ( !Language::isValidBuiltInCode( $lang ) ) {
- $lang = $this->getConfig()->get( 'LanguageCode' );
+ // The 'lang' parameter is required. (Not yet enforced.)
+ // If omitted, localise with the dummy language code.
+ $lang = self::DEFAULT_LANG;
}
$this->language = $lang;
}
*/
public function getDirection() {
if ( $this->direction === null ) {
- $this->direction = $this->getRequest()->getRawVal( 'dir' );
- if ( !$this->direction ) {
+ $direction = $this->getRequest()->getRawVal( 'dir' );
+ if ( $direction === 'ltr' || $direction === 'rtl' ) {
+ $this->direction = $direction;
+ } else {
// Determine directionality based on user language (T8100)
$this->direction = Language::factory( $this->getLanguage() )->getDir();
}