2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2018-04-15 23:21:12 +00:00
|
|
|
* 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
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2019-04-10 21:43:50 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extended Template class of BaseTemplate for mobile devices
|
|
|
|
*/
|
|
|
|
class MinervaTemplate extends BaseTemplate {
|
2017-07-24 16:53:04 +00:00
|
|
|
/** @var bool Specify whether the page is a special page */
|
2017-07-12 15:12:40 +00:00
|
|
|
protected $isSpecialPage;
|
|
|
|
|
2017-07-24 16:53:04 +00:00
|
|
|
/** @var bool Whether or not the user is on the Special:MobileMenu page */
|
2017-07-12 15:12:40 +00:00
|
|
|
protected $isSpecialMobileMenuPage;
|
|
|
|
|
2017-07-24 16:53:04 +00:00
|
|
|
/** @var bool Specify whether the page is main page */
|
2017-07-12 15:12:40 +00:00
|
|
|
protected $isMainPage;
|
|
|
|
|
2019-07-14 14:44:29 +00:00
|
|
|
/** @var bool */
|
|
|
|
protected $isMainPageTalk;
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Start render the page in template
|
|
|
|
*/
|
|
|
|
public function execute() {
|
|
|
|
$title = $this->getSkin()->getTitle();
|
|
|
|
$this->isSpecialPage = $title->isSpecialPage();
|
|
|
|
$this->isSpecialMobileMenuPage = $this->isSpecialPage &&
|
2018-04-15 23:37:33 +00:00
|
|
|
$title->isSpecial( 'MobileMenu' );
|
2017-07-12 15:12:40 +00:00
|
|
|
$this->isMainPage = $title->isMainPage();
|
2019-02-19 23:44:53 +00:00
|
|
|
$this->isMainPageTalk = $title->getSubjectPage()->isMainPage();
|
2017-07-12 15:12:40 +00:00
|
|
|
Hooks::run( 'MinervaPreRender', [ $this ] );
|
|
|
|
$this->render( $this->data );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns available page actions
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-04-03 19:34:14 +00:00
|
|
|
protected function getPageActions() {
|
2017-07-12 15:12:40 +00:00
|
|
|
return $this->isFallbackEditor() ? [] : $this->data['page_actions'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ) {
|
2017-08-04 14:50:33 +00:00
|
|
|
if ( isset( $this->data[$link] ) && $data[$link] !== '' && $data[$link] !== false ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
$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.
|
2019-07-14 14:44:29 +00:00
|
|
|
'licensehtml' => $data['mobile-license'] ?? '',
|
2017-07-12 15:12:40 +00:00
|
|
|
'lists' => $groups,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the HTML for rendering the available page actions
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-02-25 19:50:56 +00:00
|
|
|
protected function getPageActionsHtml() {
|
2019-06-20 19:17:50 +00:00
|
|
|
$templateParser = new TemplateParser( __DIR__ . '/../../components' );
|
2019-04-04 21:20:39 +00:00
|
|
|
$pageActions = $this->getPageActions();
|
2017-07-12 15:12:40 +00:00
|
|
|
$html = '';
|
2019-02-25 19:50:56 +00:00
|
|
|
|
2019-04-04 21:20:39 +00:00
|
|
|
if ( $pageActions && $pageActions['toolbar'] ) {
|
2019-06-20 19:17:50 +00:00
|
|
|
$html = $templateParser->processTemplate( 'PageActionsMenu', $pageActions );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the 'Last edited' message, e.g. 'Last edited on...'
|
|
|
|
* @param array $data Data used to build the page
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getHistoryLinkHtml( $data ) {
|
|
|
|
$action = Action::getActionName( RequestContext::getMain() );
|
|
|
|
if ( isset( $data['historyLink'] ) && $action === 'view' ) {
|
|
|
|
$args = [
|
2019-03-21 14:50:23 +00:00
|
|
|
'clockIconClass' => MinervaUI::iconClass( 'clock', 'before' ),
|
2017-08-16 19:18:08 +00:00
|
|
|
'arrowIconClass' => MinervaUI::iconClass(
|
2018-01-05 18:52:17 +00:00
|
|
|
'arrow-gray', 'element', 'mw-ui-icon-small mf-mw-ui-icon-rotate-anti-clockwise indicator',
|
|
|
|
// Uses icon in MobileFrontend so must be prefixed mf.
|
|
|
|
// Without MobileFrontend it will not render.
|
|
|
|
// Rather than maintain 2 versions (and variants) of the arrow icon which can conflict
|
|
|
|
// with each othe and bloat CSS, we'll
|
|
|
|
// use the MobileFrontend one. Long term when T177432 and T160690 are resolved
|
|
|
|
// we should be able to use one icon definition and break this dependency.
|
|
|
|
'mf'
|
|
|
|
),
|
2017-11-22 18:55:24 +00:00
|
|
|
] + $data['historyLink'];
|
2017-07-12 15:12:40 +00:00
|
|
|
$templateParser = new TemplateParser( __DIR__ );
|
|
|
|
return $templateParser->processTemplate( 'history', $args );
|
|
|
|
}
|
2019-03-19 20:05:42 +00:00
|
|
|
|
|
|
|
return '';
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 17:17:38 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-07-12 15:12:40 +00:00
|
|
|
protected function isFallbackEditor() {
|
|
|
|
$action = $this->getSkin()->getRequest()->getVal( 'action' );
|
|
|
|
return $action === 'edit';
|
|
|
|
}
|
2017-10-05 17:17:38 +00:00
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Get page secondary actions
|
2019-07-14 14:44:29 +00:00
|
|
|
* @return array
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
protected function getSecondaryActions() {
|
|
|
|
if ( $this->isFallbackEditor() ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->data['secondary_actions'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get HTML representing secondary page actions like language selector
|
|
|
|
* @return string
|
2019-07-14 14:44:29 +00:00
|
|
|
* @suppress PhanTypeArraySuspiciousNullable,PhanTypeMismatchArgument The array shape of
|
|
|
|
* $el is too complicated, and not inferred correctly
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
protected function getSecondaryActionsHtml() {
|
2017-08-16 19:18:08 +00:00
|
|
|
$baseClass = MinervaUI::buttonClass( '', 'button' );
|
2019-03-19 20:05:42 +00:00
|
|
|
/** @var SkinMinerva $skin */
|
2017-07-12 15:12:40 +00:00
|
|
|
$skin = $this->getSkin();
|
2019-01-10 21:41:55 +00:00
|
|
|
$html = '';
|
2017-07-12 15:12:40 +00:00
|
|
|
// no secondary actions on the user page
|
|
|
|
if ( $skin instanceof SkinMinerva && !$skin->getUserPageHelper()->isUserPage() ) {
|
|
|
|
foreach ( $this->getSecondaryActions() as $el ) {
|
|
|
|
if ( isset( $el['attributes']['class'] ) ) {
|
|
|
|
$el['attributes']['class'] .= ' ' . $baseClass;
|
|
|
|
} else {
|
|
|
|
$el['attributes']['class'] = $baseClass;
|
|
|
|
}
|
|
|
|
$html .= Html::element( 'a', $el['attributes'], $el['label'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 21:41:55 +00:00
|
|
|
return $html;
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the HTML for the content of a page
|
|
|
|
* @param array $data Data used to build the page
|
|
|
|
* @return string representing HTML of content
|
|
|
|
*/
|
|
|
|
protected function getContentHtml( $data ) {
|
|
|
|
if ( !$data[ 'unstyledContent' ] ) {
|
|
|
|
$content = Html::openElement( 'div', [
|
|
|
|
'id' => 'bodyContent',
|
|
|
|
'class' => 'content',
|
|
|
|
] );
|
|
|
|
$content .= $data[ 'bodytext' ];
|
|
|
|
if ( isset( $data['subject-page'] ) ) {
|
|
|
|
$content .= $data['subject-page'];
|
|
|
|
}
|
|
|
|
return $content . Html::closeElement( 'div' );
|
|
|
|
}
|
2019-03-19 20:05:42 +00:00
|
|
|
|
|
|
|
return $data[ 'bodytext' ];
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the main menu only on Special:MobileMenu.
|
|
|
|
* On other pages the menu is rendered via JS.
|
2017-10-05 17:17:38 +00:00
|
|
|
* @param array $data Data used to build the page
|
2017-07-12 15:12:40 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getMainMenuHtml( $data ) {
|
|
|
|
if ( $this->isSpecialMobileMenuPage ) {
|
|
|
|
$templateParser = new TemplateParser(
|
2019-02-07 16:09:20 +00:00
|
|
|
__DIR__ . '/../../resources/skins.minerva.scripts/menu/' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-06-21 16:22:17 +00:00
|
|
|
return $templateParser->processTemplate( 'menu', $data['mainMenu']['items'] );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2019-03-19 20:05:42 +00:00
|
|
|
|
|
|
|
return '';
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the entire page
|
|
|
|
* @param array $data Data used to build the page
|
|
|
|
* @todo replace with template engines
|
|
|
|
*/
|
|
|
|
protected function render( $data ) {
|
2019-04-10 21:43:50 +00:00
|
|
|
$skinOptions = MediaWikiServices::getInstance()->getService( 'Minerva.SkinOptions' );
|
2017-07-12 15:12:40 +00:00
|
|
|
$templateParser = new TemplateParser( __DIR__ );
|
2019-04-10 21:43:50 +00:00
|
|
|
|
2019-01-10 21:41:55 +00:00
|
|
|
$internalBanner = $data[ 'internalBanner' ];
|
2019-07-14 14:44:29 +00:00
|
|
|
$preBodyHtml = $data['prebodyhtml'] ?? '';
|
2019-01-10 21:41:55 +00:00
|
|
|
$hasHeadingHolder = $internalBanner || $preBodyHtml || isset( $data['page_actions'] );
|
2019-05-31 17:14:48 +00:00
|
|
|
$hasPageActions = $this->hasPageActions( $data['skin']->getContext() );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
// prepare template data
|
|
|
|
$templateData = [
|
|
|
|
'banners' => $data['banners'],
|
|
|
|
'wgScript' => $data['wgScript'],
|
|
|
|
'isAnon' => $data['username'] === null,
|
|
|
|
'search' => $data['search'],
|
|
|
|
'placeholder' => wfMessage( 'mobile-frontend-placeholder' ),
|
|
|
|
'headelement' => $data[ 'headelement' ],
|
2019-06-21 16:22:17 +00:00
|
|
|
'menuButton' => $data['mainMenu']['buttonHTML'],
|
2019-01-10 21:41:55 +00:00
|
|
|
'siteheading' => $data['footer-site-heading-html'],
|
2019-03-19 20:05:42 +00:00
|
|
|
'mainPageURL' => Title::newMainPage()->getLocalURL(),
|
2017-07-12 15:12:40 +00:00
|
|
|
// A button when clicked will submit the form
|
|
|
|
// This is used so that on tablet devices with JS disabled the search button
|
|
|
|
// passes the value of input to the search
|
|
|
|
// We avoid using input[type=submit] as these cannot be easily styled as mediawiki ui icons
|
|
|
|
// which is problematic in Opera Mini (see T140490)
|
|
|
|
'searchButton' => Html::rawElement( 'button', [
|
|
|
|
'id' => 'searchIcon',
|
2018-03-09 18:12:04 +00:00
|
|
|
'class' => MinervaUI::iconClass( 'magnifying-glass', 'element', 'skin-minerva-search-trigger' ),
|
2017-07-12 15:12:40 +00:00
|
|
|
], wfMessage( 'searchbutton' ) ),
|
2019-06-19 17:31:16 +00:00
|
|
|
'userNotificationsData' => $data['userNotificationsData'],
|
2017-07-12 15:12:40 +00:00
|
|
|
'mainmenuhtml' => $this->getMainMenuHtml( $data ),
|
2019-01-10 21:41:55 +00:00
|
|
|
'hasheadingholder' => $hasHeadingHolder,
|
|
|
|
'taglinehtml' => $data['taglinehtml'],
|
|
|
|
'internalBanner' => $internalBanner,
|
|
|
|
'prebodyhtml' => $preBodyHtml,
|
2019-07-14 14:44:29 +00:00
|
|
|
'headinghtml' => $data['headinghtml'] ?? '',
|
|
|
|
'postheadinghtml' => $data['postheadinghtml'] ?? '',
|
2019-01-23 00:35:23 +00:00
|
|
|
'haspageactions' => $hasPageActions,
|
2019-04-19 12:36:02 +00:00
|
|
|
'pageactionshtml' => $hasPageActions ? $this->getPageActionsHtml() : '',
|
2019-01-10 21:41:55 +00:00
|
|
|
'subtitle' => $data['subtitle'],
|
|
|
|
'contenthtml' => $this->getContentHtml( $data ),
|
|
|
|
'secondaryactionshtml' => $this->getSecondaryActionsHtml(),
|
2019-06-20 01:47:54 +00:00
|
|
|
'dataAfterContent' => $this->get( 'dataAfterContent' ),
|
2017-07-12 15:12:40 +00:00
|
|
|
'footer' => $this->getFooterTemplateData( $data ),
|
2019-04-10 21:43:50 +00:00
|
|
|
'isBeta' => $skinOptions->get( SkinOptions::OPTIONS_MOBILE_BETA ),
|
2019-05-31 17:14:48 +00:00
|
|
|
'tabs' => $this->showTalkTabs( $hasPageActions, $skinOptions ) &&
|
|
|
|
$skinOptions->get( SkinOptions::OPTIONS_TALK_AT_TOP ) ? [
|
2019-01-10 22:59:56 +00:00
|
|
|
'items' => array_values( $data['content_navigation']['namespaces'] ),
|
|
|
|
] : false,
|
2017-07-12 15:12:40 +00:00
|
|
|
];
|
|
|
|
// begin rendering
|
|
|
|
echo $templateParser->processTemplate( 'minerva', $templateData );
|
|
|
|
$this->printTrail();
|
|
|
|
?>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
<?php
|
|
|
|
}
|
2019-05-31 17:14:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IContextSource $context
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function hasPageActions( IContextSource $context ) {
|
|
|
|
return !$this->isSpecialPage && !$this->isMainPage &&
|
|
|
|
Action::getActionName( $context ) === 'view';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $hasPageActions
|
|
|
|
* @param SkinOptions $skinOptions
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function showTalkTabs( $hasPageActions, SkinOptions $skinOptions ) {
|
|
|
|
$hasTalkTabs = $hasPageActions && !$this->isMainPageTalk;
|
|
|
|
if ( !$hasTalkTabs && $this->isSpecialPage &&
|
|
|
|
$skinOptions->get( SkinOptions::OPTION_TABS_ON_SPECIALS ) ) {
|
|
|
|
$hasTalkTabs = true;
|
|
|
|
}
|
|
|
|
return $hasTalkTabs;
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|