2022-11-17 02:05:44 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Skins\Citizen;
|
|
|
|
|
2024-05-15 05:24:43 +00:00
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentFooter;
|
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentMainMenu;
|
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentPageFooter;
|
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentPageHeading;
|
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentPageSidebar;
|
2024-10-23 20:08:58 +00:00
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentPageTools;
|
2024-05-15 05:24:43 +00:00
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentSearchBox;
|
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentSiteStats;
|
|
|
|
use MediaWiki\Skins\Citizen\Components\CitizenComponentUserInfo;
|
2022-11-17 02:05:44 +00:00
|
|
|
use MediaWiki\Skins\Citizen\Partials\BodyContent;
|
|
|
|
use MediaWiki\Skins\Citizen\Partials\Metadata;
|
|
|
|
use MediaWiki\Skins\Citizen\Partials\Theme;
|
|
|
|
use SkinMustache;
|
2024-04-24 02:55:16 +00:00
|
|
|
use SkinTemplate;
|
2022-11-17 02:05:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Skin subclass for Citizen
|
|
|
|
* @ingroup Skins
|
|
|
|
*/
|
|
|
|
class SkinCitizen extends SkinMustache {
|
|
|
|
use GetConfigTrait;
|
|
|
|
|
2024-10-23 20:08:58 +00:00
|
|
|
/** @var null|array for caching purposes */
|
|
|
|
private $languages;
|
|
|
|
|
2022-11-17 02:05:44 +00:00
|
|
|
/**
|
|
|
|
* Overrides template, styles and scripts module
|
|
|
|
*
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function __construct( $options = [] ) {
|
2023-08-25 21:39:37 +00:00
|
|
|
if ( !isset( $options['name'] ) ) {
|
|
|
|
$options['name'] = 'citizen';
|
|
|
|
}
|
|
|
|
|
2022-11-17 02:05:44 +00:00
|
|
|
// Add skin-specific features
|
|
|
|
$this->buildSkinFeatures( $options );
|
|
|
|
parent::__construct( $options );
|
|
|
|
}
|
|
|
|
|
2024-04-24 02:55:16 +00:00
|
|
|
/**
|
2024-06-05 19:28:25 +00:00
|
|
|
* Ensure onSkinTemplateNavigation runs after all SkinTemplateNavigation hooks
|
|
|
|
* @see T287622
|
|
|
|
*
|
|
|
|
* @param SkinTemplate $skin The skin template object.
|
2024-06-05 19:28:35 +00:00
|
|
|
* @param array &$content_navigation The content navigation array.
|
2024-04-24 02:55:16 +00:00
|
|
|
*/
|
|
|
|
protected function runOnSkinTemplateNavigationHooks( SkinTemplate $skin, &$content_navigation ) {
|
|
|
|
parent::runOnSkinTemplateNavigationHooks( $skin, $content_navigation );
|
|
|
|
Hooks\SkinHooks::onSkinTemplateNavigation( $skin, $content_navigation );
|
|
|
|
}
|
|
|
|
|
2024-10-23 20:08:58 +00:00
|
|
|
/**
|
|
|
|
* Calls getLanguages with caching.
|
|
|
|
* From Vector 2022
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getLanguagesCached(): array {
|
|
|
|
if ( $this->languages === null ) {
|
|
|
|
$this->languages = $this->getLanguages();
|
|
|
|
}
|
|
|
|
return $this->languages;
|
|
|
|
}
|
|
|
|
|
2022-11-17 02:05:44 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
|
|
|
$parentData = parent::getTemplateData();
|
|
|
|
|
2024-05-15 05:24:43 +00:00
|
|
|
$config = $this->getConfig();
|
|
|
|
$localizer = $this->getContext();
|
|
|
|
$out = $this->getOutput();
|
|
|
|
$title = $this->getTitle();
|
|
|
|
$user = $this->getUser();
|
|
|
|
$pageLang = $title->getPageLanguage();
|
|
|
|
$isRegistered = $user->isRegistered();
|
|
|
|
$isTemp = $user->isTemp();
|
|
|
|
|
2022-11-17 02:05:44 +00:00
|
|
|
$bodycontent = new BodyContent( $this );
|
|
|
|
|
2024-05-15 05:24:43 +00:00
|
|
|
$components = [
|
|
|
|
'data-footer' => new CitizenComponentFooter(
|
|
|
|
$localizer,
|
|
|
|
$parentData['data-footer']
|
|
|
|
),
|
|
|
|
'data-main-menu' => new CitizenComponentMainMenu( $parentData['data-portlets-sidebar'] ),
|
|
|
|
'data-page-footer' => new CitizenComponentPageFooter(
|
|
|
|
$localizer,
|
|
|
|
$parentData['data-footer']['data-info']
|
|
|
|
),
|
|
|
|
'data-page-heading' => new CitizenComponentPageHeading(
|
|
|
|
$localizer,
|
|
|
|
$out,
|
|
|
|
$pageLang,
|
|
|
|
$title,
|
|
|
|
$parentData['html-title-heading'],
|
|
|
|
$user
|
|
|
|
),
|
|
|
|
'data-page-sidebar' => new CitizenComponentPageSidebar(
|
|
|
|
$localizer,
|
|
|
|
$out,
|
|
|
|
$pageLang,
|
|
|
|
$title,
|
|
|
|
$user
|
|
|
|
),
|
2024-10-23 20:08:58 +00:00
|
|
|
'data-page-tools' => new CitizenComponentPageTools(
|
|
|
|
$config,
|
|
|
|
$localizer,
|
|
|
|
$title,
|
|
|
|
$user,
|
|
|
|
count( $this->getLanguagesCached() ),
|
|
|
|
$parentData['data-portlets-sidebar'],
|
|
|
|
// These portlets can be unindexed
|
|
|
|
$parentData['data-portlets']['data-languages'] ?? [],
|
|
|
|
$parentData['data-portlets']['data-variants'] ?? []
|
|
|
|
),
|
2024-05-15 05:24:43 +00:00
|
|
|
'data-search-box' => new CitizenComponentSearchBox(
|
2024-09-26 21:47:19 +00:00
|
|
|
$localizer,
|
2024-05-15 05:24:43 +00:00
|
|
|
$parentData['data-search-box'],
|
|
|
|
$this
|
|
|
|
),
|
|
|
|
'data-site-stats' => new CitizenComponentSiteStats(
|
|
|
|
$config,
|
|
|
|
$localizer,
|
|
|
|
$pageLang
|
|
|
|
),
|
|
|
|
'data-user-info' => new CitizenComponentUserInfo(
|
|
|
|
$isRegistered,
|
|
|
|
$isTemp,
|
|
|
|
$localizer,
|
|
|
|
$title,
|
|
|
|
$user,
|
|
|
|
$parentData['data-portlets']['data-user-page']
|
|
|
|
)
|
2022-11-17 02:05:44 +00:00
|
|
|
];
|
|
|
|
|
2024-05-15 05:24:43 +00:00
|
|
|
foreach ( $components as $key => $component ) {
|
|
|
|
// Array of components or null values.
|
|
|
|
if ( $component ) {
|
|
|
|
$parentData[$key] = $component->getTemplateData();
|
|
|
|
}
|
|
|
|
}
|
2022-11-17 02:05:44 +00:00
|
|
|
|
2024-05-15 05:24:43 +00:00
|
|
|
return array_merge( $parentData, [
|
|
|
|
// Booleans
|
|
|
|
'toc-enabled' => !empty( $parentData['data-toc'] ),
|
|
|
|
'html-body-content--formatted' => $bodycontent->decorateBodyContent( $parentData['html-body-content'] )
|
2024-10-23 20:08:58 +00:00
|
|
|
] );
|
2022-11-17 02:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*
|
|
|
|
* Manually disable some site-wide tools in TOOLBOX
|
|
|
|
* They are re-added in the drawer
|
|
|
|
*
|
|
|
|
* TODO: Remove this hack when Desktop Improvements separate page and site tools
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function buildNavUrls() {
|
|
|
|
$urls = parent::buildNavUrls();
|
|
|
|
|
|
|
|
$urls['upload'] = false;
|
|
|
|
$urls['specialpages'] = false;
|
|
|
|
|
|
|
|
return $urls;
|
|
|
|
}
|
|
|
|
|
2024-04-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* Add client preferences features
|
|
|
|
* Did not add the citizen-feature- prefix because there might be features from core MW or extensions
|
|
|
|
*
|
|
|
|
* @param string $feature
|
|
|
|
* @param string $value
|
|
|
|
*/
|
2024-04-25 21:51:46 +00:00
|
|
|
private function addClientPrefFeature( string $feature, string $value = 'standard' ) {
|
2024-04-25 21:03:23 +00:00
|
|
|
$this->getOutput()->addHtmlClasses( $feature . '-clientpref-' . $value );
|
|
|
|
}
|
|
|
|
|
2022-11-17 02:05:44 +00:00
|
|
|
/**
|
|
|
|
* Set up optional skin features
|
|
|
|
*
|
|
|
|
* @param array &$options
|
|
|
|
*/
|
|
|
|
private function buildSkinFeatures( array &$options ) {
|
2024-04-25 21:03:23 +00:00
|
|
|
$title = $this->getOutput()->getTitle();
|
2022-11-17 02:05:44 +00:00
|
|
|
|
|
|
|
$metadata = new Metadata( $this );
|
|
|
|
$skinTheme = new Theme( $this );
|
|
|
|
|
|
|
|
// Add metadata
|
|
|
|
$metadata->addMetadata();
|
|
|
|
|
|
|
|
// Add theme handler
|
|
|
|
$skinTheme->setSkinTheme( $options );
|
|
|
|
|
2024-04-25 19:45:24 +00:00
|
|
|
// Clientprefs feature handling
|
2024-07-10 17:59:03 +00:00
|
|
|
$this->addClientPrefFeature( 'citizen-feature-autohide-navigation', '1' );
|
2024-04-25 21:03:23 +00:00
|
|
|
$this->addClientPrefFeature( 'citizen-feature-pure-black', '0' );
|
2024-04-25 21:51:46 +00:00
|
|
|
$this->addClientPrefFeature( 'citizen-feature-custom-font-size' );
|
|
|
|
$this->addClientPrefFeature( 'citizen-feature-custom-width' );
|
2024-04-25 19:45:24 +00:00
|
|
|
|
2022-11-17 02:05:44 +00:00
|
|
|
// Collapsible sections
|
|
|
|
// Load in content pages
|
|
|
|
if ( $title !== null && $title->isContentPage() ) {
|
2022-12-09 19:48:17 +00:00
|
|
|
// Since we merged the sections module into core styles and scripts to reduce RL modules
|
|
|
|
// The style is now activated through the class below
|
2022-11-17 02:05:44 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnableCollapsibleSections' ) === true ) {
|
2022-12-09 19:48:17 +00:00
|
|
|
$options['bodyClasses'][] = 'citizen-sections-enabled';
|
2022-11-17 02:05:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CJK fonts
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnableCJKFonts' ) === true ) {
|
|
|
|
$options['styles'][] = 'skins.citizen.styles.fonts.cjk';
|
|
|
|
}
|
2023-12-15 05:41:45 +00:00
|
|
|
|
|
|
|
// AR fonts
|
|
|
|
if ( $this->getConfigValue( 'CitizenEnableARFonts' ) === true ) {
|
|
|
|
$options['styles'][] = 'skins.citizen.styles.fonts.ar';
|
|
|
|
}
|
2022-11-17 02:05:44 +00:00
|
|
|
}
|
|
|
|
}
|