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
|
|
|
|
*/
|
|
|
|
|
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 {
|
|
|
|
/** @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-10 20:40:25 +00:00
|
|
|
// Theme handler
|
2021-01-11 18:31:49 +00:00
|
|
|
$skin->setSkinTheme( $out, $options );
|
2021-01-10 20:40:25 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
// Responsive layout
|
|
|
|
// Replace with core responsive option if it is implemented in 1.36+
|
|
|
|
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1.0' );
|
2020-08-09 18:26:31 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
// Theme color
|
|
|
|
$out->addMeta( 'theme-color', $this->getConfigValue( 'CitizenThemeColor' ) ?? '' );
|
|
|
|
|
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
|
|
|
// Generate webapp manifest
|
|
|
|
$skin->addManifest();
|
|
|
|
|
|
|
|
// Preconnect origin
|
|
|
|
$skin->addPreConnect();
|
|
|
|
|
|
|
|
// HTTP headers
|
|
|
|
// CSP
|
|
|
|
$skin->addCSP();
|
|
|
|
|
|
|
|
// HSTS
|
|
|
|
$skin->addHSTS();
|
|
|
|
|
|
|
|
// Deny X-Frame-Options
|
|
|
|
$skin->addXFrameOptions();
|
|
|
|
|
|
|
|
// X-XSS-Protection
|
|
|
|
$skin->addXXSSProtection();
|
|
|
|
|
|
|
|
// Referrer policy
|
|
|
|
$skin->addStrictReferrerPolicy();
|
|
|
|
|
|
|
|
// Feature policy
|
|
|
|
$skin->addFeaturePolicy();
|
|
|
|
|
|
|
|
$options['templateDirectory'] = __DIR__ . '/templates';
|
|
|
|
parent::__construct( $options );
|
2020-08-09 18:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-10 03:06:38 +00:00
|
|
|
* @return array Returns an array of data used by Citizen skin.
|
2020-08-09 18:26:31 +00:00
|
|
|
*/
|
2020-08-10 03:06:38 +00:00
|
|
|
public function getTemplateData() : array {
|
|
|
|
$skin = $this;
|
|
|
|
$out = $skin->getOutput();
|
2020-08-09 18:26:31 +00:00
|
|
|
$title = $out->getTitle();
|
|
|
|
|
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 '').
|
|
|
|
$newTalksHtml = $skin->getNewtalks() ?: null;
|
|
|
|
|
|
|
|
$skinData = parent::getTemplateData() + [
|
|
|
|
'msg-sitetitle' => $skin->msg( 'sitetitle' )->text(),
|
|
|
|
'html-mainpage-attributes' => Xml::expandAttributes(
|
|
|
|
Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) + [
|
|
|
|
'href' => Skin::makeMainPageUrl(),
|
|
|
|
]
|
|
|
|
),
|
2021-01-19 16:46:17 +00:00
|
|
|
'data-logos' => $this->getLogoData(),
|
2020-08-10 03:06:38 +00:00
|
|
|
|
|
|
|
'data-header' => [
|
|
|
|
'data-drawer' => $this->buildDrawer(),
|
|
|
|
'data-extratools' => $this->getExtraTools(),
|
2021-01-19 20:56:42 +00:00
|
|
|
'data-personal-menu' => $this->buildPersonalMenu(),
|
2021-01-11 17:13:59 +00:00
|
|
|
'data-theme-toggle' => $this->buildThemeToggleProps(),
|
2021-01-19 20:56:42 +00:00
|
|
|
'data-search-box' => $this->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(),
|
|
|
|
|
|
|
|
'msg-tagline' => $skin->msg( 'tagline' )->text(),
|
|
|
|
|
|
|
|
'data-pagelinks' => $this->buildPageLinks(),
|
|
|
|
|
|
|
|
'html-categories' => $skin->getCategories(),
|
|
|
|
|
|
|
|
'data-footer' => $this->getFooterData(),
|
|
|
|
];
|
|
|
|
|
|
|
|
return $skinData;
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:31:33 +00:00
|
|
|
/**
|
|
|
|
* Get rows that make up the footer
|
|
|
|
* @return array for use in Mustache template describing the footer elements.
|
|
|
|
*/
|
2020-08-10 03:06:38 +00:00
|
|
|
private function getFooterData() : array {
|
|
|
|
$skin = $this;
|
|
|
|
$footerLinks = $this->getFooterLinks();
|
|
|
|
$lastMod = null;
|
|
|
|
$footerRows = [];
|
|
|
|
$footerIconRows = [];
|
|
|
|
|
|
|
|
// Get last modified message
|
2020-08-10 03:22:52 +00:00
|
|
|
if ( $footerLinks['info']['lastmod'] && isset( $footerLinks['info']['lastmod'] ) ) {
|
2020-08-10 03:06:38 +00:00
|
|
|
$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,
|
2020-08-09 18:26:31 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
$data = [
|
|
|
|
'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(),
|
|
|
|
];
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2021-01-19 16:46:17 +00:00
|
|
|
/**
|
|
|
|
* Get and pick the correct logo based on types and variants
|
|
|
|
* Based on getLogoData() in MW 1.36
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getLogoData() : array {
|
|
|
|
$logoData = ResourceLoaderSkinModule::getAvailableLogos( $this->getConfig() );
|
|
|
|
// check if the logo supports variants
|
|
|
|
$variantsLogos = $logoData['variants'] ?? null;
|
|
|
|
if ( $variantsLogos ) {
|
|
|
|
$preferred = $this->getOutput()->getTitle()
|
|
|
|
->getPageViewLanguage()->getCode();
|
|
|
|
$variantOverrides = $variantsLogos[$preferred] ?? null;
|
|
|
|
// Overrides the logo
|
|
|
|
if ( $variantOverrides ) {
|
|
|
|
foreach ( $variantOverrides as $key => $val ) {
|
|
|
|
$logoData[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $logoData;
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
/**
|
|
|
|
* Render the navigation drawer
|
2020-08-10 03:31:33 +00:00
|
|
|
* Based on buildSidebar()
|
|
|
|
*
|
2020-08-10 03:06:38 +00:00
|
|
|
* @return array
|
|
|
|
* @throws MWException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function buildDrawer() {
|
|
|
|
$skin = $this;
|
|
|
|
$portals = parent::buildSidebar();
|
|
|
|
$props = [];
|
|
|
|
$languages = null;
|
|
|
|
|
|
|
|
// Render portals
|
|
|
|
foreach ( $portals as $name => $content ) {
|
|
|
|
if ( $content === false ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Numeric strings gets an integer when set as key, cast back - T73639
|
|
|
|
$name = (string)$name;
|
|
|
|
|
|
|
|
switch ( $name ) {
|
|
|
|
case 'SEARCH':
|
|
|
|
case 'TOOLBOX':
|
|
|
|
break;
|
|
|
|
case 'LANGUAGES':
|
|
|
|
$languages = $skin->getLanguages();
|
|
|
|
$portal = $this->getMenuData( 'lang', $content );
|
|
|
|
// The language portal will be added provided either
|
|
|
|
// languages exist or there is a value in html-after-portal
|
|
|
|
// for example to show the add language wikidata link (T252800)
|
|
|
|
if ( count( $content ) || $portal['html-after-portal'] ) {
|
|
|
|
$languages = $portal;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Historically some portals have been defined using HTML rather than arrays.
|
|
|
|
// Let's move away from that to a uniform definition.
|
|
|
|
if ( !is_array( $content ) ) {
|
|
|
|
$html = $content;
|
|
|
|
$content = [];
|
|
|
|
wfDeprecated(
|
|
|
|
"`content` field in portal $name must be array."
|
|
|
|
. "Previously it could be a string but this is no longer supported.",
|
|
|
|
'1.35.0'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$html = false;
|
|
|
|
}
|
|
|
|
$portal = $this->getMenuData( $name, $content );
|
|
|
|
if ( $html ) {
|
|
|
|
$portal['html-items'] .= $html;
|
|
|
|
}
|
|
|
|
$props[] = $portal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$firstPortal = $props[0] ?? null;
|
2021-01-27 21:53:01 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
if ( $firstPortal ) {
|
|
|
|
$firstPortal[ 'class' ] .= ' portal-first';
|
|
|
|
// Hide label for first portal
|
|
|
|
$firstPortal[ 'label-class' ] .= 'screen-reader-text';
|
2021-01-27 21:53:01 +00:00
|
|
|
|
|
|
|
if ( isset( $firstPortal['html-items'] ) ) {
|
|
|
|
$this->addToolboxLinksToDrawer( $firstPortal['html-items'] );
|
|
|
|
}
|
2020-08-10 03:06:38 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 20:56:42 +00:00
|
|
|
return [
|
|
|
|
'msg-citizen-drawer-toggle' => $skin->msg( 'citizen-drawer-toggle' )->text(),
|
|
|
|
'data-portals-first' => $firstPortal,
|
|
|
|
'array-portals-rest' => array_slice( $props, 1 ),
|
|
|
|
'data-portals-languages' => $languages,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a link to special pages and the upload form to the first portal in the drawer
|
|
|
|
*
|
|
|
|
* @param string &$htmlItems
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function addToolboxLinksToDrawer( &$htmlItems ) {
|
|
|
|
// First add a link to special pages
|
|
|
|
$htmlItems .= $this->makeListItem( 'specialpages', [
|
|
|
|
'href' => self::makeSpecialUrl( 'specialpages' ),
|
|
|
|
'id' => 't-specialpages'
|
|
|
|
] );
|
|
|
|
|
|
|
|
// Then add a link to the upload form
|
|
|
|
$htmlItems .= $this->makeListItem( 'upload', [
|
|
|
|
'href' => self::makeSpecialUrl( 'upload' ),
|
|
|
|
'id' => 't-upload'
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
2021-01-19 20:56:42 +00:00
|
|
|
/**
|
|
|
|
* Build Personal Tools menu
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function buildPersonalMenu(): array {
|
|
|
|
$skin = $this;
|
2021-01-13 09:22:19 +00:00
|
|
|
$personalTools = $this->getPersonalToolsForMakeListItem(
|
2020-08-10 03:06:38 +00:00
|
|
|
$this->buildPersonalUrls()
|
2020-08-09 18:26:31 +00:00
|
|
|
);
|
2021-01-22 00:16:21 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
// Move the Echo badges and ULS out of default list
|
|
|
|
if ( isset( $personalTools['notifications-alert'] ) ) {
|
|
|
|
unset( $personalTools['notifications-alert'] );
|
|
|
|
}
|
|
|
|
if ( isset( $personalTools['notifications-notice'] ) ) {
|
|
|
|
unset( $personalTools['notifications-notice'] );
|
|
|
|
}
|
|
|
|
if ( isset( $personalTools['uls'] ) ) {
|
|
|
|
unset( $personalTools['uls'] );
|
|
|
|
}
|
|
|
|
|
2021-01-22 00:16:21 +00:00
|
|
|
if ( $this->getUser()->isLoggedIn() ) {
|
|
|
|
$personalTools = $this->addUserGroupsToMenu( $personalTools );
|
|
|
|
}
|
|
|
|
|
2021-01-19 20:56:42 +00:00
|
|
|
$personalMenu = $this->getMenuData( 'personal', $personalTools );
|
2020-08-10 03:06:38 +00:00
|
|
|
// Hide label for personal tools
|
2021-01-19 20:56:42 +00:00
|
|
|
$personalMenu[ 'label-class' ] .= 'screen-reader-text';
|
2020-08-09 18:26:31 +00:00
|
|
|
|
|
|
|
return [
|
2021-01-19 20:56:42 +00:00
|
|
|
'msg-citizen-personalmenu-toggle' => $skin->msg( 'citizen-personalmenu-toggle' )->text(),
|
|
|
|
'data-personal-menu-list' => $personalMenu,
|
2020-08-09 18:26:31 +00:00
|
|
|
];
|
|
|
|
}
|
2020-06-17 02:56:40 +00:00
|
|
|
|
2021-01-22 00:16:21 +00:00
|
|
|
/**
|
|
|
|
* This adds all explicit user groups as links to the personal menu
|
|
|
|
* Links are added right below the user page link
|
|
|
|
* Wrapped in an <li> element with id 'pt-usergroups'
|
|
|
|
*
|
|
|
|
* @param array $originalUrls The original personal tools urls
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function addUserGroupsToMenu( $originalUrls ) {
|
|
|
|
$personalTools = [];
|
|
|
|
|
|
|
|
// This does not return implicit groups
|
|
|
|
$groups = MediaWikiServices::getInstance()->getUserGroupManager()->getUserGroups( $this->getUser() );
|
|
|
|
|
|
|
|
// If the user has only implicit groups return early
|
|
|
|
if ( empty( $groups ) ) {
|
|
|
|
return $originalUrls;
|
|
|
|
}
|
|
|
|
|
2021-01-26 20:55:46 +00:00
|
|
|
$userPage = array_shift( $originalUrls );
|
2021-01-22 00:16:21 +00:00
|
|
|
$groupLinks = [];
|
|
|
|
$msgName = 'group-%s';
|
|
|
|
|
|
|
|
foreach ( $groups as $group ) {
|
|
|
|
$groupPage = Title::newFromText(
|
|
|
|
$this->msg( sprintf( $msgName, $group ) )->text(),
|
|
|
|
NS_PROJECT
|
|
|
|
);
|
|
|
|
|
|
|
|
$groupLinks[$group] = [
|
|
|
|
'msg' => sprintf( $msgName, $group ),
|
|
|
|
'href' => $groupPage->getLinkURL(), // Nullpointer should not happen
|
|
|
|
'tooltiponly' => true,
|
|
|
|
'id' => sprintf( $msgName, $group ),
|
|
|
|
// 'exists' => $groupPage->exists() - This will add an additional DB call
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$userGroups = [
|
|
|
|
'id' => 'pt-usergroups',
|
|
|
|
'links' => $groupLinks
|
|
|
|
];
|
|
|
|
|
|
|
|
// The following defines the order of links added
|
|
|
|
$personalTools['userpage'] = $userPage;
|
|
|
|
$personalTools['usergroups'] = $userGroups;
|
|
|
|
|
|
|
|
foreach ( $originalUrls as $key => $url ) {
|
|
|
|
$personalTools[$key] = $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $personalTools;
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
/**
|
|
|
|
* Echo notification badges and ULS button
|
2020-08-10 03:31:33 +00:00
|
|
|
*
|
2020-08-10 03:06:38 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getExtratools(): array {
|
2021-01-22 00:16:21 +00:00
|
|
|
$personalTools = $this->getPersonalToolsForMakeListItem(
|
2020-08-10 03:06:38 +00:00
|
|
|
$this->buildPersonalUrls()
|
|
|
|
);
|
2020-06-17 02:56:40 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
// Create the Echo badges and ULS
|
|
|
|
$extraTools = [];
|
|
|
|
if ( isset( $personalTools['notifications-alert'] ) ) {
|
|
|
|
$extraTools['notifications-alert'] = $personalTools['notifications-alert'];
|
|
|
|
}
|
|
|
|
if ( isset( $personalTools['notifications-notice'] ) ) {
|
|
|
|
$extraTools['notifications-notice'] = $personalTools['notifications-notice'];
|
|
|
|
}
|
|
|
|
if ( isset( $personalTools['uls'] ) ) {
|
|
|
|
$extraTools['uls'] = $personalTools['uls'];
|
|
|
|
}
|
2020-06-17 02:56:40 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
$html = $this->getMenuData( 'personal-extra', $extraTools );
|
2020-06-17 02:56:40 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
// Hide label for extra tools
|
|
|
|
$html[ 'label-class' ] .= 'screen-reader-text';
|
2020-06-17 02:56:40 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
return $html;
|
|
|
|
}
|
2020-06-17 02:56:40 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
/**
|
|
|
|
* Render the search box
|
2020-08-10 03:31:33 +00:00
|
|
|
*
|
2020-08-10 03:06:38 +00:00
|
|
|
* @return array
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
private function buildSearchProps() : array {
|
|
|
|
$skin = $this->getSkin();
|
2020-06-17 02:56:40 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
$toggleMsg = $skin->msg( 'citizen-search-toggle' )->text();
|
|
|
|
$accessKey = Linker::accesskey( 'search' );
|
2020-06-17 02:56:40 +00:00
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
return [
|
|
|
|
'msg-citizen-search-toggle' => $toggleMsg,
|
|
|
|
'msg-citizen-search-toggle-shortcut' => $toggleMsg . ' [alt-shift-' . $accessKey . ']',
|
|
|
|
'form-action' => $this->getConfigValue( 'Script' ),
|
|
|
|
'html-input' => $this->makeSearchInput( [ 'id' => 'searchInput' ] ),
|
|
|
|
'msg-search' => $skin->msg( 'search' ),
|
|
|
|
'page-title' => SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey(),
|
|
|
|
'html-random-href' => Skin::makeSpecialUrl( 'Randompage' ),
|
|
|
|
'msg-random' => $skin->msg( 'Randompage' )->text(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-01-11 17:13:59 +00:00
|
|
|
/**
|
|
|
|
* Render the theme toggle
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
private function buildThemeToggleProps() : array {
|
|
|
|
$skin = $this->getSkin();
|
|
|
|
|
|
|
|
$toggleMsg = $skin->msg( 'citizen-theme-toggle' )->text();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'msg-citizen-theme-toggle-shortcut' => $toggleMsg,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
private 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
|
2021-01-22 00:16:21 +00:00
|
|
|
$class = ( empty( $urls ) && !$props['html-after-portal'] )
|
2020-08-10 03:06:38 +00:00
|
|
|
? ' mw-portal-empty' : '';
|
|
|
|
$props['class'] = $class;
|
|
|
|
return $props;
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getConfig() wrapper to catch exceptions.
|
|
|
|
* Returns null on exception
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @return mixed|null
|
|
|
|
* @see SkinTemplate::getConfig()
|
|
|
|
*/
|
|
|
|
private function getConfigValue( $key ) {
|
|
|
|
try {
|
|
|
|
$value = $this->getConfig()->get( $key );
|
|
|
|
} catch ( ConfigException $e ) {
|
|
|
|
$value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the manifest if enabled in 'CitizenEnableManifest'.
|
|
|
|
* Manifest link will be empty if wfExpandUrl throws an exception.
|
|
|
|
*/
|
|
|
|
private function addManifest() {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableManifest' ) === true ) {
|
|
|
|
try {
|
|
|
|
$href =
|
|
|
|
wfExpandUrl( wfAppendQuery( wfScript( 'api' ),
|
|
|
|
[ 'action' => 'webapp-manifest' ] ), PROTO_RELATIVE );
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
$href = '';
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
$out->addLink( [
|
2020-06-17 02:56:40 +00:00
|
|
|
'rel' => 'manifest',
|
|
|
|
'href' => $href,
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
/**
|
|
|
|
* Adds a preconnect header if enabled in 'CitizenEnablePreconnect'
|
|
|
|
*/
|
|
|
|
private function addPreConnect() {
|
|
|
|
$out = $this->getOutput();
|
|
|
|
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnablePreconnect' ) === true ) {
|
|
|
|
$out->addLink( [
|
|
|
|
'rel' => 'preconnect',
|
|
|
|
'href' => $this->getConfigValue( 'CitizenPreconnectURL' ),
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
/**
|
|
|
|
* Adds the csp directive if enabled in 'CitizenEnableCSP'.
|
|
|
|
* Directive holds the content of 'CitizenCSPDirective'.
|
|
|
|
*/
|
|
|
|
private function addCSP() {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableCSP' ) === true ) {
|
|
|
|
|
|
|
|
$cspDirective = $this->getConfigValue( 'CitizenCSPDirective' ) ?? '';
|
|
|
|
$cspMode = 'Content-Security-Policy';
|
|
|
|
|
|
|
|
// Check if report mode is enabled
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnableCSPReportMode' ) === true ) {
|
|
|
|
$cspMode = 'Content-Security-Policy-Report-Only';
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
$out->getRequest()->response()->header( sprintf( '%s: %s', $cspMode,
|
2020-06-17 02:56:40 +00:00
|
|
|
$cspDirective ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the HSTS Header. If no max age or an invalid max age is set a default of 300 will be
|
|
|
|
* applied.
|
|
|
|
* Preload and Include Subdomains can be enabled by setting 'CitizenHSTSIncludeSubdomains'
|
|
|
|
* and/or 'CitizenHSTSPreload' to true.
|
|
|
|
*/
|
|
|
|
private function addHSTS() {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableHSTS' ) === true ) {
|
|
|
|
|
|
|
|
$maxAge = $this->getConfigValue( 'CitizenHSTSMaxAge' );
|
|
|
|
$includeSubdomains = $this->getConfigValue( 'CitizenHSTSIncludeSubdomains' ) ?? false;
|
|
|
|
$preload = $this->getConfigValue( 'CitizenHSTSPreload' ) ?? false;
|
|
|
|
|
|
|
|
// HSTS max age
|
|
|
|
if ( is_int( $maxAge ) ) {
|
|
|
|
$maxAge = max( $maxAge, 0 );
|
|
|
|
} else {
|
|
|
|
// Default to 5 mins if input is invalid
|
|
|
|
$maxAge = 300;
|
|
|
|
}
|
|
|
|
|
|
|
|
$hstsHeader = 'Strict-Transport-Security: max-age=' . $maxAge;
|
|
|
|
|
|
|
|
if ( $includeSubdomains ) {
|
|
|
|
$hstsHeader .= '; includeSubDomains';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $preload ) {
|
|
|
|
$hstsHeader .= '; preload';
|
|
|
|
}
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
$out->getRequest()->response()->header( $hstsHeader );
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the X-Frame-Options header if set in 'CitizenEnableDenyXFrameOptions'
|
|
|
|
*/
|
|
|
|
private function addXFrameOptions() {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableDenyXFrameOptions' ) === true ) {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out->getRequest()->response()->header( 'X-Frame-Options: deny' );
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the X-XSS-Protection header if set in 'CitizenEnableXXSSProtection'
|
|
|
|
*/
|
|
|
|
private function addXXSSProtection() {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableXXSSProtection' ) === true ) {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out->getRequest()->response()->header( 'X-XSS-Protection: 1; mode=block' );
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the referrer header if enabled in 'CitizenEnableStrictReferrerPolicy'
|
|
|
|
*/
|
|
|
|
private function addStrictReferrerPolicy() {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableStrictReferrerPolicy' ) === true ) {
|
|
|
|
// iOS Safari, IE, Edge compatiblity
|
2020-08-10 03:06:38 +00:00
|
|
|
$out->getRequest()->response()->header( 'Referrer-Policy: strict-origin' );
|
|
|
|
$out->getRequest()->response()->header( 'Referrer-Policy: strict-origin-when-cross-origin' );
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the Feature policy header to the response if enabled in 'CitizenFeaturePolicyDirective'
|
|
|
|
*/
|
|
|
|
private function addFeaturePolicy() {
|
2020-08-10 03:06:38 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
2020-06-17 02:56:40 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableFeaturePolicy' ) === true ) {
|
|
|
|
|
|
|
|
$featurePolicy = $this->getConfigValue( 'CitizenFeaturePolicyDirective' ) ?? '';
|
|
|
|
|
2020-08-10 03:06:38 +00:00
|
|
|
$out->getRequest()->response()->header( sprintf( 'Feature-Policy: %s',
|
2020-06-17 02:56:40 +00:00
|
|
|
$featurePolicy ) );
|
|
|
|
}
|
|
|
|
}
|
2021-01-09 21:58:43 +00:00
|
|
|
|
2021-01-09 22:15:47 +00:00
|
|
|
/**
|
2021-01-10 20:40:25 +00:00
|
|
|
* Sets the corresponding theme class on the <html> element
|
|
|
|
* If the theme is set to auto, the theme switcher script will be added
|
2021-01-09 22:15:47 +00:00
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
2021-01-11 18:47:47 +00:00
|
|
|
* @param array &$options
|
2021-01-09 22:15:47 +00:00
|
|
|
*/
|
2021-01-11 18:31:49 +00:00
|
|
|
private function setSkinTheme( OutputPage $out, array &$options ) {
|
2021-01-10 20:40:25 +00:00
|
|
|
// Set theme to site theme
|
2021-01-11 17:13:59 +00:00
|
|
|
$theme = $this->getConfigValue( 'CitizenThemeDefault' ) ?? 'auto';
|
2021-01-09 22:15:47 +00:00
|
|
|
|
2021-01-10 20:40:25 +00:00
|
|
|
// Set theme to user theme if registered
|
|
|
|
if ( $this->getUser()->isRegistered() ) {
|
2021-01-11 17:13:59 +00:00
|
|
|
$theme = MediaWikiServices::getInstance()->getUserOptionsLookup()->getOption(
|
|
|
|
$this->getUser(),
|
|
|
|
'CitizenThemeUser',
|
|
|
|
'auto'
|
|
|
|
);
|
2021-01-10 20:40:25 +00:00
|
|
|
}
|
2021-01-09 22:15:47 +00:00
|
|
|
|
2021-01-13 08:38:26 +00:00
|
|
|
$cookieTheme = $this->getRequest()->getCookie( 'skin-citizen-theme', null, 'auto' );
|
|
|
|
if ( $cookieTheme !== 'auto' ) {
|
2021-01-13 08:39:35 +00:00
|
|
|
$theme = $cookieTheme;
|
|
|
|
}
|
2021-01-13 08:38:26 +00:00
|
|
|
|
2021-01-10 20:40:25 +00:00
|
|
|
// Add HTML class based on theme set
|
|
|
|
$out->addHtmlClasses( 'skin-citizen-' . $theme );
|
2021-01-11 17:17:37 +00:00
|
|
|
if ( $this->getRequest()->getCookie( 'skin-citizen-theme-override' ) === null ) {
|
2021-01-11 17:13:59 +00:00
|
|
|
// Only set the theme cookie if the theme wasn't overridden by the user through the button
|
2021-01-11 17:17:37 +00:00
|
|
|
$this->getRequest()->response()->setCookie( 'skin-citizen-theme', $theme, 0, [
|
2021-01-11 17:13:59 +00:00
|
|
|
'httpOnly' => false,
|
2021-01-11 17:17:37 +00:00
|
|
|
] );
|
2021-01-09 22:15:47 +00:00
|
|
|
}
|
2021-01-11 17:13:59 +00:00
|
|
|
|
2021-01-11 18:12:49 +00:00
|
|
|
// Script content at 'skins.citizen.scripts.theme/inline.js
|
2021-01-12 01:12:14 +00:00
|
|
|
$this->getOutput()->addHeadItem( 'theme-switcher', '<script>window.switchTheme=(()=>{try{const t=document.cookie.match(/skin-citizen-theme=(dark|light|auto)/),e=null!==t?t.pop():null;null!==e&&(document.documentElement.classList.remove(...["auto","dark","light"].map(t=>"skin-citizen-"+t)),document.documentElement.classList.add("skin-citizen-"+e))}catch(t){}}),window.switchTheme();</script>' );
|
2021-01-11 18:31:49 +00:00
|
|
|
|
|
|
|
// Add styles and scripts module
|
2021-01-12 01:12:14 +00:00
|
|
|
if ( $theme === 'auto' ) {
|
|
|
|
$options['scripts'] = array_merge(
|
|
|
|
$options['scripts'],
|
|
|
|
[ 'skins.citizen.scripts.theme' ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-11 18:31:49 +00:00
|
|
|
$options['styles'] = array_merge(
|
|
|
|
$options['styles'],
|
|
|
|
[ 'skins.citizen.styles.theme' ]
|
|
|
|
);
|
2021-01-09 22:15:47 +00:00
|
|
|
}
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|