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
|
|
|
|
2020-07-14 13:07:09 +00:00
|
|
|
use Config;
|
2022-08-04 21:11:54 +00:00
|
|
|
use IContextSource;
|
2021-01-02 13:11:04 +00:00
|
|
|
use MediaWiki\Auth\Hook\LocalUserCreatedHook;
|
|
|
|
use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
|
2022-08-04 21:11:54 +00:00
|
|
|
use MediaWiki\Hook\RequestContextCreateSkinHook;
|
[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\ResourceLoader\Hook\ResourceLoaderSiteModulePagesHook;
|
|
|
|
use MediaWiki\ResourceLoader\Hook\ResourceLoaderSiteStylesModulePagesHook;
|
|
|
|
use MediaWiki\Skins\Hook\SkinPageReadyConfigHook;
|
2018-03-12 23:52:48 +00:00
|
|
|
use OutputPage;
|
2021-12-14 19:24:32 +00:00
|
|
|
use RuntimeException;
|
2020-06-18 12:52:00 +00:00
|
|
|
use Skin;
|
2018-03-12 23:52:48 +00:00
|
|
|
use SkinTemplate;
|
[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 User;
|
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,
|
|
|
|
MakeGlobalVariablesScriptHook,
|
|
|
|
ResourceLoaderSiteModulePagesHook,
|
|
|
|
ResourceLoaderSiteStylesModulePagesHook,
|
2022-08-04 21:11:54 +00:00
|
|
|
RequestContextCreateSkinHook,
|
2022-10-18 01:15:50 +00:00
|
|
|
SkinPageReadyConfigHook
|
2021-01-02 13:11:04 +00:00
|
|
|
{
|
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
|
|
|
/**
|
|
|
|
* @param Config $config
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private static function getActiveABTest( $config ) {
|
|
|
|
$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-07-14 13:07:09 +00:00
|
|
|
/**
|
|
|
|
* Passes config variables to Vector (modern) ResourceLoader module.
|
2022-05-25 05:12:31 +00:00
|
|
|
* @param RL\Context $context
|
2020-07-14 13:07:09 +00:00
|
|
|
* @param Config $config
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getVectorResourceLoaderConfig(
|
2022-05-25 05:12:31 +00:00
|
|
|
RL\Context $context,
|
2020-07-14 13:07:09 +00:00
|
|
|
Config $config
|
|
|
|
) {
|
|
|
|
return [
|
2022-10-06 00:38:38 +00:00
|
|
|
'wgVectorSearchApiUrl' => $config->get( 'VectorSearchApiUrl' ),
|
2021-12-14 19:24:32 +00:00
|
|
|
'wgVectorWebABTestEnrollment' => self::getActiveABTest( $config ),
|
2020-07-14 13:07:09 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
$result = $config->get( 'VectorWvuiSearchOptions' );
|
|
|
|
$result['highlightQuery'] =
|
|
|
|
VectorServices::getLanguageService()->canWordsBeSplitSafely( $context->getLanguage() );
|
|
|
|
|
|
|
|
return $result;
|
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.
|
|
|
|
// The related method self::getVectorResourceLoaderConfig handles which
|
|
|
|
// search to load.
|
|
|
|
$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 ) {
|
|
|
|
$featureManager = VectorServices::getFeatureManager();
|
|
|
|
|
2023-03-18 21:21:56 +00:00
|
|
|
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
|
2022-09-02 14:57:31 +00:00
|
|
|
foreach ( $content_navigation['views'] as $key => $item ) {
|
|
|
|
$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;
|
|
|
|
$item = self::updateMenuItemData( $item, true );
|
|
|
|
}
|
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' ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$content_navigation['views'][$key] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ) {
|
|
|
|
foreach ( $content_navigation['associated-pages'] as $key => $item ) {
|
|
|
|
self::appendClassToItem(
|
|
|
|
$item['class'],
|
|
|
|
[ 'vector-tab-noicon' ]
|
|
|
|
);
|
|
|
|
$content_navigation['associated-pages'][$key] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2022-08-01 22:06:32 +00:00
|
|
|
* @param array &$item to update
|
|
|
|
* @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();
|
2022-03-04 01:52:44 +00:00
|
|
|
$isRegistered = $user->isRegistered();
|
2023-02-03 00:35:07 +00:00
|
|
|
if ( $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' );
|
2022-03-04 01:52:44 +00:00
|
|
|
}
|
2022-04-14 16:27:31 +00:00
|
|
|
|
2023-02-03 00:35:07 +00:00
|
|
|
if ( !$isRegistered ) {
|
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;
|
|
|
|
}
|
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
|
|
|
/**
|
2022-04-19 17:50:01 +00:00
|
|
|
* Populates 'vector-user-menu-overflow' bucket for modern Vector with modified personal navigation (user links)
|
|
|
|
* menu items, including 'notification', 'user-interface-preferences', 'user-page', 'vector-user-menu-overflow'
|
2022-03-04 20:24:10 +00:00
|
|
|
*
|
2023-01-06 23:15:45 +00:00
|
|
|
* @internal used inside ::updateUserLinksItems
|
2022-04-19 17:50:01 +00:00
|
|
|
* @param SkinTemplate $sk
|
2022-03-04 20:24:10 +00:00
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
2022-04-19 17:50:01 +00:00
|
|
|
private static function updateUserLinksOverflowItems( $sk, &$content_navigation ) {
|
|
|
|
$overflow = 'vector-user-menu-overflow';
|
|
|
|
$content_navigation[$overflow] = [];
|
2022-09-14 22:24:36 +00:00
|
|
|
$featureManager = VectorServices::getFeatureManager();
|
2022-04-19 17:50:01 +00:00
|
|
|
|
|
|
|
// Logged in and logged out overflow items
|
2022-03-04 20:24:10 +00:00
|
|
|
if ( isset( $content_navigation['user-interface-preferences']['uls'] ) ) {
|
2022-04-19 17:50:01 +00:00
|
|
|
$content_navigation[$overflow]['uls'] = array_merge(
|
|
|
|
$content_navigation['user-interface-preferences']['uls'], [
|
2022-03-04 20:24:10 +00:00
|
|
|
'collapsible' => true,
|
2022-04-19 17:50:01 +00:00
|
|
|
] );
|
2022-03-04 20:24:10 +00:00
|
|
|
}
|
2022-04-19 17:50:01 +00:00
|
|
|
|
|
|
|
// Logged in overflow items
|
2022-03-04 20:24:10 +00:00
|
|
|
if ( isset( $content_navigation['user-page']['userpage'] ) ) {
|
2022-04-19 17:50:01 +00:00
|
|
|
$content_navigation[$overflow]['userpage'] = array_merge(
|
|
|
|
$content_navigation['user-page']['userpage'], [
|
2022-08-04 13:14:11 +00:00
|
|
|
// T312157: Style the userpage link as a blue link rather than a quiet button.
|
|
|
|
'button' => false,
|
2022-03-04 20:24:10 +00:00
|
|
|
'collapsible' => true,
|
2022-04-19 17:50:01 +00:00
|
|
|
// Remove icon
|
|
|
|
'icon' => '',
|
2022-03-04 20:24:10 +00:00
|
|
|
] );
|
|
|
|
}
|
2022-04-19 17:50:01 +00:00
|
|
|
if ( isset( $content_navigation['notifications'] ) ) {
|
|
|
|
foreach ( $content_navigation['notifications'] as $key => $data ) {
|
|
|
|
$content_navigation[$overflow][$key] = $data;
|
2022-09-14 23:30:25 +00:00
|
|
|
$icon = $data['icon'] ?? null;
|
2022-11-07 22:57:31 +00:00
|
|
|
if ( $icon ) {
|
2022-11-07 22:49:24 +00:00
|
|
|
$linkClass = $content_navigation[$overflow][$key]['link-class'] ?? [];
|
2022-09-14 23:30:25 +00:00
|
|
|
$item = $content_navigation[$overflow][$key];
|
|
|
|
$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['button'] = true;
|
|
|
|
$item['text-hidden'] = true;
|
|
|
|
$item['link-class'] = $newLinkClass;
|
|
|
|
$content_navigation[$overflow][$key] = $item;
|
2022-09-14 22:24:36 +00:00
|
|
|
}
|
2022-04-19 17:50:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['user-menu']['watchlist'] ) ) {
|
|
|
|
$content_navigation[$overflow]['watchlist'] = array_merge(
|
|
|
|
$content_navigation['user-menu']['watchlist'], [
|
|
|
|
'id' => 'pt-watchlist-2',
|
2022-03-04 20:24:10 +00:00
|
|
|
'button' => true,
|
|
|
|
'collapsible' => true,
|
|
|
|
'text-hidden' => true,
|
2022-04-19 17:50:01 +00:00
|
|
|
] );
|
2022-03-04 20:24:10 +00:00
|
|
|
}
|
2022-04-19 17:50:01 +00:00
|
|
|
|
|
|
|
// Anon/temp overflow items
|
2023-02-03 00:35:07 +00:00
|
|
|
if ( isset( $content_navigation['user-menu']['createaccount'] ) ) {
|
2022-04-19 17:50:01 +00:00
|
|
|
$content_navigation[$overflow]['createaccount'] = array_merge(
|
|
|
|
$content_navigation['user-menu']['createaccount'], [
|
|
|
|
'id' => 'pt-createaccount-2',
|
|
|
|
'collapsible' => true,
|
|
|
|
// Remove icon
|
|
|
|
'icon' => '',
|
|
|
|
] );
|
|
|
|
}
|
2023-01-31 18:55:27 +00:00
|
|
|
if ( isset( $content_navigation['user-menu']['login'] ) ) {
|
|
|
|
$content_navigation[$overflow]['login'] = array_merge(
|
|
|
|
$content_navigation['user-menu']['login'], [
|
|
|
|
'id' => 'pt-login-2',
|
|
|
|
'collapsible' => true,
|
|
|
|
// Remove icon
|
|
|
|
'icon' => '',
|
|
|
|
] );
|
|
|
|
}
|
2023-03-08 19:50:20 +00:00
|
|
|
if ( isset( $content_navigation['user-menu']['login-private'] ) ) {
|
|
|
|
$content_navigation[$overflow]['login-private'] = array_merge(
|
|
|
|
$content_navigation['user-menu']['login-private'], [
|
|
|
|
'id' => 'pt-login-private-2',
|
|
|
|
'collapsible' => true,
|
|
|
|
// Remove icon
|
|
|
|
'icon' => '',
|
|
|
|
] );
|
|
|
|
}
|
2022-04-19 17:50:01 +00:00
|
|
|
|
|
|
|
self::updateMenuItems( $content_navigation, $overflow );
|
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 {
|
2022-04-19 17:50:01 +00:00
|
|
|
self::updateUserLinksOverflowItems( $sk, $content_navigation );
|
|
|
|
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-' ) {
|
|
|
|
$COLLAPSE_MENU_ITEM_CLASS = $prefix . 'collapsible-item';
|
2022-08-01 22:06:32 +00:00
|
|
|
self::appendClassToItem( $item[ 'class' ], $COLLAPSE_MENU_ITEM_CLASS );
|
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
|
|
|
|
*/
|
2021-09-01 22:58:54 +00:00
|
|
|
public static function makeIcon( $name ) {
|
2021-08-26 19:47:02 +00:00
|
|
|
// Html::makeLink will pass this through rawElement
|
2022-04-14 16:27:31 +00:00
|
|
|
return '<span class="mw-ui-icon mw-ui-icon-' . $name . ' mw-ui-icon-wikimedia-' . $name . '"></span>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
2022-09-02 14:57:31 +00:00
|
|
|
* @param bool $isSmallIcon when set a small icon will be applied rather than the standard icon size
|
2022-08-01 22:06:32 +00:00
|
|
|
* @return array $item Updated data
|
2022-04-14 16:27:31 +00:00
|
|
|
*/
|
2022-09-02 14:57:31 +00:00
|
|
|
private static function updateItemData( $item, $buttonClassProp, $iconHtmlProp, $isSmallIcon = false ) {
|
2022-04-14 16:27:31 +00:00
|
|
|
$hasButton = $item['button'] ?? false;
|
|
|
|
$hideText = $item['text-hidden'] ?? false;
|
|
|
|
$isCollapsible = $item['collapsible'] ?? false;
|
|
|
|
$icon = $item['icon'] ?? '';
|
|
|
|
unset( $item['button'] );
|
|
|
|
unset( $item['icon'] );
|
|
|
|
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 ) {
|
2022-08-01 22:06:32 +00:00
|
|
|
self::appendClassToItem( $item[ $buttonClassProp ], [ 'mw-ui-button', 'mw-ui-quiet' ] );
|
2022-04-14 16:27:31 +00:00
|
|
|
}
|
|
|
|
if ( $icon ) {
|
|
|
|
if ( $hideText ) {
|
|
|
|
$iconElementClasses = [ 'mw-ui-icon', 'mw-ui-icon-element',
|
|
|
|
// Some extensions declare icons without the wikimedia- prefix. e.g. Echo
|
|
|
|
'mw-ui-icon-' . $icon,
|
|
|
|
// FIXME: Some icon names are prefixed with `wikimedia-`.
|
|
|
|
// We should seek to remove all these instances.
|
|
|
|
'mw-ui-icon-wikimedia-' . $icon
|
|
|
|
];
|
2022-09-02 14:57:31 +00:00
|
|
|
if ( $isSmallIcon ) {
|
|
|
|
$iconElementClasses[] = 'mw-ui-icon-small';
|
|
|
|
}
|
2022-08-01 22:06:32 +00:00
|
|
|
self::appendClassToItem( $item[ $buttonClassProp ], $iconElementClasses );
|
2022-04-14 16:27:31 +00:00
|
|
|
} else {
|
2022-08-01 22:06:32 +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
|
2022-09-02 14:57:31 +00:00
|
|
|
* @param bool $isSmallIcon when set a small icon will be applied rather than the standard icon size
|
2022-08-01 22:06:32 +00:00
|
|
|
* @return array $item Updated menu item data
|
|
|
|
*/
|
2022-09-02 14:57:31 +00:00
|
|
|
public static function updateMenuItemData( $item, $isSmallIcon = false ) {
|
2022-08-01 22:06:32 +00:00
|
|
|
$buttonClassProp = 'link-class';
|
|
|
|
$iconHtmlProp = 'link-html';
|
2022-09-02 14:57:31 +00:00
|
|
|
return self::updateItemData( $item, $buttonClassProp, $iconHtmlProp, $isSmallIcon );
|
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 ) {
|
2021-08-26 19:47:02 +00:00
|
|
|
foreach ( $content_navigation[$menu] as $key => $item ) {
|
2022-08-01 22:06:32 +00:00
|
|
|
$content_navigation[$menu][$key] = 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 = [];
|
|
|
|
foreach ( array_keys( $content_navigation['views'] ?? [] ) as $key ) {
|
2023-03-18 21:21:56 +00:00
|
|
|
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
|
2022-04-27 19:32:19 +00:00
|
|
|
$newItem = $content_navigation['views'][$key];
|
|
|
|
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 ) {
|
2020-06-12 21:43:58 +00:00
|
|
|
$title = $sk->getRelevantTitle();
|
2021-04-30 02:54:54 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-12-14 21:59:16 +00:00
|
|
|
/**
|
|
|
|
* Adds MediaWiki:Vector.css as the skin style that controls classic Vector.
|
|
|
|
*
|
|
|
|
* @param string $skin
|
|
|
|
* @param array &$pages
|
|
|
|
*/
|
2021-01-02 13:11:04 +00:00
|
|
|
public function onResourceLoaderSiteStylesModulePages( $skin, &$pages ): void {
|
2023-03-09 18:08:36 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
|
|
|
if ( $skin === Constants::SKIN_NAME_MODERN && $config->get( 'VectorShareUserScripts' ) ) {
|
2021-12-14 21:59:16 +00:00
|
|
|
$pages['MediaWiki:Vector.css'] = [ 'type' => 'style' ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds MediaWiki:Vector.css as the skin style that controls classic Vector.
|
|
|
|
*
|
|
|
|
* @param string $skin
|
|
|
|
* @param array &$pages
|
|
|
|
*/
|
2021-01-02 13:11:04 +00:00
|
|
|
public function onResourceLoaderSiteModulePages( $skin, &$pages ): void {
|
2023-03-09 18:08:36 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
|
|
|
if ( $skin === Constants::SKIN_NAME_MODERN && $config->get( 'VectorShareUserScripts' ) ) {
|
2021-12-14 21:59:16 +00:00
|
|
|
$pages['MediaWiki:Vector.js'] = [ 'type' => 'script' ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2022-04-14 18:21:12 +00:00
|
|
|
$vectorPrefs = [
|
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'
|
|
|
|
],
|
2022-10-17 08:43:26 +00:00
|
|
|
Constants::PREF_KEY_LIMITED_WIDTH => [
|
|
|
|
'type' => 'toggle',
|
2022-10-19 12:08:53 +00:00
|
|
|
'label-message' => 'vector-prefs-limited-width',
|
2022-10-17 08:43:26 +00:00
|
|
|
'section' => 'rendering/skin/skin-prefs',
|
2022-10-19 12:08:53 +00:00
|
|
|
'help-message' => 'vector-prefs-limited-width-help',
|
2022-10-18 01:15:50 +00:00
|
|
|
'hide-if' => [ '!==', 'skin', Constants::SKIN_NAME_MODERN ],
|
2022-10-17 08:43:26 +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 ) {
|
2022-04-05 13:54:23 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
|
|
|
$default = $config->get( Constants::CONFIG_KEY_DEFAULT_SKIN_VERSION_FOR_NEW_ACCOUNTS );
|
2022-03-31 03:47:57 +00:00
|
|
|
if ( $default ) {
|
|
|
|
$optionsManager = MediaWikiServices::getInstance()->getUserOptionsManager();
|
|
|
|
$optionsManager->setOption(
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
2022-08-04 21:11:54 +00:00
|
|
|
/**
|
|
|
|
* Temporary RequestContextCreateSkin hook handler.
|
|
|
|
* Switches to new Vector on certain pages.
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/RequestContextCreateSkin
|
|
|
|
*
|
|
|
|
* @param IContextSource $context The RequestContext object the skin is being created for.
|
|
|
|
* @param Skin|null|string &$skin A variable reference you may set a Skin instance or string
|
|
|
|
* key on to override the skin that will be used for the context.
|
|
|
|
* @return bool|void
|
|
|
|
*/
|
|
|
|
public function onRequestContextCreateSkin( $context, &$skin ) {
|
|
|
|
if ( !$skin ) {
|
|
|
|
// user is anonymous
|
|
|
|
$user = $context->getUser();
|
|
|
|
$config = $context->getConfig();
|
|
|
|
$titles = $config->get( 'Vector2022PreviewPages' );
|
|
|
|
$title = $context->getTitle();
|
|
|
|
$titleText = $title ? $title->getPrefixedText() : null;
|
|
|
|
if ( $titleText && $user->isAnon() && in_array( $titleText, $titles ) ) {
|
|
|
|
$skin = 'vector-2022';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 21:27:09 +00:00
|
|
|
/**
|
|
|
|
* NOTE: Please use ResourceLoaderGetConfigVars hook instead if possible
|
|
|
|
* for adding config to the page.
|
|
|
|
* Adds config variables to JS that depend on current page/request.
|
|
|
|
*
|
|
|
|
* Adds a config flag that can disable saving the VectorSidebarVisible
|
|
|
|
* user preference when the sidebar menu icon is clicked.
|
|
|
|
*
|
|
|
|
* @param array &$vars Array of variables to be added into the output.
|
|
|
|
* @param OutputPage $out OutputPage instance calling the hook
|
|
|
|
*/
|
2021-01-02 13:11:04 +00:00
|
|
|
public function onMakeGlobalVariablesScript( &$vars, $out ): void {
|
2021-09-09 22:13:48 +00:00
|
|
|
$skin = $out->getSkin();
|
2022-02-02 21:52:17 +00:00
|
|
|
$skinName = $skin->getSkinName();
|
|
|
|
if ( !self::isVectorSkin( $skinName ) ) {
|
2020-08-12 15:05:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-04 21:11:54 +00:00
|
|
|
$config = $out->getConfig();
|
2020-08-12 15:05:06 +00:00
|
|
|
$user = $out->getUser();
|
2020-07-15 21:27:09 +00:00
|
|
|
|
2022-08-04 21:11:54 +00:00
|
|
|
// Must be exposed to CentralNotice banners via mw.config
|
|
|
|
$vars[ 'wgVector2022PreviewPages' ] = $config->get( 'Vector2022PreviewPages' );
|
2020-07-15 21:27: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
|
|
|
}
|
2017-06-30 19:21:16 +00:00
|
|
|
}
|