2017-06-30 19:21:16 +00:00
|
|
|
<?php
|
2018-03-12 23:52:48 +00:00
|
|
|
|
2022-05-23 07:32:40 +00:00
|
|
|
namespace MediaWiki\Skins\Vector;
|
2018-03-12 23:52:48 +00:00
|
|
|
|
2021-01-02 13:11:04 +00:00
|
|
|
use MediaWiki\Auth\Hook\LocalUserCreatedHook;
|
2024-01-02 19:54:08 +00:00
|
|
|
use MediaWiki\Config\Config;
|
2024-06-10 20:28:24 +00:00
|
|
|
use MediaWiki\Context\RequestContext;
|
[Special:Preferences] [PHP] Add skin version user preference and configs
Add a Vector-specific user preference to Special:Preferences for
toggling skin version, either Legacy Vector or the latest Vector.
The presentation of the new preference section and the default values
for anonymous, new, and existing accounts are configurable via
$wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by
the feature manager in T244481),
$wgVectorDefaultSkinVersionForExistingAccounts, and
$wgVectorDefaultSkinVersionForNewAccounts. These configurations default
to the fullest experience so that third-party configuration is minimal.
See skin.json for details. The configurations are each tested in
VectorHooksTest.php.
When presentation is enabled, the new preference appears as a checkbox;
enabled is Legacy mode and disable is latest. There are a number of
unfortunate details:
- Showing and hiding a checkbox is supported by OOUI. Showing and hiding
a whole section (Vector skin preferences, in this case) is not so this
additional client JavaScript functionality is added in Core (see
Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377).
- Stylization as a checkbox is wanted. However, the implied storage type
for OOUI checkboxes is a boolean. This is not wanted in the event that
another skin version is added (e.g., '3' or 'alpha'). As a workaround,
the preference is converted from a boolean to a version string ('1' or
'2') on save in Hooks::onPreferencesFormPreSave() and from a version
string to a checkbox enable / disable string ('1' or '0') in
onGetPreferences(). There a number of test cases to help cover these
concerning details.
Documentation for overriding the skin version as a URL query parameter
is provided in anticipation of T244481.
Bug: T242381
Bug: T245793
Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377
Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22
Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-01-02 13:11:04 +00:00
|
|
|
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
2022-05-25 05:12:31 +00:00
|
|
|
use MediaWiki\ResourceLoader as RL;
|
2021-01-02 13:11:04 +00:00
|
|
|
use MediaWiki\Skins\Hook\SkinPageReadyConfigHook;
|
2023-10-04 09:31:15 +00:00
|
|
|
use MediaWiki\Skins\Vector\Hooks\HookRunner;
|
2024-02-27 19:33:12 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsManager;
|
2024-01-02 19:54:08 +00:00
|
|
|
use MediaWiki\User\User;
|
2021-12-14 19:24:32 +00:00
|
|
|
use RuntimeException;
|
2018-03-12 23:52:48 +00:00
|
|
|
use SkinTemplate;
|
2017-06-30 19:21:16 +00:00
|
|
|
|
|
|
|
/**
|
[Special:Preferences] [PHP] Add skin version user preference and configs
Add a Vector-specific user preference to Special:Preferences for
toggling skin version, either Legacy Vector or the latest Vector.
The presentation of the new preference section and the default values
for anonymous, new, and existing accounts are configurable via
$wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by
the feature manager in T244481),
$wgVectorDefaultSkinVersionForExistingAccounts, and
$wgVectorDefaultSkinVersionForNewAccounts. These configurations default
to the fullest experience so that third-party configuration is minimal.
See skin.json for details. The configurations are each tested in
VectorHooksTest.php.
When presentation is enabled, the new preference appears as a checkbox;
enabled is Legacy mode and disable is latest. There are a number of
unfortunate details:
- Showing and hiding a checkbox is supported by OOUI. Showing and hiding
a whole section (Vector skin preferences, in this case) is not so this
additional client JavaScript functionality is added in Core (see
Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377).
- Stylization as a checkbox is wanted. However, the implied storage type
for OOUI checkboxes is a boolean. This is not wanted in the event that
another skin version is added (e.g., '3' or 'alpha'). As a workaround,
the preference is converted from a boolean to a version string ('1' or
'2') on save in Hooks::onPreferencesFormPreSave() and from a version
string to a checkbox enable / disable string ('1' or '0') in
onGetPreferences(). There a number of test cases to help cover these
concerning details.
Documentation for overriding the skin version as a URL query parameter
is provided in anticipation of T244481.
Bug: T242381
Bug: T245793
Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377
Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22
Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
|
|
|
* Presentation hook handlers for Vector skin.
|
2017-06-30 19:21:16 +00:00
|
|
|
*
|
|
|
|
* Hook handler method names should be in the form of:
|
|
|
|
* on<HookName>()
|
2020-08-04 00:17:53 +00:00
|
|
|
* @package Vector
|
|
|
|
* @internal
|
2017-06-30 19:21:16 +00:00
|
|
|
*/
|
2021-01-02 13:11:04 +00:00
|
|
|
class Hooks implements
|
|
|
|
GetPreferencesHook,
|
|
|
|
LocalUserCreatedHook,
|
2022-10-18 01:15:50 +00:00
|
|
|
SkinPageReadyConfigHook
|
2021-01-02 13:11:04 +00:00
|
|
|
{
|
2024-02-27 19:33:12 +00:00
|
|
|
private Config $config;
|
|
|
|
private UserOptionsManager $userOptionsManager;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
Config $config,
|
|
|
|
UserOptionsManager $userOptionsManager
|
|
|
|
) {
|
|
|
|
$this->config = $config;
|
|
|
|
$this->userOptionsManager = $userOptionsManager;
|
|
|
|
}
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
/**
|
|
|
|
* Checks if the current skin is a variant of Vector
|
|
|
|
*
|
|
|
|
* @param string $skinName
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private static function isVectorSkin( string $skinName ): bool {
|
|
|
|
return (
|
|
|
|
$skinName === Constants::SKIN_NAME_LEGACY ||
|
|
|
|
$skinName === Constants::SKIN_NAME_MODERN
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-14 19:24:32 +00:00
|
|
|
/**
|
2023-04-10 18:56:19 +00:00
|
|
|
* @param RL\Context $context
|
2021-12-14 19:24:32 +00:00
|
|
|
* @param Config $config
|
|
|
|
* @return array
|
|
|
|
*/
|
2023-04-10 18:56:19 +00:00
|
|
|
public static function getActiveABTest(
|
|
|
|
RL\Context $context,
|
|
|
|
Config $config
|
|
|
|
) {
|
2021-12-14 19:24:32 +00:00
|
|
|
$ab = $config->get(
|
2022-03-17 23:02:39 +00:00
|
|
|
Constants::CONFIG_WEB_AB_TEST_ENROLLMENT
|
2021-12-14 19:24:32 +00:00
|
|
|
);
|
|
|
|
if ( count( $ab ) === 0 ) {
|
|
|
|
// If array is empty then no experiment and need to validate.
|
|
|
|
return $ab;
|
|
|
|
}
|
|
|
|
if ( !array_key_exists( 'buckets', $ab ) ) {
|
|
|
|
throw new RuntimeException( 'Invalid VectorWebABTestEnrollment value: Must contain buckets key.' );
|
|
|
|
}
|
|
|
|
if ( !array_key_exists( 'unsampled', $ab['buckets'] ) ) {
|
|
|
|
throw new RuntimeException( 'Invalid VectorWebABTestEnrollment value: Must define an `unsampled` bucket.' );
|
|
|
|
} else {
|
|
|
|
// check bucket values.
|
|
|
|
foreach ( $ab['buckets'] as $bucketName => $bucketDefinition ) {
|
|
|
|
if ( !is_array( $bucketDefinition ) ) {
|
|
|
|
throw new RuntimeException( 'Invalid VectorWebABTestEnrollment value: Buckets should be arrays' );
|
|
|
|
}
|
|
|
|
$samplingRate = $bucketDefinition['samplingRate'];
|
|
|
|
if ( is_string( $samplingRate ) ) {
|
|
|
|
throw new RuntimeException(
|
|
|
|
'Invalid VectorWebABTestEnrollment value: Sampling rate should be number between 0 and 1.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ab;
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:58:10 +00:00
|
|
|
/**
|
2021-06-30 12:51:04 +00:00
|
|
|
* Generates config variables for skins.vector.search Resource Loader module (defined in
|
|
|
|
* skin.json).
|
|
|
|
*
|
2022-05-25 05:12:31 +00:00
|
|
|
* @param RL\Context $context
|
2020-11-26 00:58:10 +00:00
|
|
|
* @param Config $config
|
2021-06-30 12:51:04 +00:00
|
|
|
* @return array<string,mixed>
|
2020-11-26 00:58:10 +00:00
|
|
|
*/
|
2022-02-01 20:52:16 +00:00
|
|
|
public static function getVectorSearchResourceLoaderConfig(
|
2022-05-25 05:12:31 +00:00
|
|
|
RL\Context $context,
|
2020-11-26 00:58:10 +00:00
|
|
|
Config $config
|
2021-06-30 12:51:04 +00:00
|
|
|
): array {
|
2023-06-02 10:56:22 +00:00
|
|
|
$vectorSearchConfig = [
|
|
|
|
'highlightQuery' =>
|
|
|
|
VectorServices::getLanguageService()->canWordsBeSplitSafely( $context->getLanguage() )
|
|
|
|
];
|
2021-06-30 12:51:04 +00:00
|
|
|
|
2023-10-04 09:31:15 +00:00
|
|
|
$hookRunner = new HookRunner( MediaWikiServices::getInstance()->getHookContainer() );
|
|
|
|
$hookRunner->onVectorSearchResourceLoaderConfig( $vectorSearchConfig );
|
2023-06-02 10:56:22 +00:00
|
|
|
|
|
|
|
return array_merge( $config->get( 'VectorWvuiSearchOptions' ), $vectorSearchConfig );
|
2020-11-26 00:58:10 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 13:07:09 +00:00
|
|
|
/**
|
|
|
|
* SkinPageReadyConfig hook handler
|
|
|
|
*
|
|
|
|
* Replace searchModule provided by skin.
|
|
|
|
*
|
|
|
|
* @since 1.35
|
2022-05-25 05:12:31 +00:00
|
|
|
* @param RL\Context $context
|
2020-07-14 13:07:09 +00:00
|
|
|
* @param mixed[] &$config Associative array of configurable options
|
|
|
|
* @return void This hook must not abort, it must return no value
|
|
|
|
*/
|
2021-01-02 13:11:04 +00:00
|
|
|
public function onSkinPageReadyConfig(
|
2022-05-25 05:12:31 +00:00
|
|
|
RL\Context $context,
|
2020-07-14 13:07:09 +00:00
|
|
|
array &$config
|
2021-01-02 13:11:04 +00:00
|
|
|
): void {
|
2020-07-14 13:07:09 +00:00
|
|
|
// It's better to exit before any additional check
|
2022-01-11 23:30:03 +00:00
|
|
|
if ( !self::isVectorSkin( $context->getSkin() ) ) {
|
2020-07-14 13:07:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the `mediawiki.page.ready` module not to wire up search.
|
2022-03-14 18:49:23 +00:00
|
|
|
// This allows us to use the new Vue implementation.
|
2022-05-25 05:12:31 +00:00
|
|
|
// Context has no knowledge of legacy / modern Vector
|
2020-07-14 13:07:09 +00:00
|
|
|
// and from its point of view they are the same thing.
|
|
|
|
// Please see the modules `skins.vector.js` and `skins.vector.legacy.js`
|
|
|
|
// for the wire up of search.
|
|
|
|
$config['search'] = false;
|
|
|
|
}
|
|
|
|
|
2021-05-07 21:56:29 +00:00
|
|
|
/**
|
2022-09-02 14:57:31 +00:00
|
|
|
* Moves watch item from actions to views menu.
|
2021-05-07 21:56:29 +00:00
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used inside Hooks::onSkinTemplateNavigation
|
2021-05-07 21:56:29 +00:00
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
|
|
|
private static function updateActionsMenu( &$content_navigation ) {
|
|
|
|
$key = null;
|
|
|
|
if ( isset( $content_navigation['actions']['watch'] ) ) {
|
|
|
|
$key = 'watch';
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['actions']['unwatch'] ) ) {
|
|
|
|
$key = 'unwatch';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Promote watch link from actions to views and add an icon
|
2022-10-07 00:23:00 +00:00
|
|
|
// The second check to isset is pointless but shuts up phan.
|
|
|
|
if ( $key !== null && isset( $content_navigation['actions'][ $key ] ) ) {
|
2021-06-30 22:55:09 +00:00
|
|
|
$content_navigation['views'][$key] = $content_navigation['actions'][$key];
|
2021-05-07 21:56:29 +00:00
|
|
|
unset( $content_navigation['actions'][$key] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 14:57:31 +00:00
|
|
|
/**
|
|
|
|
* Adds icons to items in the "views" menu.
|
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used inside Hooks::onSkinTemplateNavigation
|
2022-09-02 14:57:31 +00:00
|
|
|
* @param array &$content_navigation
|
|
|
|
* @param bool $isLegacy is this the legacy Vector skin?
|
|
|
|
*/
|
|
|
|
private static function updateViewsMenuIcons( &$content_navigation, $isLegacy ) {
|
2023-03-18 21:21:56 +00:00
|
|
|
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
|
2024-01-11 23:07:46 +00:00
|
|
|
foreach ( $content_navigation['views'] as &$item ) {
|
2022-09-02 14:57:31 +00:00
|
|
|
$icon = $item['icon'] ?? null;
|
|
|
|
if ( $icon ) {
|
2022-11-07 22:57:31 +00:00
|
|
|
if ( $isLegacy ) {
|
2022-09-02 14:57:31 +00:00
|
|
|
self::appendClassToItem(
|
|
|
|
$item['class'],
|
|
|
|
[ 'icon' ]
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Force the item as a button with hidden text.
|
|
|
|
$item['button'] = true;
|
|
|
|
$item['text-hidden'] = true;
|
2023-04-27 20:39:40 +00:00
|
|
|
$item = self::updateMenuItemData( $item, false );
|
2022-09-02 14:57:31 +00:00
|
|
|
}
|
2022-10-19 19:44:33 +00:00
|
|
|
} elseif ( !$isLegacy ) {
|
|
|
|
// The vector-tab-noicon class is only used in Vector-22.
|
2022-09-02 14:57:31 +00:00
|
|
|
self::appendClassToItem(
|
|
|
|
$item['class'],
|
|
|
|
[ 'vector-tab-noicon' ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All associated pages menu items do not have icons so are given the vector-tab-noicon class.
|
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used inside Hooks::onSkinTemplateNavigation
|
2022-09-02 14:57:31 +00:00
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
|
|
|
private static function updateAssociatedPagesMenuIcons( &$content_navigation ) {
|
2024-01-11 23:07:46 +00:00
|
|
|
foreach ( $content_navigation['associated-pages'] as &$item ) {
|
2022-09-02 14:57:31 +00:00
|
|
|
self::appendClassToItem(
|
|
|
|
$item['class'],
|
|
|
|
[ 'vector-tab-noicon' ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 22:55:09 +00:00
|
|
|
/**
|
2022-08-01 22:06:32 +00:00
|
|
|
* Adds class to a property
|
2021-06-30 22:55:09 +00:00
|
|
|
*
|
2024-01-11 23:07:46 +00:00
|
|
|
* @param array|string &$item to update
|
2022-08-01 22:06:32 +00:00
|
|
|
* @param array|string $classes to add to the item
|
2021-06-30 22:55:09 +00:00
|
|
|
*/
|
2022-08-01 22:06:32 +00:00
|
|
|
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;
|
2021-06-30 22:55:09 +00:00
|
|
|
} else {
|
2022-08-01 22:06:32 +00:00
|
|
|
// Treat as whatever $classes is
|
|
|
|
$item = $classes;
|
2021-06-30 22:55:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 22:06:32 +00:00
|
|
|
if ( is_string( $item ) ) {
|
|
|
|
$item = trim( $item );
|
|
|
|
}
|
2021-06-02 22:57:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 21:56:29 +00:00
|
|
|
/**
|
2022-01-18 19:13:34 +00:00
|
|
|
* Updates personal navigation menu (user links) dropdown for modern Vector:
|
|
|
|
* - Adds icons
|
|
|
|
* - Makes user page and watchlist collapsible
|
2021-05-07 21:56:29 +00:00
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used inside ::updateUserLinksItems
|
2021-05-07 21:56:29 +00:00
|
|
|
* @param SkinTemplate $sk
|
|
|
|
* @param array &$content_navigation
|
2023-02-01 23:38:44 +00:00
|
|
|
* @suppress PhanTypeInvalidDimOffset
|
2021-05-07 21:56:29 +00:00
|
|
|
*/
|
2022-01-18 19:13:34 +00:00
|
|
|
private static function updateUserLinksDropdownItems( $sk, &$content_navigation ) {
|
2021-08-24 21:34:59 +00:00
|
|
|
// For logged-in users in modern Vector, rearrange some links in the personal toolbar.
|
2022-03-28 21:22:50 +00:00
|
|
|
$user = $sk->getUser();
|
2024-01-11 23:07:46 +00:00
|
|
|
if ( $user->isRegistered() ) {
|
2022-03-04 01:52:44 +00:00
|
|
|
// Remove user page from personal menu dropdown for logged in use
|
2022-04-14 16:27:31 +00:00
|
|
|
$content_navigation['user-menu']['userpage']['collapsible'] = true;
|
2022-01-20 17:42:58 +00:00
|
|
|
// watchlist may be disabled if $wgGroupPermissions['*']['viewmywatchlist'] = false;
|
|
|
|
// See [[phab:T299671]]
|
2022-03-04 15:45:45 +00:00
|
|
|
if ( isset( $content_navigation['user-menu']['watchlist'] ) ) {
|
2022-04-14 16:27:31 +00:00
|
|
|
$content_navigation['user-menu']['watchlist']['collapsible'] = true;
|
2022-01-20 17:42:58 +00:00
|
|
|
}
|
2022-04-14 16:27:31 +00:00
|
|
|
|
2023-02-01 23:38:44 +00:00
|
|
|
// Anon editor links handled manually in new anon editor menu
|
|
|
|
$logoutMenu = [];
|
|
|
|
if ( isset( $content_navigation['user-menu']['logout'] ) ) {
|
|
|
|
$logoutMenu['logout'] = $content_navigation['user-menu']['logout'];
|
|
|
|
$logoutMenu['logout']['id'] = 'pt-logout';
|
|
|
|
unset( $content_navigation['user-menu']['logout'] );
|
|
|
|
}
|
|
|
|
$content_navigation['user-menu-logout'] = $logoutMenu;
|
|
|
|
|
2022-04-14 16:27:31 +00:00
|
|
|
self::updateMenuItems( $content_navigation, 'user-menu' );
|
2023-02-01 23:38:44 +00:00
|
|
|
self::updateMenuItems( $content_navigation, 'user-menu-logout' );
|
2024-01-11 23:07:46 +00:00
|
|
|
} else {
|
2023-02-01 23:38:44 +00:00
|
|
|
// Remove "Not logged in" from personal menu dropdown for anon users.
|
|
|
|
unset( $content_navigation['user-menu']['anonuserpage'] );
|
|
|
|
|
|
|
|
// Make login and create account collapsible
|
2023-03-08 19:50:20 +00:00
|
|
|
if ( isset( $content_navigation['user-menu']['login'] ) ) {
|
|
|
|
$content_navigation['user-menu']['login']['collapsible'] = true;
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['user-menu']['login-private'] ) ) {
|
|
|
|
$content_navigation['user-menu']['login-private']['collapsible'] = true;
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['user-menu']['createaccount'] ) ) {
|
|
|
|
$content_navigation['user-menu']['createaccount']['collapsible'] = true;
|
|
|
|
}
|
2024-10-15 23:07:29 +00:00
|
|
|
if ( isset( $content_navigation['user-menu']['sitesupport'] ) ) {
|
|
|
|
$content_navigation['user-menu']['sitesupport']['collapsible'] = true;
|
|
|
|
}
|
2023-02-01 23:38:44 +00:00
|
|
|
|
|
|
|
// Anon editor links handled manually in new anon editor menu
|
|
|
|
$anonEditorMenu = [];
|
|
|
|
if ( isset( $content_navigation['user-menu']['anoncontribs'] ) ) {
|
|
|
|
$anonEditorMenu['anoncontribs'] = $content_navigation['user-menu']['anoncontribs'];
|
|
|
|
$anonEditorMenu['anoncontribs']['id'] = 'pt-anoncontribs';
|
|
|
|
unset( $content_navigation['user-menu']['anoncontribs'] );
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['user-menu']['anontalk'] ) ) {
|
|
|
|
$anonEditorMenu['anontalk'] = $content_navigation['user-menu']['anontalk'];
|
|
|
|
$anonEditorMenu['anontalk']['id'] = 'pt-anontalk';
|
|
|
|
unset( $content_navigation['user-menu']['anontalk'] );
|
|
|
|
}
|
|
|
|
$content_navigation['user-menu-anon-editor'] = $anonEditorMenu;
|
|
|
|
|
|
|
|
// Only show icons for anon menu items (login and create account).
|
|
|
|
self::updateMenuItems( $content_navigation, 'user-menu' );
|
2021-08-24 21:34:59 +00:00
|
|
|
}
|
2022-01-18 19:13:34 +00:00
|
|
|
}
|
2021-06-02 22:57:43 +00:00
|
|
|
|
2022-03-04 20:24:10 +00:00
|
|
|
/**
|
2023-11-08 01:01:59 +00:00
|
|
|
* Echo has styles that control icons rendering in places we don't want them.
|
|
|
|
* This code works around T343838.
|
2022-03-04 20:24:10 +00:00
|
|
|
*
|
2022-04-19 17:50:01 +00:00
|
|
|
* @param SkinTemplate $sk
|
2022-03-04 20:24:10 +00:00
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
2023-11-08 01:01:59 +00:00
|
|
|
private static function fixEcho( $sk, &$content_navigation ) {
|
2022-04-19 17:50:01 +00:00
|
|
|
if ( isset( $content_navigation['notifications'] ) ) {
|
2024-01-11 23:07:46 +00:00
|
|
|
foreach ( $content_navigation['notifications'] as &$item ) {
|
|
|
|
$icon = $item['icon'] ?? null;
|
2022-11-07 22:57:31 +00:00
|
|
|
if ( $icon ) {
|
2024-01-11 23:07:46 +00:00
|
|
|
$linkClass = $item['link-class'] ?? [];
|
2022-09-14 23:30:25 +00:00
|
|
|
$newLinkClass = [
|
2022-09-14 22:24:36 +00:00
|
|
|
// Allows Echo to react to clicks
|
|
|
|
'mw-echo-notification-badge-nojs'
|
|
|
|
];
|
2022-09-14 23:30:25 +00:00
|
|
|
if ( in_array( 'mw-echo-unseen-notifications', $linkClass ) ) {
|
|
|
|
$newLinkClass[] = 'mw-echo-unseen-notifications';
|
|
|
|
}
|
|
|
|
$item['link-class'] = $newLinkClass;
|
2022-09-14 22:24:36 +00:00
|
|
|
}
|
2022-04-19 17:50:01 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-04 20:24:10 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 19:13:34 +00:00
|
|
|
/**
|
|
|
|
* Updates personal navigation menu (user links) for modern Vector wherein user page, create account and login links
|
|
|
|
* are removed from the dropdown to be handled separately. In legacy Vector, the custom "user-page" bucket is
|
|
|
|
* removed to preserve existing behavior.
|
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used inside Hooks::onSkinTemplateNavigation
|
2022-01-18 19:13:34 +00:00
|
|
|
* @param SkinTemplate $sk
|
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
|
|
|
private static function updateUserLinksItems( $sk, &$content_navigation ) {
|
2022-03-04 20:24:10 +00:00
|
|
|
$skinName = $sk->getSkinName();
|
|
|
|
if ( self::isSkinVersionLegacy( $skinName ) ) {
|
|
|
|
// Remove user page from personal toolbar since it will be inside the personal menu for logged-in
|
|
|
|
// users in legacy Vector.
|
|
|
|
unset( $content_navigation['user-page'] );
|
|
|
|
} else {
|
2023-11-08 01:01:59 +00:00
|
|
|
self::fixEcho( $sk, $content_navigation );
|
2022-04-19 17:50:01 +00:00
|
|
|
self::updateUserLinksDropdownItems( $sk, $content_navigation );
|
2021-05-07 21:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 23:44:18 +00:00
|
|
|
/**
|
|
|
|
* Modifies list item to make it collapsible.
|
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used in ::updateItemData and ::createMoreOverflowMenu
|
2022-01-12 23:44:18 +00:00
|
|
|
* @param array &$item
|
2022-04-27 19:32:19 +00:00
|
|
|
* @param string $prefix defaults to user-links-
|
2022-01-12 23:44:18 +00:00
|
|
|
*/
|
2022-04-27 19:32:19 +00:00
|
|
|
private static function makeMenuItemCollapsible( array &$item, string $prefix = 'user-links-' ) {
|
2024-01-11 23:07:46 +00:00
|
|
|
$collapseMenuItemClass = $prefix . 'collapsible-item';
|
|
|
|
self::appendClassToItem( $item[ 'class' ], $collapseMenuItemClass );
|
2022-01-12 23:44:18 +00:00
|
|
|
}
|
|
|
|
|
2021-08-26 19:47:02 +00:00
|
|
|
/**
|
|
|
|
* Make an icon
|
|
|
|
*
|
|
|
|
* @internal for use inside Vector skin.
|
|
|
|
* @param string $name
|
|
|
|
* @return string of HTML
|
|
|
|
*/
|
2024-03-03 18:50:53 +00:00
|
|
|
private static function makeIcon( $name ) {
|
2021-08-26 19:47:02 +00:00
|
|
|
// Html::makeLink will pass this through rawElement
|
2023-04-27 20:39:40 +00:00
|
|
|
return '<span class="vector-icon mw-ui-icon-' . $name . ' mw-ui-icon-wikimedia-' . $name . '"></span>';
|
2022-04-14 16:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-08-01 22:06:32 +00:00
|
|
|
* Update template data to include classes and html that handle buttons, icons, and collapsible items.
|
2022-04-14 16:27:31 +00:00
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used in ::updateMenuItemData
|
2022-08-01 22:06:32 +00:00
|
|
|
* @param array $item data to update
|
|
|
|
* @param string $buttonClassProp property to append button classes
|
|
|
|
* @param string $iconHtmlProp property to set icon HTML
|
2023-05-02 19:03:13 +00:00
|
|
|
* @param bool $unsetIcon should the icon field be unset?
|
2022-08-01 22:06:32 +00:00
|
|
|
* @return array $item Updated data
|
2022-04-14 16:27:31 +00:00
|
|
|
*/
|
2023-05-02 19:03:13 +00:00
|
|
|
private static function updateItemData(
|
2023-04-27 20:39:40 +00:00
|
|
|
$item, $buttonClassProp, $iconHtmlProp, $unsetIcon = true
|
2023-05-02 19:03:13 +00:00
|
|
|
) {
|
2022-04-14 16:27:31 +00:00
|
|
|
$hasButton = $item['button'] ?? false;
|
|
|
|
$hideText = $item['text-hidden'] ?? false;
|
|
|
|
$isCollapsible = $item['collapsible'] ?? false;
|
|
|
|
$icon = $item['icon'] ?? '';
|
2023-05-02 19:03:13 +00:00
|
|
|
if ( $unsetIcon ) {
|
|
|
|
unset( $item['icon'] );
|
|
|
|
}
|
2022-04-14 16:27:31 +00:00
|
|
|
unset( $item['button'] );
|
|
|
|
unset( $item['text-hidden'] );
|
|
|
|
unset( $item['collapsible'] );
|
2022-08-01 22:06:32 +00:00
|
|
|
|
2022-04-14 16:27:31 +00:00
|
|
|
if ( $isCollapsible ) {
|
|
|
|
self::makeMenuItemCollapsible( $item );
|
|
|
|
}
|
|
|
|
if ( $hasButton ) {
|
2023-04-27 20:39:40 +00:00
|
|
|
// Hardcoded button classes, this should be fixed by replacing Hooks.php with VectorComponentButton.php
|
|
|
|
self::appendClassToItem( $item[ $buttonClassProp ], [
|
|
|
|
'cdx-button',
|
|
|
|
'cdx-button--fake-button',
|
|
|
|
'cdx-button--fake-button--enabled',
|
|
|
|
'cdx-button--weight-quiet'
|
|
|
|
] );
|
2022-04-14 16:27:31 +00:00
|
|
|
}
|
|
|
|
if ( $icon ) {
|
2023-04-27 20:39:40 +00:00
|
|
|
if ( $hideText && $hasButton ) {
|
|
|
|
self::appendClassToItem( $item[ $buttonClassProp ], [ 'cdx-button--icon-only' ] );
|
2022-04-14 16:27:31 +00:00
|
|
|
}
|
2023-04-27 20:39:40 +00:00
|
|
|
|
|
|
|
$item[ $iconHtmlProp ] = self::makeIcon( $icon );
|
2022-04-14 16:27:31 +00:00
|
|
|
}
|
|
|
|
return $item;
|
2021-08-26 19:47:02 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 22:06:32 +00:00
|
|
|
/**
|
|
|
|
* Updates template data for Vector menu items.
|
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used inside Hooks::updateMenuItems ::updateViewsMenuIcons and ::updateUserLinksDropdownItems
|
2022-08-01 22:06:32 +00:00
|
|
|
* @param array $item menu item data to update
|
2023-05-02 19:03:13 +00:00
|
|
|
* @param bool $unsetIcon should the icon field be unset?
|
2022-08-01 22:06:32 +00:00
|
|
|
* @return array $item Updated menu item data
|
|
|
|
*/
|
2024-03-03 18:50:53 +00:00
|
|
|
private static function updateMenuItemData( $item, $unsetIcon = true ) {
|
2022-08-01 22:06:32 +00:00
|
|
|
$buttonClassProp = 'link-class';
|
|
|
|
$iconHtmlProp = 'link-html';
|
2023-04-27 20:39:40 +00:00
|
|
|
return self::updateItemData( $item, $buttonClassProp, $iconHtmlProp, $unsetIcon );
|
2022-08-01 22:06:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-26 19:47:02 +00:00
|
|
|
/**
|
|
|
|
* Updates user interface preferences for modern Vector to upgrade icon/button menu items.
|
|
|
|
*
|
|
|
|
* @param array &$content_navigation
|
|
|
|
* @param string $menu identifier
|
|
|
|
*/
|
2021-12-14 18:12:26 +00:00
|
|
|
private static function updateMenuItems( &$content_navigation, $menu ) {
|
2024-01-11 23:07:46 +00:00
|
|
|
foreach ( $content_navigation[$menu] as &$item ) {
|
|
|
|
$item = self::updateMenuItemData( $item );
|
2021-08-26 19:47:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 19:32:19 +00:00
|
|
|
/**
|
|
|
|
* Vector 2022 only:
|
|
|
|
* Creates an additional menu that will be injected inside the more (cactions)
|
|
|
|
* dropdown menu. This menu is a clone of `views` and this menu will only be
|
|
|
|
* shown at low resolutions (when the `views` menu is hidden).
|
|
|
|
*
|
|
|
|
* An additional menu is used instead of adding to the existing cactions menu
|
|
|
|
* so that the emptyPortlet logic for that menu is preserved and the cactions menu
|
|
|
|
* is not shown at large resolutions when empty (e.g. all items including collapsed
|
|
|
|
* items are hidden).
|
|
|
|
*
|
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
|
|
|
private static function createMoreOverflowMenu( &$content_navigation ) {
|
|
|
|
$clonedViews = [];
|
2024-01-11 23:07:46 +00:00
|
|
|
foreach ( $content_navigation['views'] ?? [] as $key => $item ) {
|
|
|
|
$newItem = $item;
|
2022-04-27 19:32:19 +00:00
|
|
|
self::makeMenuItemCollapsible(
|
|
|
|
$newItem,
|
|
|
|
'vector-more-'
|
|
|
|
);
|
|
|
|
$clonedViews['more-' . $key] = $newItem;
|
|
|
|
}
|
|
|
|
// Inject collapsible menu items ahead of existing actions.
|
|
|
|
$content_navigation['views-overflow'] = $clonedViews;
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:09:21 +00:00
|
|
|
/**
|
|
|
|
* Upgrades Vector's watch action to a watchstar.
|
2021-07-28 18:20:07 +00:00
|
|
|
* This is invoked inside SkinVector, not via skin registration, as skin hooks
|
|
|
|
* are not guaranteed to run last.
|
|
|
|
* This can possibly be revised based on the outcome of T287622.
|
2020-05-11 22:09:21 +00:00
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation
|
|
|
|
* @param SkinTemplate $sk
|
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
|
|
|
public static function onSkinTemplateNavigation( $sk, &$content_navigation ) {
|
2022-02-02 21:52:17 +00:00
|
|
|
$skinName = $sk->getSkinName();
|
2022-09-02 14:57:31 +00:00
|
|
|
// These changes should only happen in Vector.
|
|
|
|
if ( !$skinName || !self::isVectorSkin( $skinName ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-11 22:09:21 +00:00
|
|
|
|
2024-01-11 23:07:46 +00:00
|
|
|
$title = $sk->getRelevantTitle();
|
2022-09-02 14:57:31 +00:00
|
|
|
if (
|
|
|
|
$sk->getConfig()->get( 'VectorUseIconWatch' ) &&
|
|
|
|
$title && $title->canExist()
|
|
|
|
) {
|
|
|
|
self::updateActionsMenu( $content_navigation );
|
2020-05-11 22:09:21 +00:00
|
|
|
}
|
2022-09-02 14:57:31 +00:00
|
|
|
|
|
|
|
self::updateUserLinksItems( $sk, $content_navigation );
|
2022-04-27 19:32:19 +00:00
|
|
|
if ( $skinName === Constants::SKIN_NAME_MODERN ) {
|
|
|
|
self::createMoreOverflowMenu( $content_navigation );
|
|
|
|
}
|
2022-09-02 14:57:31 +00:00
|
|
|
|
|
|
|
// The updating of the views menu happens /after/ the overflow menu has been created
|
|
|
|
// this avoids icons showing in the more overflow menu.
|
|
|
|
self::updateViewsMenuIcons( $content_navigation, self::isSkinVersionLegacy( $skinName ) );
|
|
|
|
self::updateAssociatedPagesMenuIcons( $content_navigation );
|
2020-05-11 22:09:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 18:21:12 +00:00
|
|
|
/**
|
2023-03-29 15:54:37 +00:00
|
|
|
* Adds Vector specific user preferences that can only be accessed via API.
|
2022-04-14 18:21:12 +00:00
|
|
|
*
|
|
|
|
* @param User $user User whose preferences are being modified.
|
|
|
|
* @param array[] &$prefs Preferences description array, to be fed to a HTMLForm object.
|
|
|
|
*/
|
2021-01-02 13:11:04 +00:00
|
|
|
public function onGetPreferences( $user, &$prefs ): void {
|
2024-06-18 22:10:42 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$featureManagerFactory = $services->getService( 'Vector.FeatureManagerFactory' );
|
|
|
|
$featureManager = $featureManagerFactory->createFeatureManager( RequestContext::getMain() );
|
|
|
|
$isNightModeEnabled = $featureManager->isFeatureEnabled( Constants::FEATURE_NIGHT_MODE );
|
|
|
|
|
2022-04-14 18:21:12 +00:00
|
|
|
$vectorPrefs = [
|
2024-06-06 02:17:00 +00:00
|
|
|
Constants::PREF_KEY_LIMITED_WIDTH => [
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'vector-prefs-limited-width',
|
|
|
|
'section' => 'rendering/skin/skin-prefs',
|
|
|
|
'help-message' => 'vector-prefs-limited-width-help',
|
|
|
|
'hide-if' => [ '!==', 'skin', Constants::SKIN_NAME_MODERN ],
|
|
|
|
],
|
2023-09-20 22:48:26 +00:00
|
|
|
Constants::PREF_KEY_FONT_SIZE => [
|
2024-07-30 20:29:53 +00:00
|
|
|
'type' => 'select',
|
2024-06-06 02:17:00 +00:00
|
|
|
'label-message' => 'vector-feature-custom-font-size-name',
|
|
|
|
'section' => 'rendering/skin/skin-prefs',
|
|
|
|
'options-messages' => [
|
|
|
|
'vector-feature-custom-font-size-0-label' => '0',
|
|
|
|
'vector-feature-custom-font-size-1-label' => '1',
|
|
|
|
'vector-feature-custom-font-size-2-label' => '2',
|
|
|
|
],
|
|
|
|
'hide-if' => [ '!==', 'skin', Constants::SKIN_NAME_MODERN ],
|
2023-09-20 22:48:26 +00:00
|
|
|
],
|
2022-12-07 22:15:31 +00:00
|
|
|
Constants::PREF_KEY_PAGE_TOOLS_PINNED => [
|
|
|
|
'type' => 'api'
|
2022-04-14 18:21:12 +00:00
|
|
|
],
|
2022-12-15 22:52:24 +00:00
|
|
|
Constants::PREF_KEY_MAIN_MENU_PINNED => [
|
|
|
|
'type' => 'api'
|
|
|
|
],
|
2023-02-23 21:23:46 +00:00
|
|
|
Constants::PREF_KEY_TOC_PINNED => [
|
|
|
|
'type' => 'api'
|
|
|
|
],
|
2024-04-12 03:27:34 +00:00
|
|
|
Constants::PREF_KEY_APPEARANCE_PINNED => [
|
2023-11-21 17:01:04 +00:00
|
|
|
'type' => 'api'
|
|
|
|
],
|
2024-06-06 02:17:00 +00:00
|
|
|
Constants::PREF_KEY_NIGHT_MODE => [
|
2024-06-18 22:10:42 +00:00
|
|
|
'type' => $isNightModeEnabled ? 'select' : 'api',
|
2024-06-06 02:17:00 +00:00
|
|
|
'label-message' => 'skin-theme-name',
|
|
|
|
'help-message' => 'skin-theme-description',
|
2022-10-17 08:43:26 +00:00
|
|
|
'section' => 'rendering/skin/skin-prefs',
|
2024-06-06 02:17:00 +00:00
|
|
|
'options-messages' => [
|
|
|
|
'skin-theme-day-label' => 'day',
|
|
|
|
'skin-theme-night-label' => 'night',
|
|
|
|
'skin-theme-os-label' => 'os',
|
|
|
|
],
|
2022-10-18 01:15:50 +00:00
|
|
|
'hide-if' => [ '!==', 'skin', Constants::SKIN_NAME_MODERN ],
|
2023-08-30 22:12:03 +00:00
|
|
|
],
|
2022-04-14 18:21:12 +00:00
|
|
|
];
|
|
|
|
$prefs += $vectorPrefs;
|
|
|
|
}
|
|
|
|
|
[Special:Preferences] [PHP] Add skin version user preference and configs
Add a Vector-specific user preference to Special:Preferences for
toggling skin version, either Legacy Vector or the latest Vector.
The presentation of the new preference section and the default values
for anonymous, new, and existing accounts are configurable via
$wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by
the feature manager in T244481),
$wgVectorDefaultSkinVersionForExistingAccounts, and
$wgVectorDefaultSkinVersionForNewAccounts. These configurations default
to the fullest experience so that third-party configuration is minimal.
See skin.json for details. The configurations are each tested in
VectorHooksTest.php.
When presentation is enabled, the new preference appears as a checkbox;
enabled is Legacy mode and disable is latest. There are a number of
unfortunate details:
- Showing and hiding a checkbox is supported by OOUI. Showing and hiding
a whole section (Vector skin preferences, in this case) is not so this
additional client JavaScript functionality is added in Core (see
Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377).
- Stylization as a checkbox is wanted. However, the implied storage type
for OOUI checkboxes is a boolean. This is not wanted in the event that
another skin version is added (e.g., '3' or 'alpha'). As a workaround,
the preference is converted from a boolean to a version string ('1' or
'2') on save in Hooks::onPreferencesFormPreSave() and from a version
string to a checkbox enable / disable string ('1' or '0') in
onGetPreferences(). There a number of test cases to help cover these
concerning details.
Documentation for overriding the skin version as a URL query parameter
is provided in anticipation of T244481.
Bug: T242381
Bug: T245793
Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377
Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22
Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
|
|
|
/**
|
|
|
|
* Called one time when initializing a users preferences for a newly created account.
|
|
|
|
*
|
|
|
|
* @param User $user Newly created user object.
|
|
|
|
* @param bool $isAutoCreated
|
|
|
|
*/
|
2021-01-02 13:11:04 +00:00
|
|
|
public function onLocalUserCreated( $user, $isAutoCreated ) {
|
2024-02-27 19:33:12 +00:00
|
|
|
$default = $this->config->get( Constants::CONFIG_KEY_DEFAULT_SKIN_VERSION_FOR_NEW_ACCOUNTS );
|
2022-03-31 03:47:57 +00:00
|
|
|
if ( $default ) {
|
2024-02-27 19:33:12 +00:00
|
|
|
$this->userOptionsManager->setOption(
|
2022-03-31 03:47:57 +00:00
|
|
|
$user,
|
|
|
|
Constants::PREF_KEY_SKIN,
|
|
|
|
$default === Constants::SKIN_VERSION_LEGACY ?
|
|
|
|
Constants::SKIN_NAME_LEGACY : Constants::SKIN_NAME_MODERN
|
|
|
|
);
|
|
|
|
}
|
[Special:Preferences] [PHP] Add skin version user preference and configs
Add a Vector-specific user preference to Special:Preferences for
toggling skin version, either Legacy Vector or the latest Vector.
The presentation of the new preference section and the default values
for anonymous, new, and existing accounts are configurable via
$wgVectorShowSkinPreferences, $wgVectorDefaultSkinVersion (to be used by
the feature manager in T244481),
$wgVectorDefaultSkinVersionForExistingAccounts, and
$wgVectorDefaultSkinVersionForNewAccounts. These configurations default
to the fullest experience so that third-party configuration is minimal.
See skin.json for details. The configurations are each tested in
VectorHooksTest.php.
When presentation is enabled, the new preference appears as a checkbox;
enabled is Legacy mode and disable is latest. There are a number of
unfortunate details:
- Showing and hiding a checkbox is supported by OOUI. Showing and hiding
a whole section (Vector skin preferences, in this case) is not so this
additional client JavaScript functionality is added in Core (see
Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377).
- Stylization as a checkbox is wanted. However, the implied storage type
for OOUI checkboxes is a boolean. This is not wanted in the event that
another skin version is added (e.g., '3' or 'alpha'). As a workaround,
the preference is converted from a boolean to a version string ('1' or
'2') on save in Hooks::onPreferencesFormPreSave() and from a version
string to a checkbox enable / disable string ('1' or '0') in
onGetPreferences(). There a number of test cases to help cover these
concerning details.
Documentation for overriding the skin version as a URL query parameter
is provided in anticipation of T244481.
Bug: T242381
Bug: T245793
Depends-On: Iaf68b238a8ac7a4fb22b9ef5d6c5a3394ee2e377
Depends-On: Ifc2863fca9cd9efd11ac30c780420e8d89e8cb22
Change-Id: I177dad88fc982170641059b6a4f53fbb38eefad6
2020-01-23 21:53:09 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 15:05:06 +00:00
|
|
|
/**
|
|
|
|
* Gets whether the current skin version is the legacy version.
|
|
|
|
*
|
2022-02-02 21:52:17 +00:00
|
|
|
* @param string $skinName hint that can be used to detect modern vector.
|
2020-08-12 15:05:06 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2022-01-20 22:14:19 +00:00
|
|
|
private static function isSkinVersionLegacy( $skinName ): bool {
|
2022-04-01 15:53:03 +00:00
|
|
|
return $skinName === Constants::SKIN_NAME_LEGACY;
|
2020-08-12 15:05:06 +00:00
|
|
|
}
|
2023-10-18 17:32:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register Vector 2022 beta feature to the beta features list
|
|
|
|
*
|
|
|
|
* @param User $user User the preferences are for
|
|
|
|
* @param array &$betaFeatures
|
|
|
|
*/
|
|
|
|
public function onGetBetaFeaturePreferences( User $user, array &$betaFeatures ) {
|
2024-01-11 23:07:46 +00:00
|
|
|
$skinName = RequestContext::getMain()->getSkinName();
|
2023-10-18 17:32:16 +00:00
|
|
|
// Only Vector 2022 is supported for beta features
|
|
|
|
if ( $skinName !== Constants::SKIN_NAME_MODERN ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Only add Vector 2022 beta feature if there is at least one beta feature present in config
|
|
|
|
$configHasBeta = false;
|
|
|
|
foreach ( Constants::VECTOR_BETA_FEATURES as $featureName ) {
|
2024-02-27 19:33:12 +00:00
|
|
|
if ( $this->config->has( $featureName ) && $this->config->get( $featureName )[ 'beta' ] === true ) {
|
2023-10-18 17:32:16 +00:00
|
|
|
$configHasBeta = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !$configHasBeta ) {
|
|
|
|
return;
|
|
|
|
}
|
2024-02-27 19:33:12 +00:00
|
|
|
$skinsAssetsPath = $this->config->get( 'StylePath' );
|
2023-11-07 17:47:38 +00:00
|
|
|
$imagesDir = "$skinsAssetsPath/Vector/resources/images";
|
2023-10-18 17:32:16 +00:00
|
|
|
$betaFeatures[ Constants::VECTOR_2022_BETA_KEY ] = [
|
|
|
|
'label-message' => 'vector-2022-beta-preview-label',
|
|
|
|
'desc-message' => 'vector-2022-beta-preview-description',
|
|
|
|
'screenshot' => [
|
|
|
|
// follow up work to add images is required in T349321
|
2023-11-07 17:47:38 +00:00
|
|
|
'ltr' => "$imagesDir/vector-2022-beta-preview-ltr.svg",
|
|
|
|
'rtl' => "$imagesDir/vector-2022-beta-preview-rtl.svg",
|
2023-10-18 17:32:16 +00:00
|
|
|
],
|
2023-12-06 15:52:28 +00:00
|
|
|
'info-link' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/Reading/Web/Accessibility_for_reading',
|
|
|
|
'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:Reading/Web/Accessibility_for_reading',
|
2023-10-18 17:32:16 +00:00
|
|
|
];
|
|
|
|
}
|
2017-06-30 19:21:16 +00:00
|
|
|
}
|