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;
|
2021-03-02 22:16:24 +00:00
|
|
|
use Citizen\Partials\BodyContent;
|
2021-01-28 11:19:50 +00:00
|
|
|
use Citizen\Partials\Drawer;
|
2022-05-07 04:45:51 +00:00
|
|
|
use Citizen\Partials\FirstHeading;
|
2021-01-28 19:35:31 +00:00
|
|
|
use Citizen\Partials\Footer;
|
2021-01-28 11:19:50 +00:00
|
|
|
use Citizen\Partials\Header;
|
2021-03-04 20:08:32 +00:00
|
|
|
use Citizen\Partials\Logos;
|
2021-01-28 11:19:50 +00:00
|
|
|
use Citizen\Partials\Metadata;
|
2021-01-28 19:35:31 +00:00
|
|
|
use Citizen\Partials\PageTools;
|
2021-03-16 17:10:54 +00:00
|
|
|
use Citizen\Partials\Tagline;
|
2021-01-28 11:19:50 +00:00
|
|
|
use Citizen\Partials\Theme;
|
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
|
|
|
|
2022-02-09 17:00:45 +00:00
|
|
|
/**
|
|
|
|
* @var array|null
|
|
|
|
*/
|
|
|
|
private $contentNavigationUrls;
|
|
|
|
|
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 = [] ) {
|
2021-04-09 17:08:01 +00:00
|
|
|
// Add skin-specific features
|
|
|
|
$this->buildSkinFeatures( $options );
|
2021-03-18 16:35:18 +00:00
|
|
|
|
2021-04-09 15:48:47 +00:00
|
|
|
$options['templateDirectory'] = dirname( __DIR__, 1 ) . '/templates';
|
2020-08-10 03:06:38 +00:00
|
|
|
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
|
|
|
|
*/
|
2021-07-30 02:49:01 +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();
|
2022-04-14 04:30:33 +00:00
|
|
|
$parentData = parent::getTemplateData();
|
2020-08-09 18:26:31 +00:00
|
|
|
|
2021-01-28 11:27:55 +00:00
|
|
|
$header = new Header( $this );
|
2021-03-04 20:08:32 +00:00
|
|
|
$logos = new Logos( $this );
|
2021-01-28 19:35:31 +00:00
|
|
|
$drawer = new Drawer( $this );
|
2022-05-07 04:45:51 +00:00
|
|
|
$firstHeading = new FirstHeading( $this );
|
2021-03-16 17:10:54 +00:00
|
|
|
$tagline = new Tagline( $this );
|
2021-03-02 22:16:24 +00:00
|
|
|
$bodycontent = new BodyContent( $this );
|
2021-01-28 19:35:31 +00:00
|
|
|
$footer = new Footer( $this );
|
|
|
|
$tools = new PageTools( $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
|
|
|
|
2022-04-14 04:30:33 +00:00
|
|
|
return $parentData + [
|
2022-05-12 21:01:01 +00:00
|
|
|
'toc-enabled' => $out->isTOCEnabled(),
|
2021-01-28 11:19:50 +00:00
|
|
|
'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-03-04 20:08:32 +00:00
|
|
|
'data-logos' => $logos->getLogoData(),
|
2020-08-10 03:06:38 +00:00
|
|
|
|
|
|
|
'data-header' => [
|
2022-05-16 01:37:39 +00:00
|
|
|
'data-drawer' => $drawer->getDrawerTemplateData(),
|
2021-01-28 11:27:55 +00:00
|
|
|
'data-extratools' => $header->getExtraTools(),
|
|
|
|
'data-personal-menu' => $header->buildPersonalMenu(),
|
|
|
|
'data-search-box' => $header->buildSearchProps(),
|
2021-04-26 15:50:04 +00:00
|
|
|
'msg-citizen-jumptotop' => $this->msg( 'citizen-jumptotop' )->text() . ' [home]',
|
2020-08-10 03:06:38 +00:00
|
|
|
],
|
|
|
|
|
2022-05-07 04:45:51 +00:00
|
|
|
'html-title--formatted' => $firstHeading->buildFirstHeading( $parentData[ 'html-title' ] ),
|
|
|
|
|
2022-04-14 04:30:33 +00:00
|
|
|
'data-pagetools' => $tools->buildPageTools( $parentData ),
|
2020-08-10 03:06:38 +00:00
|
|
|
|
|
|
|
'html-newtalk' => $newTalksHtml ? '<div class="usermessage">' . $newTalksHtml . '</div>' : '',
|
|
|
|
'page-langcode' => $title->getPageViewLanguage()->getHtmlCode(),
|
|
|
|
|
2021-03-16 17:10:54 +00:00
|
|
|
'msg-tagline' => $tagline->getTagline( $out ),
|
2020-08-10 03:06:38 +00:00
|
|
|
|
2021-03-03 00:28:54 +00:00
|
|
|
'html-body-content--formatted' => $bodycontent->buildBodyContent( $out ),
|
2021-03-02 22:16:24 +00:00
|
|
|
|
2021-06-20 06:03:43 +00:00
|
|
|
'data-citizen-footer' => $footer->getFooterData(),
|
2020-08-10 03:06:38 +00:00
|
|
|
];
|
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
|
|
|
|
*/
|
2021-01-28 20:09:52 +00:00
|
|
|
final public function buildPersonalUrlsPublic() {
|
2021-01-28 11:21:58 +00:00
|
|
|
return parent::buildPersonalUrls();
|
|
|
|
}
|
|
|
|
|
2021-01-28 19:35:31 +00:00
|
|
|
/**
|
|
|
|
* Change access to public, as it is used in partials
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2021-01-28 20:09:52 +00:00
|
|
|
final public function getFooterLinksPublic() {
|
2021-01-28 19:35:31 +00:00
|
|
|
return parent::getFooterLinks();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change access to public, as it is used in partials
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2021-01-28 20:09:52 +00:00
|
|
|
final public function getFooterIconsPublic() {
|
2021-01-28 19:35:31 +00:00
|
|
|
return parent::getFooterIcons();
|
|
|
|
}
|
|
|
|
|
2022-02-09 17:00:45 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
protected function runOnSkinTemplateNavigationHooks( $skin, &$contentNavigationUrls ) {
|
|
|
|
parent::runOnSkinTemplateNavigationHooks( $skin, $contentNavigationUrls );
|
|
|
|
// There are some SkinTemplate modifications that occur after the execution of this hook
|
|
|
|
// to add rel attributes and ID attributes.
|
|
|
|
// The only one Minerva needs is this one so we manually add it.
|
2022-03-05 23:14:48 +00:00
|
|
|
foreach ( array_keys( $contentNavigationUrls['namespaces'] ) as $id ) {
|
|
|
|
if ( in_array( $id, [ 'user_talk', 'talk' ] ) ) {
|
2022-02-09 17:00:45 +00:00
|
|
|
$contentNavigationUrls['namespaces'][ $id ]['rel'] = 'discussion';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->contentNavigationUrls = $contentNavigationUrls;
|
|
|
|
}
|
|
|
|
|
2021-01-28 19:35:31 +00:00
|
|
|
/**
|
|
|
|
* Change access to public, as it is used in partials
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2021-01-28 20:09:52 +00:00
|
|
|
final public function buildContentNavigationUrlsPublic() {
|
2022-02-09 17:00:45 +00:00
|
|
|
if ( !method_exists( parent::class, 'runOnSkinTemplateNavigationHooks' ) ) {
|
|
|
|
// Support for MediaWiki versions < 1.37
|
|
|
|
return parent::buildContentNavigationUrls();
|
|
|
|
} else {
|
|
|
|
// Works with mediawiki version >= 1.37
|
|
|
|
return $this->contentNavigationUrls;
|
|
|
|
}
|
2021-01-28 19:35:31 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 22:16:24 +00:00
|
|
|
/**
|
|
|
|
* Change access to public, as it is used in partials
|
|
|
|
*
|
2021-03-03 00:09:39 +00:00
|
|
|
* @param Title $title
|
|
|
|
* @param string $html body text
|
2021-03-03 08:05:13 +00:00
|
|
|
* @return string
|
2021-03-02 22:16:24 +00:00
|
|
|
*/
|
|
|
|
final public function wrapHTMLPublic( $title, $html ) {
|
|
|
|
return parent::wrapHTML( $title, $html );
|
|
|
|
}
|
|
|
|
|
2021-01-28 11:21:58 +00:00
|
|
|
/**
|
2022-05-16 01:37:39 +00:00
|
|
|
* Polyfill for 1.35 from SkinTemplate
|
2022-05-16 01:39:00 +00:00
|
|
|
*
|
2022-05-16 01:37:39 +00:00
|
|
|
* @since 1.36
|
|
|
|
* @stable for overriding
|
|
|
|
* @param string $name of the portal e.g. p-personal the name is personal.
|
|
|
|
* @param array $items that are accepted input to Skin::makeListItem
|
|
|
|
* @return array data that can be passed to a Mustache template that
|
|
|
|
* represents a single menu.
|
2021-01-28 11:21:58 +00:00
|
|
|
*/
|
2022-05-16 01:37:39 +00:00
|
|
|
public function getPortletData( $name, array $items ) {
|
|
|
|
// Monobook and Vector historically render this portal as an element with ID p-cactions
|
|
|
|
// This inconsistency is regretful from a code point of view
|
|
|
|
// However this ensures compatibility with gadgets.
|
|
|
|
// In future we should port p-#cactions to #p-actions and drop this rename.
|
|
|
|
if ( $name === 'actions' ) {
|
|
|
|
$name = 'cactions';
|
|
|
|
}
|
|
|
|
|
|
|
|
// user-menu is the new personal tools, without the notifications.
|
|
|
|
// A lot of user code and gadgets relies on it being named personal.
|
|
|
|
// This allows it to function as a drop-in replacement.
|
|
|
|
if ( $name === 'user-menu' ) {
|
|
|
|
$name = 'personal';
|
|
|
|
}
|
|
|
|
|
|
|
|
$legacyClasses = '';
|
|
|
|
if ( $name === 'category-normal' ) {
|
|
|
|
// retain historic category IDs and classes
|
|
|
|
$id = 'mw-normal-catlinks';
|
|
|
|
$legacyClasses .= ' mw-normal-catlinks';
|
|
|
|
} elseif ( $name === 'category-hidden' ) {
|
|
|
|
// retain historic category IDs and classes
|
|
|
|
$id = 'mw-hidden-catlinks';
|
|
|
|
$legacyClasses .= ' mw-hidden-catlinks mw-hidden-cats-hidden';
|
|
|
|
} else {
|
|
|
|
$id = Sanitizer::escapeIdForAttribute( "p-$name" );
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'id' => $id,
|
|
|
|
'class' => 'mw-portlet ' . Sanitizer::escapeClass( "mw-portlet-$name" ) . $legacyClasses,
|
|
|
|
'html-tooltip' => Linker::tooltip( $id ),
|
2021-01-28 11:21:58 +00:00
|
|
|
'html-items' => '',
|
2022-05-16 01:37:39 +00:00
|
|
|
// Will be populated by SkinAfterPortlet hook.
|
|
|
|
'html-after-portal' => '',
|
|
|
|
'html-before-portal' => '',
|
2021-01-28 11:21:58 +00:00
|
|
|
];
|
|
|
|
|
2022-05-16 01:37:39 +00:00
|
|
|
foreach ( $items as $key => $item ) {
|
|
|
|
$data['html-items'] .= $this->makeListItem( $key, $item );
|
2021-01-28 11:21:58 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 01:37:39 +00:00
|
|
|
$data['label'] = $this->getPortletLabel( $name );
|
|
|
|
$data['is-empty'] = count( $items ) === 0 && $content === '';
|
|
|
|
$data['class'] .= $data['is-empty'] ? ' emptyPortlet' : '';
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Polyfill for 1.35 from SkinTemplate
|
2022-05-16 01:39:00 +00:00
|
|
|
*
|
2022-05-16 01:37:39 +00:00
|
|
|
* @since 1.36
|
|
|
|
* @param string $name of the portal e.g. p-personal the name is personal.
|
|
|
|
* @return string that is human readable corresponding to the menu
|
|
|
|
*/
|
|
|
|
public function getPortletLabel( $name ) {
|
|
|
|
// For historic reasons for some menu items,
|
|
|
|
// there is no language key corresponding with its menu key.
|
|
|
|
$mappings = [
|
|
|
|
'tb' => 'toolbox',
|
|
|
|
'personal' => 'personaltools',
|
|
|
|
'lang' => 'otherlanguages',
|
|
|
|
];
|
2021-01-28 11:21:58 +00:00
|
|
|
|
2022-05-16 01:37:39 +00:00
|
|
|
$msgObj = $this->msg( $mappings[ $name ] ?? $name );
|
|
|
|
// If no message exists fallback to plain text (T252727)
|
|
|
|
$labelText = $msgObj->exists() ? $msgObj->text() : $name;
|
|
|
|
return $labelText;
|
2021-01-28 11:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-27 21:53:01 +00:00
|
|
|
* @inheritDoc
|
|
|
|
*
|
2021-01-28 19:35:31 +00:00
|
|
|
* Manually disable links to upload and special pages
|
2021-01-27 21:53:01 +00:00
|
|
|
* 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-04-09 17:08:01 +00:00
|
|
|
|
2021-06-09 17:48:38 +00:00
|
|
|
/**
|
|
|
|
* Returns the javascript entry modules to load. Only modules that need to
|
|
|
|
* be overriden or added conditionally should be placed here.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDefaultModules() {
|
|
|
|
$modules = parent::getDefaultModules();
|
|
|
|
|
|
|
|
$modules['content'] = array_diff( $modules['content'], [
|
|
|
|
// Citizen provides its own implementation. Loading this will break display.
|
|
|
|
'mediawiki.toc'
|
|
|
|
] );
|
|
|
|
|
|
|
|
return $modules;
|
|
|
|
}
|
|
|
|
|
2021-04-09 17:08:01 +00:00
|
|
|
/**
|
|
|
|
* Set up optional skin features
|
|
|
|
*
|
|
|
|
* @param array &$options
|
|
|
|
*/
|
|
|
|
private function buildSkinFeatures( array &$options ) {
|
|
|
|
$out = $this->getOutput();
|
|
|
|
$title = $out->getTitle();
|
|
|
|
|
|
|
|
$metadata = new Metadata( $this );
|
|
|
|
$skinTheme = new Theme( $this );
|
|
|
|
|
|
|
|
// Add metadata
|
|
|
|
$metadata->addMetadata();
|
|
|
|
|
|
|
|
// Add theme handler
|
|
|
|
$skinTheme->setSkinTheme( $options );
|
|
|
|
|
|
|
|
// Collapsible sections
|
|
|
|
// Load in content pages
|
|
|
|
if ( $title !== null && $title->isContentPage() ) {
|
|
|
|
// Load Citizen collapsible sections modules if enabled
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnableCollapsibleSections' ) === true ) {
|
|
|
|
$options['scripts'][] = 'skins.citizen.scripts.sections';
|
|
|
|
$options['styles'][] = 'skins.citizen.styles.sections';
|
|
|
|
$options['styles'][] = 'skins.citizen.icons.sections';
|
|
|
|
}
|
2021-04-18 01:24:08 +00:00
|
|
|
}
|
2021-04-09 17:08:01 +00:00
|
|
|
|
2021-04-18 01:24:08 +00:00
|
|
|
// Table of content highlight
|
2022-05-12 21:01:01 +00:00
|
|
|
$options['styles'][] = 'skins.citizen.styles.toc';
|
2021-04-09 17:08:01 +00:00
|
|
|
|
|
|
|
// Drawer sitestats
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnableDrawerSiteStats' ) === true ) {
|
|
|
|
$options['styles'][] = 'skins.citizen.styles.sitestats';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drawer subsearch
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnableDrawerSubSearch' ) === true ) {
|
|
|
|
$options['scripts'][] = 'skins.citizen.scripts.drawer';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Debug styles
|
|
|
|
if (
|
|
|
|
$this->getConfigValue( 'ShowDebug' ) === true
|
|
|
|
|| $this->getConfigValue( 'ShowExceptionDetails' ) === true
|
2021-04-09 17:08:41 +00:00
|
|
|
) {
|
2021-04-09 17:08:01 +00:00
|
|
|
$options['styles'][] = 'skins.citizen.styles.debug';
|
|
|
|
}
|
|
|
|
}
|
2020-06-17 02:56:40 +00:00
|
|
|
}
|