2022-11-15 22:41:28 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare( strict_types=1 );
|
|
|
|
|
|
|
|
namespace MediaWiki\Skins\Citizen\Hooks;
|
|
|
|
|
2023-06-12 02:13:23 +00:00
|
|
|
use ExtensionRegistry;
|
2024-04-24 21:47:33 +00:00
|
|
|
use Html;
|
2023-08-25 21:39:37 +00:00
|
|
|
use Language;
|
2022-11-15 22:41:28 +00:00
|
|
|
use MediaWiki\Hook\BeforePageDisplayHook;
|
|
|
|
use MediaWiki\Hook\SidebarBeforeOutputHook;
|
|
|
|
use MediaWiki\Hook\SkinBuildSidebarHook;
|
2022-11-16 01:54:28 +00:00
|
|
|
use MediaWiki\Hook\SkinEditSectionLinksHook;
|
2024-02-04 20:17:34 +00:00
|
|
|
use MediaWiki\ResourceLoader as RL;
|
2023-08-25 21:39:37 +00:00
|
|
|
use MediaWiki\Skins\Citizen\GetConfigTrait;
|
2022-11-15 22:41:28 +00:00
|
|
|
use MediaWiki\Skins\Hook\SkinPageReadyConfigHook;
|
2023-08-25 23:52:58 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-08-25 21:39:37 +00:00
|
|
|
use OutputPage;
|
2023-06-12 02:12:50 +00:00
|
|
|
use Skin;
|
2023-08-25 21:39:37 +00:00
|
|
|
use SkinTemplate;
|
2023-06-12 02:12:50 +00:00
|
|
|
use SpecialPage;
|
2022-11-15 22:41:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hooks to run relating the skin
|
|
|
|
*/
|
|
|
|
class SkinHooks implements
|
|
|
|
BeforePageDisplayHook,
|
|
|
|
SidebarBeforeOutputHook,
|
|
|
|
SkinBuildSidebarHook,
|
2022-11-16 01:54:28 +00:00
|
|
|
SkinEditSectionLinksHook,
|
2024-04-24 02:55:16 +00:00
|
|
|
SkinPageReadyConfigHook
|
2022-11-15 22:41:28 +00:00
|
|
|
{
|
2023-08-25 21:39:37 +00:00
|
|
|
use GetConfigTrait;
|
2023-06-12 02:13:23 +00:00
|
|
|
|
2022-11-15 22:41:28 +00:00
|
|
|
/**
|
|
|
|
* Adds the inline theme switcher script to the page
|
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @param Skin $skin
|
|
|
|
*/
|
|
|
|
public function onBeforePageDisplay( $out, $skin ): void {
|
|
|
|
// It's better to exit before any additional check
|
|
|
|
if ( $skin->getSkinName() !== 'citizen' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-25 23:33:11 +00:00
|
|
|
if ( $this->getConfigValue( 'CitizenEnablePreferences', $out ) === true ) {
|
|
|
|
$script = file_get_contents( MW_INSTALL_PATH . '/skins/Citizen/resources/skins.citizen.scripts/inline.js' );
|
|
|
|
$script = Html::inlineScript( $script );
|
2024-05-06 18:06:04 +00:00
|
|
|
$script = RL\ResourceLoader::filter( 'minify-js', $script );
|
2024-04-25 23:33:11 +00:00
|
|
|
$out->addHeadItem( 'skin.citizen.inline', $script );
|
|
|
|
}
|
2022-11-15 22:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify toolbox links
|
|
|
|
* For some reason onSkinBuildSidebar was not able to get toolbox
|
|
|
|
* So we need to use this hook instead
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SidebarBeforeOutput
|
|
|
|
* @param Skin $skin
|
|
|
|
* @param array &$sidebar
|
|
|
|
*/
|
|
|
|
public function onSidebarBeforeOutput( $skin, &$sidebar ): void {
|
|
|
|
// Be extra safe because it might be active on other skins with caching
|
|
|
|
if ( $skin->getSkinName() === 'citizen' && $sidebar ) {
|
|
|
|
if ( isset( $sidebar['TOOLBOX'] ) ) {
|
|
|
|
self::updateToolboxMenu( $sidebar );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify sidebar links
|
|
|
|
* This is cached compared to onSidebarBeforeOutput
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinBuildSidebar
|
|
|
|
* @param Skin $skin
|
|
|
|
* @param array &$bar
|
|
|
|
*/
|
|
|
|
public function onSkinBuildSidebar( $skin, &$bar ): void {
|
|
|
|
// Be extra safe because it might be active on other skins with caching
|
2023-08-25 21:39:37 +00:00
|
|
|
if ( $skin->getSkinName() !== 'citizen' || !$bar ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$out = $skin->getOutput();
|
|
|
|
$globalToolsId = $this->getConfigValue( 'CitizenGlobalToolsPortlet', $out );
|
|
|
|
// remove initial p- for backward compatibility
|
|
|
|
$name = empty( $globalToolsId ) ? 'navigation' : preg_replace( '/^p-/', '', $globalToolsId );
|
|
|
|
$bar[$name]['specialpages'] = [
|
|
|
|
'text' => $skin->msg( 'specialpages' ),
|
2024-10-28 20:48:59 +00:00
|
|
|
// TODO: Replace with SkinComponentUtils on 1.43
|
|
|
|
'href' => SpecialPage::getTitleFor( 'Specialpages' )->getLocalURL(),
|
2023-08-25 21:39:37 +00:00
|
|
|
'title' => $skin->msg( 'tooltip-t-specialpages' ),
|
|
|
|
'icon' => 'specialPages',
|
|
|
|
'id' => 't-specialpages',
|
|
|
|
];
|
|
|
|
|
|
|
|
if ( $this->getConfigValue( 'EnableUploads', $out ) === true ) {
|
2024-10-28 20:48:59 +00:00
|
|
|
$isUploadWizardEnabled = ExtensionRegistry::getInstance()->isLoaded( 'Upload Wizard' );
|
2023-08-25 21:39:37 +00:00
|
|
|
$bar[$name]['upload'] = [
|
|
|
|
'text' => $skin->msg( 'upload' ),
|
2024-10-28 20:48:59 +00:00
|
|
|
// TODO: Replace with SkinComponentUtils on 1.43
|
|
|
|
'href' => SpecialPage::getTitleFor( $isUploadWizardEnabled ?
|
|
|
|
'UploadWizard' :
|
|
|
|
'Upload'
|
|
|
|
)->getLocalURL(),
|
2023-08-25 21:39:37 +00:00
|
|
|
'title' => $skin->msg( 'tooltip-t-upload' ),
|
|
|
|
'icon' => 'upload',
|
|
|
|
'id' => 't-upload',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $bar as $key => $item ) {
|
|
|
|
self::addIconsToMenuItems( $bar, $key );
|
2022-11-15 22:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-16 01:54:28 +00:00
|
|
|
/**
|
|
|
|
* Modify editsection links
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinEditSectionLinks
|
|
|
|
* @param Skin $skin
|
|
|
|
* @param Title $title
|
|
|
|
* @param string $section
|
|
|
|
* @param string $sectionTitle
|
|
|
|
* @param array &$result
|
2022-11-16 01:55:22 +00:00
|
|
|
* @param Language $lang
|
2022-11-16 01:54:28 +00:00
|
|
|
*/
|
|
|
|
public function onSkinEditSectionLinks( $skin, $title, $section, $sectionTitle, &$result, $lang ) {
|
2022-11-16 03:39:10 +00:00
|
|
|
// Be extra safe because it might be active on other skins with caching
|
2023-08-25 21:39:37 +00:00
|
|
|
if ( $skin->getSkinName() !== 'citizen' || !$result ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add icon to edit section link
|
|
|
|
// If VE button is present, use wikiText icon
|
|
|
|
if ( isset( $result['veeditsection'] ) ) {
|
|
|
|
self::appendClassToItem(
|
|
|
|
$result['veeditsection']['attribs']['class'],
|
2024-06-05 04:04:12 +00:00
|
|
|
'citizen-editsection-icon mw-ui-icon-wikimedia-edit'
|
2023-08-25 21:39:37 +00:00
|
|
|
);
|
|
|
|
self::appendClassToItem(
|
|
|
|
$result['editsection']['attribs']['class'],
|
2024-06-05 04:04:12 +00:00
|
|
|
'citizen-editsection-icon mw-ui-icon-wikimedia-wikiText'
|
2023-08-25 21:39:37 +00:00
|
|
|
);
|
|
|
|
} elseif ( isset( $result['editsection'] ) ) {
|
|
|
|
self::appendClassToItem(
|
|
|
|
$result['editsection']['attribs']['class'],
|
2024-06-05 04:04:12 +00:00
|
|
|
'citizen-editsection-icon mw-ui-icon-wikimedia-edit'
|
2023-08-25 21:39:37 +00:00
|
|
|
);
|
2022-11-16 01:54:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 22:41:28 +00:00
|
|
|
/**
|
|
|
|
* SkinPageReadyConfig hook handler
|
|
|
|
*
|
|
|
|
* Replace searchModule provided by skin.
|
|
|
|
*
|
2024-02-04 20:17:34 +00:00
|
|
|
* @since 1.36
|
|
|
|
* @param RL\Context $context
|
2022-11-15 22:41:28 +00:00
|
|
|
* @param mixed[] &$config Associative array of configurable options
|
|
|
|
* @return void This hook must not abort, it must return no value
|
|
|
|
*/
|
|
|
|
public function onSkinPageReadyConfig( $context, array &$config ): void {
|
|
|
|
// It's better to exit before any additional check
|
|
|
|
if ( $context->getSkin() !== 'citizen' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the `mediawiki.page.ready` module not to wire up search.
|
|
|
|
$config['search'] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify navigation links
|
|
|
|
*
|
2024-04-24 02:55:16 +00:00
|
|
|
* TODO: Update to a proper hook when T287622 is resolved
|
2022-11-15 22:41:28 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation::Universal
|
|
|
|
* @param SkinTemplate $sktemplate
|
|
|
|
* @param array &$links
|
|
|
|
*/
|
2024-04-24 02:55:16 +00:00
|
|
|
public static function onSkinTemplateNavigation( $sktemplate, &$links ): void {
|
2022-11-15 22:41:28 +00:00
|
|
|
// Be extra safe because it might be active on other skins with caching
|
2023-08-25 21:39:37 +00:00
|
|
|
if ( $sktemplate->getSkinName() !== 'citizen' ) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-15 22:41:28 +00:00
|
|
|
|
2023-08-25 21:39:37 +00:00
|
|
|
if ( isset( $links['actions'] ) ) {
|
|
|
|
self::updateActionsMenu( $links );
|
|
|
|
}
|
2022-11-15 22:41:28 +00:00
|
|
|
|
2023-08-25 21:39:37 +00:00
|
|
|
if ( isset( $links['associated-pages'] ) ) {
|
|
|
|
self::updateAssociatedPagesMenu( $links );
|
|
|
|
}
|
2022-11-15 22:41:28 +00:00
|
|
|
|
2024-05-03 21:33:50 +00:00
|
|
|
if ( isset( $links['notifications'] ) ) {
|
|
|
|
self::updateNotificationsMenu( $links );
|
|
|
|
}
|
|
|
|
|
2023-08-25 21:39:37 +00:00
|
|
|
if ( isset( $links['user-menu'] ) ) {
|
|
|
|
self::updateUserMenu( $sktemplate, $links );
|
|
|
|
}
|
2023-02-15 23:38:02 +00:00
|
|
|
|
2023-08-25 21:39:37 +00:00
|
|
|
if ( isset( $links['user-interface-preferences'] ) ) {
|
|
|
|
self::updateUserInterfacePreferencesMenu( $sktemplate, $links );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $links['views'] ) ) {
|
|
|
|
self::updateViewsMenu( $links );
|
2022-11-15 22:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update actions menu items
|
|
|
|
*
|
2024-04-24 02:55:16 +00:00
|
|
|
* @internal used inside Hooks\SkinHooks::onSkinTemplateNavigation
|
2022-11-15 22:41:28 +00:00
|
|
|
* @param array &$links
|
|
|
|
*/
|
|
|
|
private static function updateActionsMenu( &$links ) {
|
|
|
|
// Most icons are not mapped yet in the actions menu
|
|
|
|
$iconMap = [
|
|
|
|
'delete' => 'trash',
|
|
|
|
'move' => 'move',
|
|
|
|
'protect' => 'lock',
|
2022-11-18 18:18:42 +00:00
|
|
|
'unprotect' => 'unLock',
|
|
|
|
// Extension:Purge
|
|
|
|
// Extension:SemanticMediaWiki
|
2024-05-03 22:06:56 +00:00
|
|
|
'purge' => 'reload',
|
|
|
|
// Extension:Cargo
|
2024-05-03 22:12:22 +00:00
|
|
|
'cargo-purge' => 'reload',
|
|
|
|
// Extension:DiscussionTools
|
|
|
|
'dt-page-subscribe' => 'bell'
|
2022-11-15 22:41:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
self::mapIconsToMenuItems( $links, 'actions', $iconMap );
|
|
|
|
self::addIconsToMenuItems( $links, 'actions' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update associated pages menu items
|
|
|
|
*
|
2024-04-24 02:55:16 +00:00
|
|
|
* @internal used inside Hooks\SkinHooks::onSkinTemplateNavigation
|
2022-11-15 22:41:28 +00:00
|
|
|
* @param array &$links
|
|
|
|
*/
|
|
|
|
private static function updateAssociatedPagesMenu( &$links ) {
|
|
|
|
// Most icons are not mapped yet in the associated pages menu
|
|
|
|
$iconMap = [
|
|
|
|
'main' => 'article',
|
2024-04-27 17:29:23 +00:00
|
|
|
'file' => 'image',
|
2024-06-06 18:52:30 +00:00
|
|
|
'talk' => 'speechBubbles',
|
2022-12-02 03:33:45 +00:00
|
|
|
'user' => 'userAvatar'
|
2022-11-15 22:41:28 +00:00
|
|
|
];
|
|
|
|
|
2022-12-02 03:33:45 +00:00
|
|
|
// Special handling for talk pages
|
|
|
|
// Since talk keys have namespace as prefix
|
|
|
|
foreach ( $links['associated-pages'] as $key => $item ) {
|
2024-06-06 18:43:34 +00:00
|
|
|
$keyStr = (string)$key;
|
|
|
|
// TODO: use str_ends_with when we drop PHP 7.X
|
|
|
|
if ( substr( $keyStr, -5 ) === '_talk' ) {
|
|
|
|
// Extract the namespace key from the talk key (e.g. Project from Project_talk)
|
|
|
|
// TODO: use str_starts_with when we drop PHP 7.X
|
|
|
|
$namespace = substr( $keyStr, 0, -5 );
|
2022-12-02 03:33:45 +00:00
|
|
|
$links['associated-pages'][$key]['icon'] = 'speechBubbles';
|
2024-06-06 18:45:41 +00:00
|
|
|
$links['associated-pages'][$namespace]['icon'] = 'arrowPrevious';
|
2022-12-02 03:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 22:41:28 +00:00
|
|
|
self::mapIconsToMenuItems( $links, 'associated-pages', $iconMap );
|
|
|
|
self::addIconsToMenuItems( $links, 'associated-pages' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update toolbox menu items
|
|
|
|
*
|
2024-04-24 02:55:16 +00:00
|
|
|
* @internal used inside Hooks\SkinHooks::onSkinTemplateNavigation
|
2022-11-15 22:41:28 +00:00
|
|
|
* @param array &$links
|
|
|
|
*/
|
|
|
|
private static function updateToolboxMenu( &$links ) {
|
|
|
|
// Most icons are not mapped yet in the toolbox menu
|
|
|
|
$iconMap = [
|
|
|
|
'whatlinkshere' => 'articleRedirect',
|
|
|
|
'recentchangeslinked' => 'recentChanges',
|
|
|
|
'print' => 'printer',
|
|
|
|
'permalink' => 'link',
|
|
|
|
'info' => 'infoFilled',
|
|
|
|
'contributions' => 'userContributions',
|
|
|
|
'log' => 'history',
|
|
|
|
'blockip' => 'block',
|
2023-07-06 19:02:14 +00:00
|
|
|
'emailuser' => 'message',
|
2022-11-18 18:18:42 +00:00
|
|
|
'userrights' => 'userGroup',
|
|
|
|
// Extension:Cargo
|
|
|
|
'cargo-pagevalues' => 'database',
|
2023-01-05 06:12:56 +00:00
|
|
|
// Extension:CiteThisPage
|
2024-05-03 22:54:03 +00:00
|
|
|
'citethispage' => 'quotes',
|
2023-01-05 06:12:56 +00:00
|
|
|
// Extension:CreateRedirect
|
|
|
|
'createredirect' => 'articleRedirect',
|
2022-11-18 18:18:42 +00:00
|
|
|
// Extension:SemanticMediaWiki
|
2023-02-17 04:50:48 +00:00
|
|
|
'smwbrowselink' => 'database',
|
|
|
|
// Extension:UrlShortener
|
2024-04-27 03:56:03 +00:00
|
|
|
'urlshortener' => 'link',
|
2024-04-27 17:25:37 +00:00
|
|
|
'urlshortener-qrcode' => 'qrCode',
|
|
|
|
// Extension:Wikibase
|
|
|
|
'wikibase' => 'logoWikidata'
|
2022-11-15 22:41:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
self::mapIconsToMenuItems( $links, 'TOOLBOX', $iconMap );
|
|
|
|
self::addIconsToMenuItems( $links, 'TOOLBOX' );
|
|
|
|
}
|
|
|
|
|
2024-05-03 21:33:50 +00:00
|
|
|
/**
|
|
|
|
* Update notifications menu
|
|
|
|
*
|
|
|
|
* @internal used inside Hooks\SkinHooks::onSkinTemplateNavigation
|
|
|
|
* @param array &$links
|
|
|
|
*/
|
|
|
|
private static function updateNotificationsMenu( &$links ) {
|
2024-05-06 19:28:56 +00:00
|
|
|
$iconMap = [
|
|
|
|
'notifications-alert' => 'bell',
|
|
|
|
'notifications-notice' => 'tray'
|
|
|
|
];
|
|
|
|
|
|
|
|
self::mapIconsToMenuItems( $links, 'notifications', $iconMap );
|
|
|
|
self::addIconsToMenuItems( $links, 'notifications' );
|
|
|
|
|
2024-05-03 21:33:50 +00:00
|
|
|
/**
|
|
|
|
* Echo has styles that control icons rendering in places we don't want them.
|
|
|
|
* Based on fixEcho() from Vector, see T343838
|
|
|
|
*/
|
|
|
|
foreach ( $links['notifications'] as &$item ) {
|
|
|
|
$icon = $item['icon'] ?? null;
|
|
|
|
if ( $icon ) {
|
|
|
|
$linkClass = $item['link-class'] ?? [];
|
|
|
|
$newLinkClass = [
|
|
|
|
// Allows Echo to react to clicks
|
2024-07-06 00:37:52 +00:00
|
|
|
'citizen-echo-notification-badge',
|
|
|
|
'citizen-header__button',
|
|
|
|
'mw-echo-notification-badge-nojs'
|
2024-05-03 21:33:50 +00:00
|
|
|
];
|
|
|
|
if ( in_array( 'mw-echo-unseen-notifications', $linkClass ) ) {
|
|
|
|
$newLinkClass[] = 'mw-echo-unseen-notifications';
|
|
|
|
}
|
|
|
|
$item['link-class'] = $newLinkClass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 22:41:28 +00:00
|
|
|
/**
|
|
|
|
* Update user menu
|
2024-04-24 02:55:42 +00:00
|
|
|
*
|
2024-04-24 02:55:16 +00:00
|
|
|
* @internal used inside Hooks\SkinHooks::onSkinTemplateNavigation
|
2022-11-15 22:41:28 +00:00
|
|
|
* @param SkinTemplate $sktemplate
|
|
|
|
* @param array &$links
|
|
|
|
*/
|
|
|
|
private static function updateUserMenu( $sktemplate, &$links ) {
|
|
|
|
$user = $sktemplate->getUser();
|
|
|
|
$isRegistered = $user->isRegistered();
|
|
|
|
$isTemp = $user->isTemp();
|
|
|
|
|
|
|
|
if ( $isTemp ) {
|
|
|
|
// Remove temporary user page text from user menu and recreate it in user info
|
|
|
|
unset( $links['user-menu']['tmpuserpage'] );
|
|
|
|
// Remove links as they are added to the bottom of user menu later
|
|
|
|
// unset( $links['user-menu']['logout'] );
|
|
|
|
} elseif ( $isRegistered ) {
|
|
|
|
// Remove user page link from user menu and recreate it in user info
|
|
|
|
unset( $links['user-menu']['userpage'] );
|
|
|
|
} else {
|
|
|
|
// Remove anon user page text from user menu and recreate it in user info
|
|
|
|
unset( $links['user-menu']['anonuserpage'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
self::addIconsToMenuItems( $links, 'user-menu' );
|
|
|
|
}
|
|
|
|
|
2023-02-15 23:38:02 +00:00
|
|
|
/**
|
|
|
|
* Update user interface preferences menu
|
|
|
|
*
|
2024-04-24 02:55:16 +00:00
|
|
|
* @internal used inside Hooks\SkinHooks::onSkinTemplateNavigation
|
2023-02-15 23:38:02 +00:00
|
|
|
* @param SkinTemplate $sktemplate
|
|
|
|
* @param array &$links
|
|
|
|
*/
|
|
|
|
private static function updateUserInterfacePreferencesMenu( $sktemplate, &$links ) {
|
|
|
|
self::addIconsToMenuItems( $links, 'user-interface-preferences' );
|
|
|
|
}
|
|
|
|
|
2022-11-15 22:41:28 +00:00
|
|
|
/**
|
|
|
|
* Update views menu items
|
|
|
|
*
|
2024-04-24 02:55:16 +00:00
|
|
|
* @internal used inside Hooks\SkinHooks::onSkinTemplateNavigation
|
2022-11-15 22:41:28 +00:00
|
|
|
* @param array &$links
|
|
|
|
*/
|
|
|
|
private static function updateViewsMenu( &$links ) {
|
|
|
|
// Most icons are not mapped yet in the views menu
|
|
|
|
$iconMap = [
|
|
|
|
'view' => 'article',
|
|
|
|
// View source button only appears when the user do not have permission
|
|
|
|
'viewsource' => 'editLock',
|
|
|
|
'history' => 'history',
|
|
|
|
'edit' => 'edit',
|
|
|
|
'view-foreign' => 'linkExternal',
|
|
|
|
// Extension:VisualEditor
|
2024-05-06 17:37:33 +00:00
|
|
|
've-edit' => 'edit',
|
2022-11-15 22:41:28 +00:00
|
|
|
// Extension:DiscussionTools
|
|
|
|
'addsection' => 'speechBubbleAdd'
|
|
|
|
];
|
|
|
|
|
|
|
|
// If both visual edit and source edit buttons are present
|
|
|
|
if ( isset( $links['views']['ve-edit'] ) && isset( $links['views']['edit'] ) ) {
|
|
|
|
// Add a class so that we can make a merged button through CSS
|
2022-11-16 04:41:47 +00:00
|
|
|
self::appendClassToItem( $links['views']['ve-edit']['class'], [ 'citizen-ve-edit-merged' ] );
|
|
|
|
self::appendClassToItem( $links['views']['edit']['class'], [ 'citizen-ve-edit-merged' ] );
|
2022-11-15 22:41:28 +00:00
|
|
|
// Use wikiText icon instead of edit icon for source edit
|
|
|
|
$iconMap['edit'] = 'wikiText';
|
|
|
|
}
|
|
|
|
|
|
|
|
self::mapIconsToMenuItems( $links, 'views', $iconMap );
|
|
|
|
self::addIconsToMenuItems( $links, 'views' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the icon parameter of the menu item based on the mapping
|
|
|
|
*
|
|
|
|
* @param array &$links
|
|
|
|
* @param string $menu identifier
|
|
|
|
* @param array $map icon mapping
|
|
|
|
*/
|
|
|
|
private static function mapIconsToMenuItems( &$links, $menu, $map ) {
|
|
|
|
foreach ( $map as $key => $icon ) {
|
|
|
|
if ( isset( $links[$menu][$key] ) ) {
|
|
|
|
$links[$menu][$key]['icon'] ??= $icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the HTML needed for icons to menu items
|
|
|
|
*
|
|
|
|
* @param array &$links
|
|
|
|
* @param string $menu identifier
|
|
|
|
*/
|
|
|
|
private static function addIconsToMenuItems( &$links, $menu ) {
|
|
|
|
// Loop through each menu to check/append its link classes.
|
|
|
|
foreach ( $links[$menu] as $key => $item ) {
|
|
|
|
$icon = $item['icon'] ?? '';
|
|
|
|
|
|
|
|
if ( $icon ) {
|
|
|
|
// Html::makeLink will pass this through rawElement
|
|
|
|
// Avoid using mw-ui-icon in case its styles get loaded
|
2023-02-15 23:38:02 +00:00
|
|
|
// Sometimes extension includes the "wikimedia-" part in the icon key (e.g. ULS),
|
|
|
|
// so we apply both classes just to be safe
|
|
|
|
$links[$menu][$key]['link-html'] = '<span class="citizen-ui-icon mw-ui-icon-' . $icon . ' mw-ui-icon-wikimedia-' . $icon . '"></span>';
|
2022-11-15 22:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-16 04:36:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds class to a property
|
|
|
|
* Based on Vector
|
|
|
|
*
|
2024-06-05 03:37:16 +00:00
|
|
|
* @param array|string &$item to update
|
2022-11-16 04:36:30 +00:00
|
|
|
* @param array|string $classes to add to the item
|
|
|
|
*/
|
|
|
|
private static function appendClassToItem( &$item, $classes ) {
|
|
|
|
$existingClasses = $item;
|
|
|
|
|
|
|
|
if ( is_array( $existingClasses ) ) {
|
|
|
|
// Treat as array
|
|
|
|
$newArrayClasses = is_array( $classes ) ? $classes : [ trim( $classes ) ];
|
|
|
|
$item = array_merge( $existingClasses, $newArrayClasses );
|
|
|
|
} elseif ( is_string( $existingClasses ) ) {
|
|
|
|
// Treat as string
|
|
|
|
$newStrClasses = is_string( $classes ) ? trim( $classes ) : implode( ' ', $classes );
|
|
|
|
$item .= ' ' . $newStrClasses;
|
|
|
|
} else {
|
|
|
|
// Treat as whatever $classes is
|
|
|
|
$item = $classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_string( $item ) ) {
|
|
|
|
$item = trim( $item );
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 22:41:28 +00:00
|
|
|
}
|