resourceloader: Remove needless MW-specific fallback

This is never used by the mw.loader client code. For any
manually crafted requests or fringe usage where the load.php
might be used to fetch some raw JS code that doesn't vary by
language or skin, proceed with qqx/fallback.

In the future load.php might deny these requests and then we
could make this a constructor parameter to ResourceLoaderContext.

Bug: T32956
Change-Id: I4e4ee758cd22278cea9592d4745b4f7fc00e0add
This commit is contained in:
Timo Tijhof 2019-04-11 23:17:00 +01:00 committed by Krinkle
parent 19fe64a134
commit fa05976f5f
3 changed files with 10 additions and 8 deletions

View file

@ -84,9 +84,11 @@ class ResourceLoaderContext implements MessageLocalizer {
$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 = 'fallback';
}
}
@ -170,7 +172,9 @@ class ResourceLoaderContext implements MessageLocalizer {
$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 = 'qqx';
}
$this->language = $lang;
}

View file

@ -82,7 +82,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule {
* getPages.
*/
public function __construct( array $options = null ) {
if ( is_null( $options ) ) {
if ( $options === null ) {
return;
}

View file

@ -14,8 +14,6 @@ class ResourceLoaderContextTest extends PHPUnit\Framework\TestCase {
protected static function getResourceLoader() {
return new EmptyResourceLoader( new HashConfig( [
'ResourceLoaderDebug' => false,
'DefaultSkin' => 'fallback',
'LanguageCode' => 'nl',
'LoadScript' => '/w/load.php',
] ) );
}
@ -25,7 +23,7 @@ class ResourceLoaderContextTest extends PHPUnit\Framework\TestCase {
// Request parameters
$this->assertEquals( [], $ctx->getModules() );
$this->assertEquals( 'nl', $ctx->getLanguage() );
$this->assertEquals( 'qqx', $ctx->getLanguage() );
$this->assertEquals( false, $ctx->getDebug() );
$this->assertEquals( null, $ctx->getOnly() );
$this->assertEquals( 'fallback', $ctx->getSkin() );
@ -34,7 +32,7 @@ class ResourceLoaderContextTest extends PHPUnit\Framework\TestCase {
// Misc
$this->assertEquals( 'ltr', $ctx->getDirection() );
$this->assertEquals( 'nl|fallback||||||||', $ctx->getHash() );
$this->assertEquals( 'qqx|fallback||||||||', $ctx->getHash() );
$this->assertInstanceOf( User::class, $ctx->getUserObj() );
}