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'] );
|
||||
}
|
||||
|
||||
$tpl = $this->prepareQuickTemplate();
|
||||
$tplData = $tpl->execute();
|
||||
return $data + $tplData + [
|
||||
return $data + [
|
||||
'array-minerva-banners' => $this->prepareBanners( $data['html-site-notice'] ),
|
||||
'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-page-actions' => $this->getPageActions(),
|
||||
'data-minerva-secondary-actions' => $this->getSecondaryActions(),
|
||||
|
@ -191,33 +199,12 @@ class SkinMinerva extends SkinMustache {
|
|||
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
|
||||
* @param BaseTemplate $tpl
|
||||
* @return string|null
|
||||
* @throws MWException
|
||||
*/
|
||||
private function prepareMenus( BaseTemplate $tpl ) {
|
||||
private function prepareMenus() {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
/** @var \MediaWiki\Minerva\Menu\PageActions\PageActionsDirector $pageActionsDirector */
|
||||
$pageActionsDirector = $services->getService( 'Minerva.Menu.PageActionsDirector' );
|
||||
|
@ -225,14 +212,14 @@ class SkinMinerva extends SkinMustache {
|
|||
$userMenuDirector = $services->getService( 'Minerva.Menu.UserMenuDirector' );
|
||||
|
||||
$sidebar = parent::buildSidebar();
|
||||
$personalUrls = $tpl->get( 'personal_urls' );
|
||||
$personalTools = $this->getSkin()->getPersonalToolsForMakeListItem( $personalUrls );
|
||||
$nav = $this->buildContentNavigationUrls();
|
||||
$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->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.
|
||||
* @param QuickTemplate $tpl
|
||||
* @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();
|
||||
if ( $user->isRegistered() ) {
|
||||
$currentTitle = $this->getTitle();
|
||||
$notificationsMsg = $this->msg( 'mobile-frontend-user-button-tooltip' )->text();
|
||||
$notificationIconClass = MinervaUI::iconClass( 'bellOutline-base20',
|
||||
'element', '', 'wikimedia' );
|
||||
|
||||
if ( $user->isRegistered() ) {
|
||||
$badge = Html::element( 'a', [
|
||||
'class' => $notificationIconClass,
|
||||
'href' => SpecialPage::getTitleFor( 'Mytalk' )->getLocalURL(
|
||||
|
@ -379,25 +365,9 @@ class SkinMinerva extends SkinMustache {
|
|||
], $notificationsMsg );
|
||||
Hooks::run( 'SkinMinervaReplaceNotificationsBadge',
|
||||
[ $user, $currentTitle, &$badge ] );
|
||||
$tpl->set( 'userNotificationsHTML', $badge );
|
||||
return $badge;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -642,51 +612,39 @@ class SkinMinerva extends SkinMustache {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create and prepare header and footer content
|
||||
* @param BaseTemplate $tpl
|
||||
* Create and prepare header content
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareHeaderAndFooter( BaseTemplate $tpl ) {
|
||||
protected function prepareHeader() {
|
||||
$title = $this->getTitle();
|
||||
$user = $this->getUser();
|
||||
$out = $this->getOutput();
|
||||
$tpl->set( 'taglinehtml', $this->getTaglineHtml() );
|
||||
|
||||
if ( $title->isMainPage() ) {
|
||||
$user = $this->getUser();
|
||||
$msg = $this->msg( 'mobile-frontend-logged-in-homepage-notification', $user->getName() );
|
||||
|
||||
if ( $user->isRegistered() && !$msg->isDisabled() ) {
|
||||
$out = $this->getOutput();
|
||||
$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() );
|
||||
|
||||
// set defaults
|
||||
if ( !isset( $tpl->data['postbodytext'] ) ) {
|
||||
$tpl->set( 'postbodytext', '' ); // not currently set in desktop skin
|
||||
}
|
||||
return $this->getHeadingHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load internal banner content to show in pre content in template
|
||||
* Beware of HTML caching when using this function.
|
||||
* Content set as "internalbanner"
|
||||
* @param BaseTemplate $tpl
|
||||
* @param string $siteNotice HTML fragment
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareBanners( BaseTemplate $tpl ) {
|
||||
// Make sure Zero banner are always on top
|
||||
$banners = [ '<div id="siteNotice"></div>' ];
|
||||
protected function prepareBanners( $siteNotice ) {
|
||||
$banners = [];
|
||||
if ( $this->getConfig()->get( 'MinervaEnableSiteNotice' ) ) {
|
||||
$siteNotice = $this->getSiteNotice();
|
||||
if ( $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"
|
||||
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>
|
||||
{{#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>
|
||||
</nav>
|
||||
<div class="branding-box">
|
||||
|
@ -16,7 +16,7 @@
|
|||
{{#data-logos}}
|
||||
<span>{{>Logo}}</span>
|
||||
{{/data-logos}}
|
||||
{{#isBeta}}<sup>β</sup>{{/isBeta}}
|
||||
{{#is-minerva-beta}}<sup>β</sup>{{/is-minerva-beta}}
|
||||
</a>
|
||||
</div>
|
||||
{{#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>
|
||||
</div>
|
||||
{{^isAnon}}
|
||||
{{^is-anon}}
|
||||
<div class="minerva-user-notifications" id="pt-notifications-alert">
|
||||
{{{userNotificationsHTML}}}
|
||||
{{{html-minerva-user-notifications}}}
|
||||
</div>
|
||||
{{/isAnon}}
|
||||
{{#userMenuHTML}}{{{userMenuHTML}}}{{/userMenuHTML}}
|
||||
{{/is-anon}}
|
||||
{{#html-minerva-user-menu}}{{{html-minerva-user-menu}}}{{/html-minerva-user-menu}}
|
||||
</nav>
|
||||
</form>
|
||||
</header>
|
||||
|
@ -58,8 +58,8 @@
|
|||
{{/html-user-message}}
|
||||
<div class="pre-content heading-holder">
|
||||
<div class="page-heading">
|
||||
{{{headinghtml}}}
|
||||
{{{taglinehtml}}}
|
||||
{{{html-minerva-heading}}}
|
||||
{{{html-minerva-tagline}}}
|
||||
</div>
|
||||
{{#data-minerva-tabs}}
|
||||
<div class="minerva__tab-container">
|
||||
|
@ -71,7 +71,7 @@
|
|||
{{#data-minerva-page-actions}}
|
||||
{{>PageActionsMenu}}
|
||||
{{/data-minerva-page-actions}}
|
||||
{{{postheadinghtml}}}
|
||||
{{{html-minerva-post-heading}}}
|
||||
<div class="minerva__subtitle">{{{html-subtitle}}}</div>
|
||||
</div>
|
||||
<div id="bodyContent" class="content">
|
||||
|
|
|
@ -125,7 +125,6 @@
|
|||
"AutoloadClasses": {
|
||||
"MinervaUI": "includes/MinervaUI.php",
|
||||
"MinervaHooks": "includes/MinervaHooks.php",
|
||||
"MinervaTemplate": "includes/Skins/MinervaTemplate.php",
|
||||
"SkinMinerva": "includes/Skins/SkinMinerva.php",
|
||||
"SkinMinervaNeue": "includes/Skins/SkinMinerva.php"
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue