Require Skin name when passing options to Skin constructor

Bug: T262233
Depends-On: I4087deb8b0726c9959ac15d77a0ed2442e4890f6
Change-Id: I5772eb760e4fc56d2062a333ba4d7ca6995f3db2
This commit is contained in:
Ammar Abdulhamid 2020-09-16 11:02:31 +01:00 committed by Jdlrobson
parent fc73480e38
commit 4f32fc5e81
4 changed files with 26 additions and 14 deletions

View file

@ -1180,6 +1180,7 @@ return [
} else {
$displayName = $skin;
$spec = [
'name' => $name,
'class' => "Skin$skin"
];
}
@ -1191,6 +1192,7 @@ return [
'class' => SkinFallback::class,
'args' => [
[
'name' => 'fallback',
'styles' => [ 'mediawiki.skinning.interface' ],
'templateDirectory' => __DIR__ . '/skins/templates/fallback',
]
@ -1201,6 +1203,7 @@ return [
'class' => SkinApi::class,
'args' => [
[
'name' => 'apioutput',
'styles' => [ 'mediawiki.skinning.interface' ],
'templateDirectory' => __DIR__ . '/skins/templates/apioutput',
]

View file

@ -142,23 +142,24 @@ abstract class Skin extends ContextSource {
/**
* @since 1.31
* @param string|null|array $options Options for the skin can be an array since 1.35.
* When an array is passed `name` represents skinname,
* `scripts` represents an array of ResourceLoader script modules
* and `styles` represents
* an array of ResourceLoader style modules to load on all pages.
* @param string|array|null $options Options for the skin can be an array since 1.35.
* When a string is passed, it's the skinname.
* When an array is passed;
* `name` key represents the skinname, defaults to $wgDefaultSkin if not provided
* `scripts` represents an array of ResourceLoader script modules and
* `styles` represents an array of ResourceLoader style modules to load on all pages.
* `responsive` indicates if a viewport meta tag should be set.
*/
public function __construct( $options = null ) {
if ( is_string( $options ) ) {
$this->skinname = $options;
} elseif ( $options ) {
$this->options = $options;
$name = $options['name'] ?? null;
// Note: skins might override the public $skinname method instead
if ( $name ) {
$this->skinname = $name;
if ( !$name ) {
throw new SkinException( 'Skin name must be specified' );
}
$this->options = $options;
$this->skinname = $name;
}
}

View file

@ -14,6 +14,7 @@ class SkinTemplateTest extends MediaWikiIntegrationTestCase {
public function testMakeListItem( $expected, $key, array $item, array $options, $message ) {
$template = $this->getMockForAbstractClass( BaseTemplate::class );
$template->set( 'skin', new SkinFallback( [
'name' => 'fallback',
'templateDirectory' => __DIR__,
] ) );

View file

@ -35,11 +35,18 @@ class SkinTest extends MediaWikiIntegrationTestCase {
$this->assertSame( $expected, $skin->isResponsive() );
}
public function provideSkinResponsiveOptions() : array {
return [
'responsive not set' => [ [], false ],
'responsive false' => [ [ 'responsive' => false ], false ],
'responsive true' => [ [ 'responsive' => true ], true ]
public function provideSkinResponsiveOptions() {
yield 'responsive not set' => [
[ 'name' => 'test' ],
false
];
yield 'responsive false' => [
[ 'name' => 'test', 'responsive' => false ],
false
];
yield 'responsive true' => [
[ 'name' => 'test', 'responsive' => true ],
true
];
}
}