* @since 1.26
*/
protected function addLogoPreloadLinkHeaders() {
- $logo = $this->getConfig()->get( 'Logo' ); // wgLogo
- $logoHD = $this->getConfig()->get( 'LogoHD' ); // wgLogoHD
+ $logo = ResourceLoaderSkinModule::getLogo( $this->getConfig() );
$tags = [];
$logosPerDppx = [];
$logos = [];
- $logosPerDppx['1.0'] = $logo;
-
- if ( !$logoHD ) {
+ if ( !is_array( $logo ) ) {
// No media queries required if we only have one variant
$this->addLinkHeader( '<' . $logo . '>;rel=preload;as=image' );
return;
}
- foreach ( $logoHD as $dppx => $src ) {
- // Only 1.5x and 2x are supported
- // Note: Keep in sync with ResourceLoaderSkinModule
- if ( in_array( $dppx, [ '1.5x', '2x' ] ) ) {
- // LogoHD uses a string in this format: "1.5x"
- $dppx = substr( $dppx, 0, -1 );
- $logosPerDppx[$dppx] = $src;
- }
+ foreach ( $logo as $dppx => $src ) {
+ // Keys are in this format: "1.5x"
+ $dppx = substr( $dppx, 0, -1 );
+ $logosPerDppx[$dppx] = $src;
}
// Because PHP can't have floats as array keys
* @return array
*/
public function getStyles( ResourceLoaderContext $context ) {
- $conf = $this->getConfig();
- $logo = $conf->get( 'Logo' );
- $logoHD = $conf->get( 'LogoHD' );
-
- $logo1 = OutputPage::transformResourcePath( $conf, $logo );
- $logo15 = OutputPage::transformResourcePath( $conf, $logoHD['1.5x'] );
- $logo2 = OutputPage::transformResourcePath( $conf, $logoHD['2x'] );
-
+ $logo = $this->getLogo( $this->getConfig() );
$styles = parent::getStyles( $context );
+
+ $default = !is_array( $logo ) ? $logo : $logo['1x'];
$styles['all'][] = '.mw-wiki-logo { background-image: ' .
- CSSMin::buildUrlValue( $logo1 ) .
- '; }';
- // Only 1.5x and 2x are supported
- // Note: Keep in sync with OutputPage::addLogoPreloadLinkHeaders()
- if ( $logoHD ) {
- if ( isset( $logoHD['1.5x'] ) ) {
+ CSSMin::buildUrlValue( $default ) .
+ '; }';
+
+ if ( is_array( $logo ) ) {
+ 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( $logo15 ) . ';' .
+ CSSMin::buildUrlValue( $logo['1.5x'] ) . ';' .
'background-size: 135px auto; }';
}
- if ( isset( $logoHD['2x'] ) ) {
+ 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( $logo2 ) . ';' .
+ CSSMin::buildUrlValue( $logo['2x'] ) . ';' .
'background-size: 135px auto; }';
}
}
+
return $styles;
}
+ /**
+ * @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.
+ */
+ public static function getLogo( Config $conf ) {
+ $logo = $conf->get( 'Logo' );
+ $logoHD = $conf->get( 'LogoHD' );
+
+ $logo1Url = OutputPage::transformResourcePath( $conf, $logo );
+
+ if ( !$logoHD ) {
+ return $logo1Url;
+ }
+
+ $logoUrls = [
+ '1x' => $logo1Url,
+ ];
+
+ // 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;
+ }
+
/**
* @param ResourceLoaderContext $context
* @return bool
/**
* @dataProvider providePreloadLinkHeaders
* @covers OutputPage::addLogoPreloadLinkHeaders
+ * @covers ResourceLoaderSkinModule::getLogo
*/
- public function testPreloadLinkHeaders( $config, $result ) {
+ public function testPreloadLinkHeaders( $config, $result, $baseDir = null ) {
+ if ( $baseDir ) {
+ $this->setMwGlobals( 'IP', $baseDir );
+ }
$out = TestingAccessWrapper::newFromObject( $this->newInstance( $config ) );
$out->addLogoPreloadLinkHeaders();
return [
[
[
+ 'ResourceBasePath' => '/w',
'Logo' => '/img/default.png',
'LogoHD' => [
'1.5x' => '/img/one-point-five.png',
],
[
[
+ 'ResourceBasePath' => '/w',
'Logo' => '/img/default.png',
'LogoHD' => false,
],
],
[
[
+ 'ResourceBasePath' => '/w',
'Logo' => '/img/default.png',
'LogoHD' => [
'2x' => '/img/two-x.png',
'not all and (min-resolution: 2dppx),' .
'</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
],
+ [
+ [
+ 'ResourceBasePath' => '/w',
+ 'Logo' => '/w/test.jpg',
+ 'LogoHD' => false,
+ 'UploadPath' => '/w/images',
+ ],
+ 'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
+ 'baseDir' => dirname( __DIR__ ) . '/data/media',
+ ],
];
}