mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-09-24 10:48:29 +00:00
Deprecate wgMinervaCustomLogos in favor of $wgLogos
Testing: ``` // Start with no Minerva config and no wgLogos defined in LocalSettings.php // Set $wgMinervaCustomLogos // Should trigger deprecation warning. $wgMinervaCustomLogos = [ 'copyright' => 'https://en.m.wikipedia.org/static/images/mobile/copyright/wikipedia-wordmark-fr.svg', 'copyright-height' => 40, 'copyright-width' => 120, ]; // Set wgLogos without wordmark // Should trigger deprecation warning as $wgMinervaCustomLogos is still // defined. $wgLogos = [ '1x' => 'https://en.wikipedia.beta.wmflabs.org/static/images/project-logos/enwiki.png' ]; // Set wgLogos['wordmark'] // No deprecation warning. $wgMinervaCustomLogos will now be ignored // in favor of the new wordmark key. $wgLogos = [ '1x' => 'https://en.wikipedia.beta.wmflabs.org/static/images/project-logos/enwiki.png', 'wordmark' => [ 'src' => 'https://en.m.wikipedia.org/static/images/mobile/copyright/wikipedia-wordmark-fr.svg', 'height' => 40, 'width' => 120, ], ]; // You can now safely drop $wgMinervaCustomLogos. ``` Depends-On: I66a971631c623cc94b58eb0e5e5bad804789bf1c Bug: T232140 Change-Id: I013bd0904fe8c55efa49d14e84cf06ec1412896f
This commit is contained in:
parent
7131fa054c
commit
51a348097d
|
@ -91,36 +91,79 @@ class SkinMinerva extends SkinTemplate {
|
|||
return $this->mainMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consults the deprecated $wgMinervaCustomLogos for a $wgLogo compatible logo.
|
||||
* @deprecated since 1.35
|
||||
* @param Config $config
|
||||
* @return array|false either an array representing a wordmark or false if no wordmark exists.
|
||||
*/
|
||||
private function getSitenameFromLegacyCode( Config $config ) {
|
||||
try {
|
||||
/**
|
||||
* Before 1.35 this config variable defined an array with the keys
|
||||
* `copyright`, `copyright-width`, and `copyright-height`.
|
||||
* These equate to keys of wgLogos['wordmark'] - `src`, `width` and `height`
|
||||
* respectfully. The array also had a key `copyright-fallback`, which is not
|
||||
* supported in the new logos but can be replicated using a PNG for `1x` and
|
||||
* an SVG for `2x`.
|
||||
*/
|
||||
$customLogos = $config->get( 'MinervaCustomLogos' );
|
||||
wfDeprecated( 'MinervaCustomLogos', '1.35' );
|
||||
if ( isset( $customLogos['copyright'] ) ) {
|
||||
$src = $customLogos['copyright'];
|
||||
$logo1x = null;
|
||||
if ( pathinfo( $src, PATHINFO_EXTENSION ) === 'svg' ) {
|
||||
$logo1x = $src;
|
||||
if ( isset( $customLogos['copyright-fallback'] ) ) {
|
||||
$src = $customLogos['copyright-fallback'];
|
||||
} else {
|
||||
$src = preg_replace( '/\.svg$/i', '.png', $src );
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'src' => $src,
|
||||
'1x' => $logo1x,
|
||||
'height' => $customLogos['copyright-height'] ?? null,
|
||||
'width' => $customLogos['copyright-width'] ?? null,
|
||||
];
|
||||
}
|
||||
} catch ( ConfigException $e ) {
|
||||
// Do nothing.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the site name for the footer, either as a text or <img> tag
|
||||
* @return string
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function getSitename() {
|
||||
$config = $this->getConfig();
|
||||
$customLogos = $config->get( 'MinervaCustomLogos' );
|
||||
$logos = ResourceLoaderSkinModule::getAvailableLogos( $config );
|
||||
$wordmark = false;
|
||||
if ( isset( $logos['wordmark'] ) ) {
|
||||
$wordmark = $logos['wordmark'];
|
||||
} else {
|
||||
$wordmark = $this->getSitenameFromLegacyCode( $config );
|
||||
}
|
||||
|
||||
$footerSitename = $this->msg( 'mobile-frontend-footer-sitename' )->text();
|
||||
|
||||
// If there's a custom site logo, use that instead of text
|
||||
if ( isset( $customLogos['copyright'] ) ) {
|
||||
$attributes = [
|
||||
'src' => $customLogos['copyright'],
|
||||
'alt' => $footerSitename,
|
||||
];
|
||||
if ( pathinfo( $customLogos['copyright'], PATHINFO_EXTENSION ) === 'svg' ) {
|
||||
$attributes['srcset'] = $customLogos['copyright'] . ' 1x';
|
||||
if ( isset( $customLogos['copyright-fallback'] ) ) {
|
||||
$attributes['src'] = $customLogos['copyright-fallback'];
|
||||
} else {
|
||||
$attributes['src'] = preg_replace( '/\.svg$/i', '.png', $customLogos['copyright'] );
|
||||
// If there's a custom site logo, use that instead of text.
|
||||
if ( $wordmark ) {
|
||||
$wordmarkAttrs = [];
|
||||
|
||||
foreach ( [ 'src', 'width', 'height' ] as $key ) {
|
||||
if ( isset( $wordmark[ $key ] ) ) {
|
||||
$wordmarkAttrs[ $key ] = $wordmark[ $key ];
|
||||
}
|
||||
}
|
||||
if ( isset( $customLogos['copyright-height'] ) ) {
|
||||
$attributes['height'] = $customLogos['copyright-height'];
|
||||
}
|
||||
if ( isset( $customLogos['copyright-width'] ) ) {
|
||||
$attributes['width'] = $customLogos['copyright-width'];
|
||||
$attributes = $wordmarkAttrs + [
|
||||
'alt' => $footerSitename,
|
||||
];
|
||||
if ( isset( $wordmark[ '1x' ] ) ) {
|
||||
$attributes['srcset'] = $wordmark['1x'] . ' 1x';
|
||||
}
|
||||
$sitename = Html::element( 'img', $attributes );
|
||||
} else {
|
||||
|
|
|
@ -30,9 +30,6 @@
|
|||
"MinervaEnableSiteNotice": {
|
||||
"value": false
|
||||
},
|
||||
"MinervaCustomLogos": {
|
||||
"value": []
|
||||
},
|
||||
"MinervaApplyKnownTemplateHacks": {
|
||||
"value": false
|
||||
},
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\MediaWiki\Minerva;
|
||||
|
||||
use HashConfig;
|
||||
use MediaWiki\Minerva\SkinOptions;
|
||||
use MediaWikiTestCase;
|
||||
use OutputPage;
|
||||
|
@ -107,7 +108,7 @@ class SkinMinervaTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test whether the font changer module is correctly added to the list context modules
|
||||
* Test whether the font changer module is correctly added to the list context modules.
|
||||
*
|
||||
* @covers ::getContextSpecificModules
|
||||
* @dataProvider provideGetContextSpecificModules
|
||||
|
@ -145,4 +146,86 @@ class SkinMinervaTest extends MediaWikiTestCase {
|
|||
[ false, self::OPTIONS_MODULE, false ],
|
||||
];
|
||||
}
|
||||
|
||||
public function provideGetSitename() {
|
||||
return [
|
||||
[
|
||||
[
|
||||
'Logos' => false,
|
||||
'Logo' => '/logo.svg',
|
||||
],
|
||||
'(mobile-frontend-footer-sitename)',
|
||||
'No wgLogos or wgMinervaCustomLogos defined.'
|
||||
],
|
||||
[
|
||||
[
|
||||
'Logos' => [
|
||||
'1x' => '/logo.svg',
|
||||
'wordmark' => [
|
||||
'src' => '/wordmark.svg',
|
||||
'width' => '10',
|
||||
'height' => '10',
|
||||
],
|
||||
],
|
||||
],
|
||||
'<img src="/wordmark.svg" width="10" height="10" alt="(mobile-frontend-footer-sitename)"/>',
|
||||
'wgLogos used.'
|
||||
],
|
||||
[
|
||||
[
|
||||
'Logos' => [
|
||||
'1x' => '/logo.svg',
|
||||
'wordmark' => [
|
||||
'src' => '/wordmark.png',
|
||||
'1x' => '/wordmark.svg',
|
||||
'width' => '10',
|
||||
'height' => '10',
|
||||
],
|
||||
],
|
||||
],
|
||||
'<img src="/wordmark.png" width="10" height="10" '
|
||||
. 'alt="(mobile-frontend-footer-sitename)" srcset="/wordmark.svg 1x"/>',
|
||||
'wgLogos used with `png` and `svg`.'
|
||||
],
|
||||
[
|
||||
[
|
||||
'DevelopmentWarnings' => false,
|
||||
'MinervaCustomLogos' => [
|
||||
'copyright' => '/wordmark.svg',
|
||||
'copyright-width' => '10',
|
||||
'copyright-height' => '10',
|
||||
],
|
||||
'Logos' => [
|
||||
'1x' => '/logo.svg',
|
||||
],
|
||||
],
|
||||
'<img src="/wordmark.png" width="10" height="10" '
|
||||
. 'alt="(mobile-frontend-footer-sitename)" srcset="/wordmark.svg 1x"/>',
|
||||
'wgMinervaCustomLogos used.'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the font changer module is correctly added to the list context modules
|
||||
*
|
||||
* @covers ::getSitename
|
||||
* @dataProvider provideGetSitename
|
||||
*/
|
||||
public function testGetSitename( $configData, $expected, $msg ) {
|
||||
$skin = new SkinMinerva();
|
||||
$config = new HashConfig( $configData );
|
||||
$context = new RequestContext();
|
||||
$context->setLanguage( 'qqx' );
|
||||
$context->setConfig( $config );
|
||||
$skin->setContext( $context );
|
||||
|
||||
// See T236778
|
||||
$this->setMwGlobals( [
|
||||
'wgDevelopmentWarnings' => false
|
||||
] );
|
||||
|
||||
$sitename = $skin->getSitename();
|
||||
$this->assertEquals( $sitename, $expected, $msg );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue