* @return array
*/
public function getStyles( ResourceLoaderContext $context ) {
- $logo = $this->getLogo( $this->getConfig() );
+ $logo = $this->getLogoData( $this->getConfig() );
$styles = parent::getStyles( $context );
$this->normalizeStyles( $styles );
'; }';
if ( is_array( $logo ) ) {
- if ( isset( $logo['1.5x'] ) ) {
- $styles[
- '(-webkit-min-device-pixel-ratio: 1.5), ' .
- '(min--moz-device-pixel-ratio: 1.5), ' .
+ if ( isset( $logo['svg'] ) ) {
+ $styles['all'][] = '.mw-wiki-logo { ' .
+ 'background-image: -webkit-linear-gradient(transparent, transparent), ' .
+ CSSMin::buildUrlValue( $logo['svg'] ) . '; ' .
+ 'background-image: linear-gradient(transparent, transparent), ' .
+ CSSMin::buildUrlValue( $logo['svg'] ) . ';' .
+ 'background-size: 135px auto; }';
+ } else {
+ if ( isset( $logo['1.5x'] ) ) {
+ $styles[
+ '(-webkit-min-device-pixel-ratio: 1.5), ' .
+ '(min--moz-device-pixel-ratio: 1.5), ' .
'(min-resolution: 1.5dppx), ' .
- '(min-resolution: 144dpi)'
- ][] = '.mw-wiki-logo { background-image: ' .
- CSSMin::buildUrlValue( $logo['1.5x'] ) . ';' .
- 'background-size: 135px auto; }';
- }
- if ( isset( $logo['2x'] ) ) {
- $styles[
- '(-webkit-min-device-pixel-ratio: 2), ' .
- '(min--moz-device-pixel-ratio: 2),' .
- '(min-resolution: 2dppx), ' .
- '(min-resolution: 192dpi)'
- ][] = '.mw-wiki-logo { background-image: ' .
- CSSMin::buildUrlValue( $logo['2x'] ) . ';' .
- 'background-size: 135px auto; }';
+ '(min-resolution: 144dpi)'
+ ][] = '.mw-wiki-logo { background-image: ' .
+ CSSMin::buildUrlValue( $logo['1.5x'] ) . ';' .
+ 'background-size: 135px auto; }';
+ }
+ if ( isset( $logo['2x'] ) ) {
+ $styles[
+ '(-webkit-min-device-pixel-ratio: 2), ' .
+ '(min--moz-device-pixel-ratio: 2), ' .
+ '(min-resolution: 2dppx), ' .
+ '(min-resolution: 192dpi)'
+ ][] = '.mw-wiki-logo { background-image: ' .
+ CSSMin::buildUrlValue( $logo['2x'] ) . ';' .
+ 'background-size: 135px auto; }';
+ }
}
}
}
}
+ /**
+ * @since 1.31
+ * @param Config $conf
+ * @return string|array
+ */
+ protected function getLogoData( Config $conf ) {
+ return static::getLogo( $conf );
+ }
+
/**
* @param Config $conf
- * @return string|array Single url if no variants are defined
- * or array of logo urls keyed by dppx in form "<float>x".
- * Key "1x" is always defined.
+ * @return string|array Single url if no variants are defined,
+ * or an array of logo urls keyed by dppx in form "<float>x".
+ * Key "1x" is always defined. Key "svg" may also be defined,
+ * in which case variants other than "1x" are omitted.
*/
public static function getLogo( Config $conf ) {
$logo = $conf->get( 'Logo' );
'1x' => $logo1Url,
];
- // Only 1.5x and 2x are supported
- if ( isset( $logoHD['1.5x'] ) ) {
- $logoUrls['1.5x'] = OutputPage::transformResourcePath(
+ if ( isset( $logoHD['svg'] ) ) {
+ $logoUrls['svg'] = OutputPage::transformResourcePath(
$conf,
- $logoHD['1.5x']
- );
- }
- if ( isset( $logoHD['2x'] ) ) {
- $logoUrls['2x'] = OutputPage::transformResourcePath(
- $conf,
- $logoHD['2x']
+ $logoHD['svg']
);
+ } else {
+ // Only 1.5x and 2x are supported
+ if ( isset( $logoHD['1.5x'] ) ) {
+ $logoUrls['1.5x'] = OutputPage::transformResourcePath(
+ $conf,
+ $logoHD['1.5x']
+ );
+ }
+ if ( isset( $logoHD['2x'] ) ) {
+ $logoUrls['2x'] = OutputPage::transformResourcePath(
+ $conf,
+ $logoHD['2x']
+ );
+ }
}
return $logoUrls;
<?php
/**
- * @group Database
* @group ResourceLoader
*/
class ResourceLoaderSkinModuleTest extends PHPUnit_Framework_TestCase {
+ // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
public static function provideGetStyles() {
return [
[
'parent' => [],
+ 'logo' => '/logo.png',
'expected' => [
'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
],
'parent' => [
'screen' => '.example {}',
],
+ 'logo' => '/logo.png',
'expected' => [
'screen' => [ '.example {}' ],
'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
],
],
+ [
+ 'parent' => [],
+ 'logo' => [
+ '1x' => '/logo.png',
+ '1.5x' => '/logo@1.5x.png',
+ '2x' => '/logo@2x.png',
+ ],
+ 'expected' => [
+ 'all' => [ <<<CSS
+.mw-wiki-logo { background-image: url(/logo.png); }
+CSS
+ ],
+ '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx), (min-resolution: 144dpi)' => [ <<<CSS
+.mw-wiki-logo { background-image: url(/logo@1.5x.png);background-size: 135px auto; }
+CSS
+ ],
+ '(-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi)' => [ <<<CSS
+.mw-wiki-logo { background-image: url(/logo@2x.png);background-size: 135px auto; }
+CSS
+ ],
+ ],
+ ],
+ [
+ 'parent' => [],
+ 'logo' => [
+ '1x' => '/logo.png',
+ 'svg' => '/logo.svg',
+ ],
+ 'expected' => [
+ 'all' => [ <<<CSS
+.mw-wiki-logo { background-image: url(/logo.png); }
+CSS
+ , <<<CSS
+.mw-wiki-logo { background-image: -webkit-linear-gradient(transparent, transparent), url(/logo.svg); background-image: linear-gradient(transparent, transparent), url(/logo.svg);background-size: 135px auto; }
+CSS
+ ],
+ ],
+ ],
];
}
+ // @codingStandardsIgnoreEnd
/**
* @dataProvider provideGetStyles
* @covers ResourceLoaderSkinModule::normalizeStyles
* @covers ResourceLoaderSkinModule::getStyles
*/
- public function testGetStyles( $parent, $expected ) {
+ public function testGetStyles( $parent, $logo, $expected ) {
$module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
->disableOriginalConstructor()
- ->setMethods( [ 'readStyleFiles' ] )
+ ->setMethods( [ 'readStyleFiles', 'getConfig', 'getLogoData' ] )
->getMock();
$module->expects( $this->once() )->method( 'readStyleFiles' )
->willReturn( $parent );
- $module->setConfig( new HashConfig( [
- 'ResourceBasePath' => '/w',
- 'Logo' => '/logo.png',
- 'LogoHD' => false,
- ] ) );
+ $module->expects( $this->once() )->method( 'getConfig' )
+ ->willReturn( new HashConfig() );
+ $module->expects( $this->once() )->method( 'getLogoData' )
+ ->willReturn( $logo );
$ctx = $this->getMockBuilder( ResourceLoaderContext::class )
->disableOriginalConstructor()->getMock();
$this->assertEquals(
- $module->getStyles( $ctx ),
- $expected
+ $expected,
+ $module->getStyles( $ctx )
);
}
$this->assertFalse( $module->isKnownEmpty( $ctx ) );
}
+
+ /**
+ * @dataProvider provideGetLogo
+ * @covers ResourceLoaderSkinModule::getLogo
+ */
+ public function testGetLogo( $config, $expected, $baseDir = null ) {
+ if ( $baseDir ) {
+ $oldIP = $GLOBALS['IP'];
+ $GLOBALS['IP'] = $baseDir;
+ $teardown = new Wikimedia\ScopedCallback( function () use ( $oldIP ) {
+ $GLOBALS['IP'] = $oldIP;
+ } );
+ }
+
+ $this->assertEquals(
+ $expected,
+ ResourceLoaderSkinModule::getLogo( new HashConfig( $config ) )
+ );
+ }
+
+ public function provideGetLogo() {
+ return [
+ 'simple' => [
+ 'config' => [
+ 'ResourceBasePath' => '/w',
+ 'Logo' => '/img/default.png',
+ 'LogoHD' => false,
+ ],
+ 'expected' => '/img/default.png',
+ ],
+ 'default and 2x' => [
+ 'config' => [
+ 'ResourceBasePath' => '/w',
+ 'Logo' => '/img/default.png',
+ 'LogoHD' => [
+ '2x' => '/img/two-x.png',
+ ],
+ ],
+ 'expected' => [
+ '1x' => '/img/default.png',
+ '2x' => '/img/two-x.png',
+ ],
+ ],
+ 'default and all HiDPIs' => [
+ 'config' => [
+ 'ResourceBasePath' => '/w',
+ 'Logo' => '/img/default.png',
+ 'LogoHD' => [
+ '1.5x' => '/img/one-point-five.png',
+ '2x' => '/img/two-x.png',
+ ],
+ ],
+ 'expected' => [
+ '1x' => '/img/default.png',
+ '1.5x' => '/img/one-point-five.png',
+ '2x' => '/img/two-x.png',
+ ],
+ ],
+ 'default and SVG' => [
+ 'config' => [
+ 'ResourceBasePath' => '/w',
+ 'Logo' => '/img/default.png',
+ 'LogoHD' => [
+ 'svg' => '/img/vector.svg',
+ ],
+ ],
+ 'expected' => [
+ '1x' => '/img/default.png',
+ 'svg' => '/img/vector.svg',
+ ],
+ ],
+ 'everything' => [
+ 'config' => [
+ 'ResourceBasePath' => '/w',
+ 'Logo' => '/img/default.png',
+ 'LogoHD' => [
+ '1.5x' => '/img/one-point-five.png',
+ '2x' => '/img/two-x.png',
+ 'svg' => '/img/vector.svg',
+ ],
+ ],
+ 'expected' => [
+ '1x' => '/img/default.png',
+ 'svg' => '/img/vector.svg',
+ ],
+ ],
+ 'versioned url' => [
+ 'config' => [
+ 'ResourceBasePath' => '/w',
+ 'Logo' => '/w/test.jpg',
+ 'LogoHD' => false,
+ 'UploadPath' => '/w/images',
+ ],
+ 'expected' => '/w/test.jpg?edcf2',
+ 'baseDir' => dirname( dirname( __DIR__ ) ) . '/data/media',
+ ],
+ ];
+ }
}