mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-27 23:50:30 +00:00
Simplify footer and logo generation
The data already provided by SkinMustache makes the existing Minerva code redundant. * html-after-content functionality equivalent to dataAfterContent value * Rename license and last modified to have html-minerva prefixes and promote to top level data object. This allows us to distingusih Minerva values from core values. Note: previously the logo used srcset to ship a 1x logo but these were dropped during the desktop improvements work. Bug: T256083 Change-Id: I7b2cd5181eae67b345f6686e3389a76a12e3b1a1
This commit is contained in:
parent
b858592eea
commit
c3b93e14b0
4
includes/Skins/Logo.mustache
Normal file
4
includes/Skins/Logo.mustache
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{#data-logos}}
|
||||
{{#wordmark}}<img src="{{src}}" width="{{width}}" height="{{height}}" />{{/wordmark}}
|
||||
{{^wordmark}}{{msg-mobile-frontend-footer-sitename}}{{/wordmark}}
|
||||
{{/data-logos}}
|
|
@ -58,45 +58,6 @@ class MinervaTemplate extends BaseTemplate {
|
|||
return $this->isFallbackEditor() ? [] : $this->data['pageActionsMenu'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns template data for footer
|
||||
*
|
||||
* @param array $data Data used to build the page
|
||||
* @return array
|
||||
*/
|
||||
protected function getFooterTemplateData( $data ) {
|
||||
$groups = [];
|
||||
|
||||
foreach ( $data['footerlinks'] as $category => $links ) {
|
||||
$items = [];
|
||||
foreach ( $links as $link ) {
|
||||
if ( isset( $this->data[$link] ) && $data[$link] !== '' && $data[$link] !== false ) {
|
||||
$items[] = [
|
||||
'category' => $category,
|
||||
'name' => $link,
|
||||
'linkhtml' => $data[$link],
|
||||
];
|
||||
}
|
||||
}
|
||||
$groups[] = [
|
||||
'name' => $category,
|
||||
'items' => $items,
|
||||
];
|
||||
}
|
||||
|
||||
// This turns off the footer id and allows us to distinguish the old footer with the new design
|
||||
|
||||
return [
|
||||
'lastmodified' => $this->getHistoryLinkHtml( $data ),
|
||||
'headinghtml' => $data['footer-site-heading-html'],
|
||||
// Note mobile-license is only available on the mobile skin. It is outputted as part of
|
||||
// footer-info on desktop hence the conditional check.
|
||||
'licensehtml' => ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ?
|
||||
MobileFrontendSkinHooks::getLicenseText( $this->getSkin() ) : '',
|
||||
'lists' => $groups,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML for rendering the available page actions
|
||||
* @return string
|
||||
|
@ -241,7 +202,6 @@ class MinervaTemplate extends BaseTemplate {
|
|||
'search' => $data['search'],
|
||||
'placeholder' => wfMessage( 'mobile-frontend-placeholder' ),
|
||||
'main-menu-tooltip' => $this->getMsg( 'mobile-frontend-main-menu-button-tooltip' ),
|
||||
'siteheading' => $data['footer-site-heading-html'],
|
||||
'mainPageURL' => Title::newMainPage()->getLocalURL(),
|
||||
'userNavigationLabel' => wfMessage( 'minerva-user-navigation' ),
|
||||
// A button when clicked will submit the form
|
||||
|
@ -268,8 +228,13 @@ class MinervaTemplate extends BaseTemplate {
|
|||
'subtitle' => $data['subtitle'],
|
||||
'contenthtml' => $this->getContentHtml( $data ),
|
||||
'secondaryactionshtml' => $this->getSecondaryActionsHtml(),
|
||||
'dataAfterContent' => $this->get( 'dataAfterContent' ),
|
||||
'footer' => $this->getFooterTemplateData( $data ),
|
||||
|
||||
'html-minerva-lastmodified' => $this->getHistoryLinkHtml( $data ),
|
||||
// Note mobile-license is only available on the mobile skin. It is outputted as part of
|
||||
// footer-info on desktop hence the conditional check.
|
||||
'html-minerva-license' => ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ?
|
||||
MobileFrontendSkinHooks::getLicenseText( $this->getSkin() ) : '',
|
||||
|
||||
'isBeta' => $skinOptions->get( SkinOptions::BETA_MODE ),
|
||||
'tabs' => $this->showTalkTabs( $hasPageActions, $skinOptions ) &&
|
||||
$skinOptions->get( SkinOptions::TALK_AT_TOP ) ? [
|
||||
|
|
|
@ -58,6 +58,9 @@ class SkinMinerva extends SkinMustache {
|
|||
parent::__construct( [
|
||||
'name' => 'minerva',
|
||||
'templateDirectory' => __DIR__,
|
||||
'messages' => [
|
||||
'mobile-frontend-footer-sitename'
|
||||
],
|
||||
'responsive' => true
|
||||
] );
|
||||
$this->skinOptions = MediaWikiServices::getInstance()->getService( 'Minerva.SkinOptions' );
|
||||
|
@ -106,40 +109,6 @@ class SkinMinerva extends SkinMustache {
|
|||
return $this->mainMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the site name for the footer, either as a text or <img> tag
|
||||
* @return string
|
||||
*/
|
||||
public function getSitename() {
|
||||
$config = $this->getConfig();
|
||||
$logos = ResourceLoaderSkinModule::getAvailableLogos( $config );
|
||||
$wordmark = $logos['wordmark'] ?? false;
|
||||
|
||||
$footerSitename = $this->msg( 'mobile-frontend-footer-sitename' )->text();
|
||||
|
||||
// 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 ];
|
||||
}
|
||||
}
|
||||
$attributes = $wordmarkAttrs + [
|
||||
'alt' => $footerSitename,
|
||||
];
|
||||
if ( isset( $wordmark[ '1x' ] ) ) {
|
||||
$attributes['srcset'] = $wordmark['1x'] . ' 1x';
|
||||
}
|
||||
$sitename = Html::element( 'img', $attributes );
|
||||
} else {
|
||||
$sitename = $footerSitename;
|
||||
}
|
||||
|
||||
return $sitename;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize various variables and generate the template
|
||||
* @return QuickTemplate
|
||||
|
@ -590,7 +559,6 @@ class SkinMinerva extends SkinMustache {
|
|||
}
|
||||
$tpl->set( 'headinghtml', $this->getHeadingHtml() );
|
||||
|
||||
$tpl->set( 'footer-site-heading-html', $this->getSitename() );
|
||||
// set defaults
|
||||
if ( !isset( $tpl->data['postbodytext'] ) ) {
|
||||
$tpl->set( 'postbodytext', '' ); // not currently set in desktop skin
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
{{#footer}}
|
||||
{{#data-footer}}
|
||||
{{! `role` is implied in `footer` element, but added to mitigate a VoiceOver bug. }}
|
||||
<footer class="mw-footer minerva-footer" role="contentinfo">
|
||||
{{{lastmodified}}}
|
||||
<div class="post-content footer-content">
|
||||
{{{dataAfterContent}}}
|
||||
<h2>{{{headinghtml}}}</h2>
|
||||
<div class="license">{{{licensehtml}}}</div>
|
||||
{{#lists}}
|
||||
<ul class="footer-{{name}} hlist hlist-separated">
|
||||
{{#items}}<li id="footer-{{category}}-{{name}}">{{{linkhtml}}}</li>{{/items}}
|
||||
</ul>
|
||||
{{/lists}}
|
||||
</div>
|
||||
{{{html-minerva-lastmodified}}}
|
||||
<div class="post-content footer-content">
|
||||
{{{html-after-content}}}
|
||||
<h2>{{>Logo}}</h2>
|
||||
<div class="license">{{{html-minerva-license}}}</div>
|
||||
{{#data-info}}{{>footerItemList}}{{/data-info}}
|
||||
{{#data-places}}{{>footerItemList}}{{/data-places}}
|
||||
</div>
|
||||
</footer>
|
||||
{{/footer}}
|
||||
{{/data-footer}}
|
||||
|
|
5
includes/Skins/footerItemList.mustache
Normal file
5
includes/Skins/footerItemList.mustache
Normal file
|
@ -0,0 +1,5 @@
|
|||
<ul id="{{id}}" class="{{id}} hlist hlist-separated">
|
||||
{{#array-items}}
|
||||
<li id="{{id}}">{{{html}}}</li>
|
||||
{{/array-items}}
|
||||
</ul>
|
|
@ -13,7 +13,7 @@
|
|||
</nav>
|
||||
<div class="branding-box">
|
||||
<a href="{{mainPageURL}}">
|
||||
<span>{{{siteheading}}}</span>
|
||||
<span>{{>Logo}}</span>
|
||||
{{#isBeta}}<sup>β</sup>{{/isBeta}}
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Tests\MediaWiki\Minerva;
|
||||
|
||||
use HashConfig;
|
||||
use MediaWiki\Minerva\SkinOptions;
|
||||
use MediaWikiTestCase;
|
||||
use OutputPage;
|
||||
|
@ -148,70 +147,4 @@ class SkinMinervaTest extends MediaWikiTestCase {
|
|||
[ false, self::OPTIONS_MODULE, false ],
|
||||
];
|
||||
}
|
||||
|
||||
public function provideGetSitename() {
|
||||
return [
|
||||
[
|
||||
[
|
||||
'Logos' => false,
|
||||
'Logo' => '/logo.svg',
|
||||
],
|
||||
'(mobile-frontend-footer-sitename)',
|
||||
'No wgLogos 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`.'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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