2020-06-17 02:56:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Citizen - A responsive skin developed for the Star Citizen Wiki
|
|
|
|
*
|
|
|
|
* This file is part of Citizen.
|
|
|
|
*
|
|
|
|
* Citizen 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Citizen 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 Citizen. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Skins
|
|
|
|
*/
|
|
|
|
|
2021-01-28 11:19:50 +00:00
|
|
|
use Citizen\GetConfigTrait;
|
|
|
|
use Citizen\Partials\Drawer;
|
|
|
|
use Citizen\Partials\Header;
|
|
|
|
use Citizen\Partials\Metadata;
|
|
|
|
use Citizen\Partials\Theme;
|
2020-08-10 03:06:38 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-08-09 18:26:31 +00:00
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
/**
|
2020-08-10 03:06:38 +00:00
|
|
|
* Skin subclass for Citizen
|
2020-06-17 02:56:40 +00:00
|
|
|
* @ingroup Skins
|
|
|
|
*/
|
2020-08-10 03:06:38 +00:00
|
|
|
class SkinCitizen extends SkinMustache {
|
2021-01-28 11:21:58 +00:00
|
|
|
use GetConfigTrait;
|
2021-01-28 11:19:50 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
/** @var array of alternate message keys for menu labels */
|
|
|
|
private const MENU_LABEL_KEYS = [
|
|
|
|
'tb' => 'toolbox',
|
|
|
|
'personal' => 'personaltools',
|
|
|
|
'lang' => 'otherlanguages',
|
|
|
|
];
|
2020-06-17 02:56:40 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-10 03:06:38 +00:00
|
|
|
* Overrides template, styles and scripts module
|
|
|
|
*
|
2020-08-09 18:26:31 +00:00
|
|
|
* @inheritDoc
|
2020-06-17 02:56:40 +00:00
|
|
|
*/
|
2020-08-10 03:06:38 +00:00
|
|
|
public function __construct( $options = [] ) {
|
|
|
|
$skin = $this;
|
|
|
|
$out = $skin->getOutput();
|
2020-08-09 18:26:31 +00:00
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
$metadata = new Metadata( $out );
|
|
|
|
$skinTheme = new Theme( $out );
|
2021-01-10 20:40:25 +00:00
|
|
|
|
2021-01-28 11:19:50 +00:00
|
|
|
$metadata->addMetadata();
|
2020-08-09 18:26:31 +00:00
|
|
|
|
2021-01-28 11:19:50 +00:00
|
|
|
// Theme handler
|
2021-01-28 11:21:58 +00:00
|
|
|
$skinTheme->setSkinTheme( $options );
|
2020-08-10 03:06:38 +00:00
|
|
|
|
2020-10-16 19:23:15 +00:00
|
|
|
// Load Citizen search suggestion styles if enabled
|
2020-08-10 03:06:38 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableSearch' ) === true ) {
|
2020-08-10 03:07:38 +00:00
|
|
|
$options['styles'] = array_merge(
|
2020-08-10 03:06:38 +00:00
|
|
|
$options['styles'],
|
2020-08-10 03:07:38 +00:00
|
|
|
[
|
2020-08-10 03:06:38 +00:00
|
|
|
'skins.citizen.styles.search',
|
|
|
|
'skins.citizen.icons.search'
|
|
|
|
]
|
2020-08-09 18:26:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
// Load Citizen image lazyload modules if enabled
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnableLazyload' ) === true ) {
|
2020-08-10 03:07:38 +00:00
|
|
|
$options['scripts'] = array_merge(
|
2020-08-10 03:06:38 +00:00
|
|
|
$options['scripts'],
|
|
|
|
[ 'skins.citizen.scripts.lazyload' ]
|
|
|
|
);
|
2020-08-10 03:07:38 +00:00
|
|
|
$options['styles'] = array_merge(
|
2020-08-10 03:06:38 +00:00
|
|
|
$options['styles'],
|
|
|
|
[ 'skins.citizen.styles.lazyload' ]
|
|
|
|
);
|
2020-08-09 18:26:31 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
// Load table of content script if ToC presents
|
2020-08-09 18:26:31 +00:00
|
|
|
if ( $out->isTOCEnabled() ) {
|
2021-01-18 20:18:39 +00:00
|
|
|
// Add class to body that notifies the page has TOC
|
|
|
|
$out->addBodyClasses( 'skin-citizen-has-toc' );
|
2020-08-10 03:06:38 +00:00
|
|
|
// Disabled style condition loading due to pop in
|
2020-08-10 03:07:38 +00:00
|
|
|
$options['scripts'] = array_merge(
|
2020-08-10 03:06:38 +00:00
|
|
|
$options['scripts'],
|
|
|
|
[ 'skins.citizen.scripts.toc' ]
|
|
|
|
);
|
2020-08-09 18:26:31 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
$options['templateDirectory'] = __DIR__ . '/templates';
|
|
|
|
parent::__construct( $options );
|
2020-08-09 18:26:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
/**
|
|
|
|
* @return array Returns an array of data used by Citizen skin.
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2020-08-10 03:06:38 +00:00
|
|
|
public function getTemplateData() : array {
|
2021-01-28 11:19:50 +00:00
|
|
|
$out = $this->getOutput();
|
2020-08-09 18:26:31 +00:00
|
|
|
$title = $out->getTitle();
|
|
|
|
|
2021-01-28 11:27:55 +00:00
|
|
|
$drawer = new Drawer( $this );
|
|
|
|
$header = new Header( $this );
|
2021-01-28 11:19:50 +00:00
|
|
|
|
2020-08-10 03:31:33 +00:00
|
|
|
// Naming conventions for Mustache parameters.
|
|
|
|
//
|
|
|
|
// Value type (first segment):
|
|
|
|
// - Prefix "is" or "has" for boolean values.
|
|
|
|
// - Prefix "msg-" for interface message text.
|
|
|
|
// - Prefix "html-" for raw HTML.
|
2020-08-10 03:06:38 +00:00
|
|
|
// - Prefix "data-" for an array of template parameters that should be passed directly
|
|
|
|
// to a template partial.
|
|
|
|
// - Prefix "array-" for lists of any values.
|
|
|
|
//
|
|
|
|
// Source of value (first or second segment)
|
|
|
|
// - Segment "page-" for data relating to the current page (e.g. Title, WikiPage, or OutputPage).
|
|
|
|
// - Segment "hook-" for any thing generated from a hook.
|
|
|
|
// It should be followed by the name of the hook in hyphenated lowercase.
|
|
|
|
//
|
|
|
|
// Conditionally used values must use null to indicate absence (not false or '').
|
2021-01-28 11:19:50 +00:00
|
|
|
$newTalksHtml = $this->getNewtalks() ?: null;
|
2020-08-10 03:06:38 +00:00
|
|
|
|
2021-01-28 11:19:50 +00:00
|
|
|
return parent::getTemplateData() + [
|
|
|
|
'msg-sitetitle' => $this->msg( 'sitetitle' )->text(),
|
2020-08-10 03:06:38 +00:00
|
|
|
'html-mainpage-attributes' => Xml::expandAttributes(
|
|
|
|
Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) + [
|
|
|
|
'href' => Skin::makeMainPageUrl(),
|
|
|
|
]
|
|
|
|
),
|
2021-01-28 11:27:55 +00:00
|
|
|
'data-logos' => $drawer->getLogoData(),
|
2020-08-10 03:06:38 +00:00
|
|
|
|
|
|
|
'data-header' => [
|
2021-01-28 11:27:55 +00:00
|
|
|
'data-drawer' => $drawer->buildDrawer(),
|
|
|
|
'data-extratools' => $header->getExtraTools(),
|
|
|
|
'data-personal-menu' => $header->buildPersonalMenu(),
|
|
|
|
'data-theme-toggle' => $header->buildThemeToggleProps(),
|
|
|
|
'data-search-box' => $header->buildSearchProps(),
|
2020-08-10 03:06:38 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
'data-pagetools' => $this->buildPageTools(),
|
|
|
|
|
|
|
|
'html-newtalk' => $newTalksHtml ? '<div class="usermessage">' . $newTalksHtml . '</div>' : '',
|
|
|
|
'page-langcode' => $title->getPageViewLanguage()->getHtmlCode(),
|
|
|
|
|
|
|
|
// Remember that the string '0' is a valid title.
|
|
|
|
// From OutputPage::getPageTitle, via ::setPageTitle().
|
|
|
|
'html-title' => $out->getPageTitle(),
|
|
|
|
|
2021-01-28 11:19:50 +00:00
|
|
|
'msg-tagline' => $this->msg( 'tagline' )->text(),
|
2020-08-10 03:06:38 +00:00
|
|
|
|
|
|
|
'data-pagelinks' => $this->buildPageLinks(),
|
|
|
|
|
2021-01-28 11:19:50 +00:00
|
|
|
'html-categories' => $this->getCategories(),
|
2020-08-10 03:06:38 +00:00
|
|
|
|
|
|
|
'data-footer' => $this->getFooterData(),
|
|
|
|
];
|
2021-01-19 20:56:42 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
/**
|
|
|
|
* Change access to public, as it is used in partials
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function buildPersonalUrls() {
|
|
|
|
return parent::buildPersonalUrls();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $label to be used to derive the id and human readable label of the menu
|
|
|
|
* If the key has an entry in the constant MENU_LABEL_KEYS then that message will be used for the
|
|
|
|
* human readable text instead.
|
|
|
|
* @param array $urls to convert to list items stored as string in html-items key
|
|
|
|
* @param array $options (optional) to be passed to makeListItem
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getMenuData(
|
|
|
|
string $label,
|
|
|
|
array $urls = [],
|
|
|
|
array $options = []
|
|
|
|
) : array {
|
|
|
|
$skin = $this->getSkin();
|
|
|
|
|
|
|
|
// For some menu items, there is no language key corresponding with its menu key.
|
|
|
|
// These inconsitencies are captured in MENU_LABEL_KEYS
|
|
|
|
$msgObj = $skin->msg( self::MENU_LABEL_KEYS[ $label ] ?? $label );
|
|
|
|
$props = [
|
|
|
|
'id' => "p-$label",
|
|
|
|
'label-class' => null,
|
|
|
|
'label-id' => "p-{$label}-label",
|
|
|
|
// If no message exists fallback to plain text (T252727)
|
|
|
|
'label' => $msgObj->exists() ? $msgObj->text() : $label,
|
|
|
|
'html-items' => '',
|
|
|
|
'html-tooltip' => Linker::tooltip( 'p-' . $label ),
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ( $urls as $key => $item ) {
|
|
|
|
$props['html-items'] .= $this->makeListItem( $key, $item, $options );
|
|
|
|
}
|
|
|
|
|
|
|
|
$props['html-after-portal'] = $this->getAfterPortlet( $label );
|
|
|
|
|
|
|
|
// Mark the portal as empty if it has no content
|
|
|
|
$class = ( empty( $urls ) && !$props['html-after-portal'] )
|
|
|
|
? ' mw-portal-empty' : '';
|
|
|
|
$props['class'] = $class;
|
|
|
|
return $props;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-27 21:53:01 +00:00
|
|
|
* @inheritDoc
|
|
|
|
*
|
|
|
|
* Manually disable links to upload and speacial pages
|
|
|
|
* as they are moved from the toolbox to the drawer
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function buildNavUrls() {
|
|
|
|
$urls = parent::buildNavUrls();
|
|
|
|
|
|
|
|
$urls['upload'] = false;
|
|
|
|
$urls['specialpages'] = false;
|
|
|
|
|
|
|
|
return $urls;
|
|
|
|
}
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
/**
|
2020-08-10 03:06:38 +00:00
|
|
|
* Render page-related tools
|
|
|
|
* Possible visibility conditions:
|
|
|
|
* * true: always visible (bool)
|
|
|
|
* * false: never visible (bool)
|
|
|
|
* * 'login': only visible if logged in (string)
|
|
|
|
* * 'permission-*': only visible if user has permission
|
|
|
|
* e.g. permission-edit = only visible if user can edit pages
|
2020-08-10 03:31:33 +00:00
|
|
|
*
|
2020-08-10 03:06:38 +00:00
|
|
|
* @return array html
|
|
|
|
*/
|
|
|
|
protected function buildPageTools(): array {
|
|
|
|
$skin = $this;
|
|
|
|
$condition = $this->getConfigValue( 'CitizenShowPageTools' );
|
2021-01-27 19:52:49 +00:00
|
|
|
$contentNavigation = parent::buildContentNavigationUrls();
|
|
|
|
$portals = parent::buildSidebar();
|
2020-08-10 03:06:38 +00:00
|
|
|
$props = [];
|
|
|
|
|
|
|
|
// Login-based condition, return true if condition is met
|
|
|
|
if ( $condition === 'login' ) {
|
|
|
|
$condition = $skin->getUser()->isLoggedIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Permission-based condition, return true if condition is met
|
|
|
|
if ( is_string( $condition ) && strpos( $condition, 'permission' ) === 0 ) {
|
|
|
|
$permission = substr( $condition, 11 );
|
|
|
|
try {
|
|
|
|
$condition = MediaWikiServices::getInstance()->getPermissionManager()->userCan(
|
|
|
|
$permission, $skin->getUser(), $skin->getTitle() );
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
$condition = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $condition === true ) {
|
|
|
|
|
2021-01-27 19:52:49 +00:00
|
|
|
$viewshtml = $this->getMenuData( 'views', $contentNavigation[ 'views' ] ?? [] );
|
|
|
|
$actionshtml = $this->getMenuData( 'actions', $contentNavigation[ 'actions' ] ?? [] );
|
|
|
|
$toolboxhtml = $this->getMenuData( 'tb', $portals['TOOLBOX'] ?? [] );
|
2020-08-10 03:06:38 +00:00
|
|
|
|
2021-01-27 19:52:49 +00:00
|
|
|
if ( $viewshtml ) {
|
|
|
|
$viewshtml[ 'label-class' ] .= 'screen-reader-text';
|
2020-08-10 03:06:38 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 19:52:49 +00:00
|
|
|
if ( $actionshtml ) {
|
|
|
|
$actionshtml[ 'label-class' ] .= 'screen-reader-text';
|
2020-08-10 03:06:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$props = [
|
2021-01-27 19:52:49 +00:00
|
|
|
'data-page-views' => $viewshtml,
|
|
|
|
'data-page-actions' => $actionshtml,
|
|
|
|
'data-page-toolbox' => $toolboxhtml,
|
2020-08-10 03:06:38 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $props;
|
|
|
|
}
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
/**
|
|
|
|
* Get rows that make up the footer
|
|
|
|
* @return array for use in Mustache template describing the footer elements.
|
|
|
|
*/
|
|
|
|
private function getFooterData() : array {
|
|
|
|
$skin = $this;
|
|
|
|
$footerLinks = $this->getFooterLinks();
|
|
|
|
$lastMod = null;
|
|
|
|
$footerRows = [];
|
|
|
|
$footerIconRows = [];
|
|
|
|
|
|
|
|
// Get last modified message
|
|
|
|
if ( $footerLinks['info']['lastmod'] && isset( $footerLinks['info']['lastmod'] ) ) {
|
|
|
|
$lastMod = $footerLinks['info']['lastmod'];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $footerLinks as $category => $links ) {
|
|
|
|
$items = [];
|
|
|
|
$rowId = "footer-$category";
|
|
|
|
|
|
|
|
// Unset footer-info
|
|
|
|
if ( $category !== 'info' ) {
|
|
|
|
foreach ( $links as $key => $link ) {
|
|
|
|
// Link may be null. If so don't include it.
|
|
|
|
if ( $link ) {
|
|
|
|
$items[] = [
|
|
|
|
'id' => "$rowId-$key",
|
|
|
|
'html' => $link,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$footerRows[] = [
|
|
|
|
'id' => $rowId,
|
|
|
|
'className' => null,
|
|
|
|
'array-items' => $items
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append footer-info after links
|
|
|
|
if ( isset( $footerLinks['info'] ) ) {
|
|
|
|
$items = [];
|
|
|
|
$rowId = "footer-info";
|
|
|
|
|
|
|
|
foreach ( $footerLinks['info'] as $key => $link ) {
|
|
|
|
// Don't include lastmod and null link
|
|
|
|
if ( $key !== 'lastmod' && $link ) {
|
|
|
|
$items[] = [
|
|
|
|
'id' => "$rowId-$key",
|
|
|
|
'html' => $link,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$footerRows[] = [
|
|
|
|
'id' => $rowId,
|
|
|
|
'className' => null,
|
|
|
|
'array-items' => $items
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// If footer icons are enabled append to the end of the rows
|
|
|
|
$footerIcons = $this->getFooterIcons();
|
|
|
|
if ( count( $footerIcons ) > 0 ) {
|
|
|
|
$items = [];
|
|
|
|
foreach ( $footerIcons as $blockName => $blockIcons ) {
|
|
|
|
$html = '';
|
|
|
|
foreach ( $blockIcons as $icon ) {
|
|
|
|
// Only output icons which have an image.
|
|
|
|
// For historic reasons this mimics the `icononly` option
|
|
|
|
// for BaseTemplate::getFooterIcons.
|
|
|
|
if ( is_string( $icon ) || isset( $icon['src'] ) ) {
|
|
|
|
$html .= $skin->makeFooterIcon( $icon );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// For historic reasons this mimics the `icononly` option
|
|
|
|
// for BaseTemplate::getFooterIcons. Empty rows should not be output.
|
|
|
|
if ( $html ) {
|
|
|
|
$items[] = [
|
|
|
|
'id' => 'footer-' . htmlspecialchars( $blockName ) . 'ico',
|
|
|
|
'html' => $html,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$footerIconRows[] = [
|
|
|
|
'id' => 'footer-icons',
|
|
|
|
'className' => 'noprint',
|
|
|
|
'array-items' => $items,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-01-28 11:27:55 +00:00
|
|
|
return [
|
2021-01-28 11:21:58 +00:00
|
|
|
'html-lastmodified' => $lastMod,
|
|
|
|
'array-footer-rows' => $footerRows,
|
|
|
|
'array-footer-icons' => $footerIconRows,
|
|
|
|
'msg-citizen-footer-desc' => $skin->msg( 'citizen-footer-desc' )->text(),
|
|
|
|
'msg-citizen-footer-tagline' => $skin->msg( 'citizen-footer-tagline' )->text(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-10 03:06:38 +00:00
|
|
|
* Render page-related links at the bottom
|
2020-08-10 03:31:33 +00:00
|
|
|
*
|
2020-08-10 03:06:38 +00:00
|
|
|
* @return array html
|
|
|
|
*/
|
|
|
|
private function buildPageLinks() : array {
|
|
|
|
$contentNavigation = $this->buildContentNavigationUrls();
|
|
|
|
|
|
|
|
$namespaceshtml = $this->getMenuData( 'namespaces', $contentNavigation[ 'namespaces' ] ?? [] );
|
|
|
|
$variantshtml = $this->getMenuData( 'variants', $contentNavigation[ 'variants' ] ?? [] );
|
|
|
|
|
|
|
|
if ( $namespaceshtml ) {
|
|
|
|
$namespaceshtml[ 'label-class' ] .= 'screen-reader-text';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $variantshtml ) {
|
|
|
|
$variantshtml[ 'label-class' ] .= 'screen-reader-text';
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'data-namespaces' => $namespaceshtml,
|
|
|
|
'data-variants' => $variantshtml,
|
|
|
|
];
|
|
|
|
}
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|