mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-27 23:50:30 +00:00
Remove MinervaTemplate class
- Update SkinMinerva class to output data previously handled by MinervaTemplate. - Update relevant templates with updated data keys. Bug: T293815 Change-Id: I33df396b07c4d2d9c1c5743d90dc54cdbd3345af
This commit is contained in:
parent
280b7b28f7
commit
7530f1c145
|
@ -1,68 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
* http://www.gnu.org/copyleft/gpl.html
|
|
||||||
*
|
|
||||||
* @file
|
|
||||||
*/
|
|
||||||
use MediaWiki\MediaWikiServices;
|
|
||||||
use MediaWiki\Minerva\SkinOptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extended Template class of BaseTemplate for mobile devices
|
|
||||||
*/
|
|
||||||
class MinervaTemplate extends BaseTemplate {
|
|
||||||
/**
|
|
||||||
* Start render the page in template
|
|
||||||
* @deprecated please migrate code here to SkinMinerva::getTemplateData
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function execute() {
|
|
||||||
return $this->getTemplateData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the main menu HTML.
|
|
||||||
* @param array $data Data used to build the page
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getMainMenuData( $data ) {
|
|
||||||
return $data['mainMenu']['items'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the entire page
|
|
||||||
* @deprecated please migrate code here to SkinMinerva::getTemplateData
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getTemplateData() {
|
|
||||||
$data = $this->data;
|
|
||||||
$skinOptions = MediaWikiServices::getInstance()->getService( 'Minerva.SkinOptions' );
|
|
||||||
$templateParser = new TemplateParser( __DIR__ );
|
|
||||||
|
|
||||||
// prepare template data
|
|
||||||
return [
|
|
||||||
'banners' => $data['banners'],
|
|
||||||
'isAnon' => $data['username'] === null,
|
|
||||||
'userNotificationsHTML' => $data['userNotificationsHTML'] ?? '',
|
|
||||||
'data-main-menu' => $this->getMainMenuData( $data ),
|
|
||||||
'taglinehtml' => $data['taglinehtml'],
|
|
||||||
'headinghtml' => $data['headinghtml'] ?? '',
|
|
||||||
'postheadinghtml' => $data['postheadinghtml'] ?? '',
|
|
||||||
'userMenuHTML' => $data['userMenuHTML'],
|
|
||||||
'isBeta' => $skinOptions->get( SkinOptions::BETA_MODE ),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -109,9 +109,17 @@ class SkinMinerva extends SkinMustache {
|
||||||
unset( $data['html-categories'] );
|
unset( $data['html-categories'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl = $this->prepareQuickTemplate();
|
return $data + [
|
||||||
$tplData = $tpl->execute();
|
'array-minerva-banners' => $this->prepareBanners( $data['html-site-notice'] ),
|
||||||
return $data + $tplData + [
|
'html-minerva-user-notifications' => $this->prepareUserNotificationsButton( $this->getNewtalks() ),
|
||||||
|
'data-minerva-main-menu' => $this->getMainMenu()->getMenuData()['items'],
|
||||||
|
'html-minerva-tagline' => $this->getTaglineHtml(),
|
||||||
|
'html-minerva-heading' => $this->prepareHeader(),
|
||||||
|
'html-minerva-post-heading' => $this->isTalkPageWithViewAction()
|
||||||
|
? $this->getTalkPagePostHeadingHtml()
|
||||||
|
: '',
|
||||||
|
'html-minerva-user-menu' => $this->prepareMenus(),
|
||||||
|
'is-minerva-beta' => $this->getSkinOptions()->get( SkinOptions::BETA_MODE ),
|
||||||
'data-minerva-tabs' => $this->getTabsData(),
|
'data-minerva-tabs' => $this->getTabsData(),
|
||||||
'data-minerva-page-actions' => $this->getPageActions(),
|
'data-minerva-page-actions' => $this->getPageActions(),
|
||||||
'data-minerva-secondary-actions' => $this->getSecondaryActions(),
|
'data-minerva-secondary-actions' => $this->getSecondaryActions(),
|
||||||
|
@ -191,33 +199,12 @@ class SkinMinerva extends SkinMustache {
|
||||||
return $this->mainMenu;
|
return $this->mainMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* initialize various variables and generate the template
|
|
||||||
* @return QuickTemplate
|
|
||||||
* @suppress PhanTypeMismatchArgument
|
|
||||||
*/
|
|
||||||
protected function prepareQuickTemplate() {
|
|
||||||
$out = $this->getOutput();
|
|
||||||
|
|
||||||
// Generate skin template
|
|
||||||
$tpl = parent::prepareQuickTemplate();
|
|
||||||
|
|
||||||
// Construct various Minerva-specific interface elements
|
|
||||||
$this->prepareMenus( $tpl );
|
|
||||||
$this->prepareHeaderAndFooter( $tpl );
|
|
||||||
$this->prepareBanners( $tpl );
|
|
||||||
$this->prepareUserNotificationsButton( $tpl, $tpl->get( 'newtalk' ) );
|
|
||||||
$this->prepareLanguages( $tpl );
|
|
||||||
|
|
||||||
return $tpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare all Minerva menus
|
* Prepare all Minerva menus
|
||||||
* @param BaseTemplate $tpl
|
* @return string|null
|
||||||
* @throws MWException
|
* @throws MWException
|
||||||
*/
|
*/
|
||||||
private function prepareMenus( BaseTemplate $tpl ) {
|
private function prepareMenus() {
|
||||||
$services = MediaWikiServices::getInstance();
|
$services = MediaWikiServices::getInstance();
|
||||||
/** @var \MediaWiki\Minerva\Menu\PageActions\PageActionsDirector $pageActionsDirector */
|
/** @var \MediaWiki\Minerva\Menu\PageActions\PageActionsDirector $pageActionsDirector */
|
||||||
$pageActionsDirector = $services->getService( 'Minerva.Menu.PageActionsDirector' );
|
$pageActionsDirector = $services->getService( 'Minerva.Menu.PageActionsDirector' );
|
||||||
|
@ -225,14 +212,14 @@ class SkinMinerva extends SkinMustache {
|
||||||
$userMenuDirector = $services->getService( 'Minerva.Menu.UserMenuDirector' );
|
$userMenuDirector = $services->getService( 'Minerva.Menu.UserMenuDirector' );
|
||||||
|
|
||||||
$sidebar = parent::buildSidebar();
|
$sidebar = parent::buildSidebar();
|
||||||
$personalUrls = $tpl->get( 'personal_urls' );
|
|
||||||
$personalTools = $this->getSkin()->getPersonalToolsForMakeListItem( $personalUrls );
|
|
||||||
$nav = $this->buildContentNavigationUrls();
|
$nav = $this->buildContentNavigationUrls();
|
||||||
$actions = $nav['actions'] ?? [];
|
$actions = $nav['actions'] ?? [];
|
||||||
$tpl->set( 'mainMenu', $this->getMainMenu()->getMenuData() );
|
$personalUrls = isset( $nav['user-menu'] ) ? $this->injectLegacyMenusIntoPersonalTools( $nav ) : [];
|
||||||
|
$personalTools = $this->getSkin()->getPersonalToolsForMakeListItem( $personalUrls );
|
||||||
$this->contentNavigationUrls = $nav;
|
$this->contentNavigationUrls = $nav;
|
||||||
$this->pageActionsMenu = $pageActionsDirector->buildMenu( $sidebar['TOOLBOX'], $actions );
|
$this->pageActionsMenu = $pageActionsDirector->buildMenu( $sidebar['TOOLBOX'], $actions );
|
||||||
$tpl->set( 'userMenuHTML', $userMenuDirector->renderMenuData( $personalTools ) );
|
|
||||||
|
return $userMenuDirector->renderMenuData( $personalTools );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -360,17 +347,16 @@ class SkinMinerva extends SkinMustache {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the user button.
|
* Prepares the user button.
|
||||||
* @param QuickTemplate $tpl
|
|
||||||
* @param string $newTalks New talk page messages for the current user
|
* @param string $newTalks New talk page messages for the current user
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function prepareUserNotificationsButton( QuickTemplate $tpl, $newTalks ) {
|
protected function prepareUserNotificationsButton( $newTalks ) {
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
$currentTitle = $this->getTitle();
|
|
||||||
$notificationsMsg = $this->msg( 'mobile-frontend-user-button-tooltip' )->text();
|
|
||||||
$notificationIconClass = MinervaUI::iconClass( 'bellOutline-base20',
|
|
||||||
'element', '', 'wikimedia' );
|
|
||||||
|
|
||||||
if ( $user->isRegistered() ) {
|
if ( $user->isRegistered() ) {
|
||||||
|
$currentTitle = $this->getTitle();
|
||||||
|
$notificationsMsg = $this->msg( 'mobile-frontend-user-button-tooltip' )->text();
|
||||||
|
$notificationIconClass = MinervaUI::iconClass( 'bellOutline-base20',
|
||||||
|
'element', '', 'wikimedia' );
|
||||||
$badge = Html::element( 'a', [
|
$badge = Html::element( 'a', [
|
||||||
'class' => $notificationIconClass,
|
'class' => $notificationIconClass,
|
||||||
'href' => SpecialPage::getTitleFor( 'Mytalk' )->getLocalURL(
|
'href' => SpecialPage::getTitleFor( 'Mytalk' )->getLocalURL(
|
||||||
|
@ -379,25 +365,9 @@ class SkinMinerva extends SkinMustache {
|
||||||
], $notificationsMsg );
|
], $notificationsMsg );
|
||||||
Hooks::run( 'SkinMinervaReplaceNotificationsBadge',
|
Hooks::run( 'SkinMinervaReplaceNotificationsBadge',
|
||||||
[ $user, $currentTitle, &$badge ] );
|
[ $user, $currentTitle, &$badge ] );
|
||||||
$tpl->set( 'userNotificationsHTML', $badge );
|
return $badge;
|
||||||
}
|
}
|
||||||
}
|
return '';
|
||||||
|
|
||||||
/**
|
|
||||||
* Rewrites the language list so that it cannot be contaminated by other extensions with things
|
|
||||||
* other than languages
|
|
||||||
* See bug 57094.
|
|
||||||
*
|
|
||||||
* @todo Remove when Special:Languages link goes stable
|
|
||||||
* @param QuickTemplate $tpl
|
|
||||||
*/
|
|
||||||
protected function prepareLanguages( $tpl ) {
|
|
||||||
$lang = $this->getTitle()->getPageViewLanguage();
|
|
||||||
$tpl->set( 'pageLang', $lang->getHtmlCode() );
|
|
||||||
$tpl->set( 'pageDir', $lang->getDir() );
|
|
||||||
// If the array is empty, then instead give the skin boolean false
|
|
||||||
$language_urls = $this->getLanguages() ?: false;
|
|
||||||
$tpl->set( 'language_urls', $language_urls );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -642,51 +612,39 @@ class SkinMinerva extends SkinMustache {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and prepare header and footer content
|
* Create and prepare header content
|
||||||
* @param BaseTemplate $tpl
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function prepareHeaderAndFooter( BaseTemplate $tpl ) {
|
protected function prepareHeader() {
|
||||||
$title = $this->getTitle();
|
$title = $this->getTitle();
|
||||||
$user = $this->getUser();
|
|
||||||
$out = $this->getOutput();
|
|
||||||
$tpl->set( 'taglinehtml', $this->getTaglineHtml() );
|
|
||||||
|
|
||||||
if ( $title->isMainPage() ) {
|
if ( $title->isMainPage() ) {
|
||||||
|
$user = $this->getUser();
|
||||||
$msg = $this->msg( 'mobile-frontend-logged-in-homepage-notification', $user->getName() );
|
$msg = $this->msg( 'mobile-frontend-logged-in-homepage-notification', $user->getName() );
|
||||||
|
|
||||||
if ( $user->isRegistered() && !$msg->isDisabled() ) {
|
if ( $user->isRegistered() && !$msg->isDisabled() ) {
|
||||||
|
$out = $this->getOutput();
|
||||||
$out->setPageTitle( $msg->text() );
|
$out->setPageTitle( $msg->text() );
|
||||||
}
|
}
|
||||||
} elseif ( $this->isTalkPageWithViewAction() ) {
|
|
||||||
// We only want the simplified talk page to show for the view action of the
|
|
||||||
// talk (e.g. not history action)
|
|
||||||
$tpl->set( 'postheadinghtml', $this->getTalkPagePostHeadingHtml() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl->set( 'headinghtml', $this->getHeadingHtml() );
|
return $this->getHeadingHtml();
|
||||||
|
|
||||||
// set defaults
|
|
||||||
if ( !isset( $tpl->data['postbodytext'] ) ) {
|
|
||||||
$tpl->set( 'postbodytext', '' ); // not currently set in desktop skin
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load internal banner content to show in pre content in template
|
* Load internal banner content to show in pre content in template
|
||||||
* Beware of HTML caching when using this function.
|
* Beware of HTML caching when using this function.
|
||||||
* Content set as "internalbanner"
|
* Content set as "internalbanner"
|
||||||
* @param BaseTemplate $tpl
|
* @param string $siteNotice HTML fragment
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function prepareBanners( BaseTemplate $tpl ) {
|
protected function prepareBanners( $siteNotice ) {
|
||||||
// Make sure Zero banner are always on top
|
$banners = [];
|
||||||
$banners = [ '<div id="siteNotice"></div>' ];
|
|
||||||
if ( $this->getConfig()->get( 'MinervaEnableSiteNotice' ) ) {
|
if ( $this->getConfig()->get( 'MinervaEnableSiteNotice' ) ) {
|
||||||
$siteNotice = $this->getSiteNotice();
|
|
||||||
if ( $siteNotice ) {
|
if ( $siteNotice ) {
|
||||||
$banners[] = $siteNotice;
|
$banners[] = $siteNotice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$tpl->set( 'banners', $banners );
|
return $banners;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{{#banners}}{{{.}}}{{/banners}}
|
{{#array-minerva-banners}}{{{.}}}{{/array-minerva-banners}}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<label for="main-menu-input" id="mw-mf-main-menu-button"
|
<label for="main-menu-input" id="mw-mf-main-menu-button"
|
||||||
class=" mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-menu-base20 mw-ui-icon-flush-left toggle-list__toggle"
|
class=" mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-menu-base20 mw-ui-icon-flush-left toggle-list__toggle"
|
||||||
title="{{msg-mobile-frontend-main-menu-button-tooltip}}" data-event-name="ui.mainmenu">{{msg-mobile-frontend-main-menu-button-tooltip}}</label>
|
title="{{msg-mobile-frontend-main-menu-button-tooltip}}" data-event-name="ui.mainmenu">{{msg-mobile-frontend-main-menu-button-tooltip}}</label>
|
||||||
{{#data-main-menu}}{{>menu}}{{/data-main-menu}}
|
{{#data-minerva-main-menu}}{{>menu}}{{/data-minerva-main-menu}}
|
||||||
<label class="main-menu-mask" for="main-menu-input"></label>
|
<label class="main-menu-mask" for="main-menu-input"></label>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="branding-box">
|
<div class="branding-box">
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
{{#data-logos}}
|
{{#data-logos}}
|
||||||
<span>{{>Logo}}</span>
|
<span>{{>Logo}}</span>
|
||||||
{{/data-logos}}
|
{{/data-logos}}
|
||||||
{{#isBeta}}<sup>β</sup>{{/isBeta}}
|
{{#is-minerva-beta}}<sup>β</sup>{{/is-minerva-beta}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{#data-search-box}}
|
{{#data-search-box}}
|
||||||
|
@ -37,12 +37,12 @@
|
||||||
}}
|
}}
|
||||||
<button id="searchIcon" class="mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-search-base20 skin-minerva-search-trigger mw-ui-button mw-ui-quiet">{{msg-searchbutton}}</button>
|
<button id="searchIcon" class="mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-search-base20 skin-minerva-search-trigger mw-ui-button mw-ui-quiet">{{msg-searchbutton}}</button>
|
||||||
</div>
|
</div>
|
||||||
{{^isAnon}}
|
{{^is-anon}}
|
||||||
<div class="minerva-user-notifications" id="pt-notifications-alert">
|
<div class="minerva-user-notifications" id="pt-notifications-alert">
|
||||||
{{{userNotificationsHTML}}}
|
{{{html-minerva-user-notifications}}}
|
||||||
</div>
|
</div>
|
||||||
{{/isAnon}}
|
{{/is-anon}}
|
||||||
{{#userMenuHTML}}{{{userMenuHTML}}}{{/userMenuHTML}}
|
{{#html-minerva-user-menu}}{{{html-minerva-user-menu}}}{{/html-minerva-user-menu}}
|
||||||
</nav>
|
</nav>
|
||||||
</form>
|
</form>
|
||||||
</header>
|
</header>
|
||||||
|
@ -58,8 +58,8 @@
|
||||||
{{/html-user-message}}
|
{{/html-user-message}}
|
||||||
<div class="pre-content heading-holder">
|
<div class="pre-content heading-holder">
|
||||||
<div class="page-heading">
|
<div class="page-heading">
|
||||||
{{{headinghtml}}}
|
{{{html-minerva-heading}}}
|
||||||
{{{taglinehtml}}}
|
{{{html-minerva-tagline}}}
|
||||||
</div>
|
</div>
|
||||||
{{#data-minerva-tabs}}
|
{{#data-minerva-tabs}}
|
||||||
<div class="minerva__tab-container">
|
<div class="minerva__tab-container">
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
{{#data-minerva-page-actions}}
|
{{#data-minerva-page-actions}}
|
||||||
{{>PageActionsMenu}}
|
{{>PageActionsMenu}}
|
||||||
{{/data-minerva-page-actions}}
|
{{/data-minerva-page-actions}}
|
||||||
{{{postheadinghtml}}}
|
{{{html-minerva-post-heading}}}
|
||||||
<div class="minerva__subtitle">{{{html-subtitle}}}</div>
|
<div class="minerva__subtitle">{{{html-subtitle}}}</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="bodyContent" class="content">
|
<div id="bodyContent" class="content">
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
"AutoloadClasses": {
|
"AutoloadClasses": {
|
||||||
"MinervaUI": "includes/MinervaUI.php",
|
"MinervaUI": "includes/MinervaUI.php",
|
||||||
"MinervaHooks": "includes/MinervaHooks.php",
|
"MinervaHooks": "includes/MinervaHooks.php",
|
||||||
"MinervaTemplate": "includes/Skins/MinervaTemplate.php",
|
|
||||||
"SkinMinerva": "includes/Skins/SkinMinerva.php",
|
"SkinMinerva": "includes/Skins/SkinMinerva.php",
|
||||||
"SkinMinervaNeue": "includes/Skins/SkinMinerva.php"
|
"SkinMinervaNeue": "includes/Skins/SkinMinerva.php"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue