2017-06-30 19:21:16 +00:00
|
|
|
<?php
|
2018-03-12 23:52:48 +00:00
|
|
|
|
|
|
|
namespace Vector;
|
|
|
|
|
2020-07-14 13:07:09 +00:00
|
|
|
use Config;
|
2021-01-02 13:11:04 +00:00
|
|
|
use MediaWiki\Auth\Hook\LocalUserCreatedHook;
|
|
|
|
use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
|
|
|
|
use MediaWiki\Hook\OutputPageBodyAttributesHook;
|
[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;
|
|
|
|
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;
|
2020-07-14 13:07:09 +00:00
|
|
|
use ResourceLoaderContext;
|
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;
|
2021-01-06 21:50:19 +00:00
|
|
|
use Title;
|
[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,
|
|
|
|
OutputPageBodyAttributesHook,
|
|
|
|
ResourceLoaderSiteModulePagesHook,
|
|
|
|
ResourceLoaderSiteStylesModulePagesHook,
|
|
|
|
SkinPageReadyConfigHook
|
|
|
|
{
|
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.
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
* @param Config $config
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getVectorResourceLoaderConfig(
|
|
|
|
ResourceLoaderContext $context,
|
|
|
|
Config $config
|
|
|
|
) {
|
|
|
|
return [
|
2020-11-23 22:55:35 +00:00
|
|
|
'wgVectorSearchHost' => $config->get( 'VectorSearchHost' ),
|
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).
|
|
|
|
*
|
2020-11-26 00:58:10 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
* @param Config $config
|
2021-06-30 12:51:04 +00:00
|
|
|
* @return array<string,mixed>
|
2020-11-26 00:58:10 +00:00
|
|
|
*/
|
|
|
|
public static function getVectorWvuiSearchResourceLoaderConfig(
|
|
|
|
ResourceLoaderContext $context,
|
|
|
|
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
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
* @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(
|
2020-07-14 13:07:09 +00:00
|
|
|
ResourceLoaderContext $context,
|
|
|
|
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.
|
2020-07-14 13:07:09 +00:00
|
|
|
// ResourceLoaderContext has no knowledge of legacy / modern Vector
|
|
|
|
// 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
|
|
|
/**
|
|
|
|
* Transforms watch item inside the action navigation menu
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
if ( $key !== null ) {
|
2021-06-30 22:55:09 +00:00
|
|
|
self::appendClassToListItem(
|
|
|
|
$content_navigation['actions'][$key],
|
|
|
|
'icon'
|
2021-05-07 21:56:29 +00:00
|
|
|
);
|
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] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 22:55:09 +00:00
|
|
|
/**
|
|
|
|
* Updates class list on list item
|
|
|
|
*
|
|
|
|
* @param array &$item to update for use in makeListItem
|
|
|
|
* @param array $classes to add to the item
|
|
|
|
* @param bool $applyToLink (optional) and defaults to false.
|
|
|
|
* If set will modify `link-class` instead of `class`
|
|
|
|
*/
|
|
|
|
private static function addListItemClass( &$item, $classes, $applyToLink = false ) {
|
|
|
|
$property = $applyToLink ? 'link-class' : 'class';
|
|
|
|
$existingClass = $item[$property] ?? [];
|
|
|
|
|
|
|
|
if ( is_array( $existingClass ) ) {
|
|
|
|
$item[$property] = array_merge( $existingClass, $classes );
|
|
|
|
} elseif ( is_string( $existingClass ) ) {
|
|
|
|
// treat as string
|
|
|
|
$item[$property] = array_merge( [ $existingClass ], $classes );
|
|
|
|
} else {
|
|
|
|
$item[$property] = $classes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-02 22:57:43 +00:00
|
|
|
/**
|
|
|
|
* Updates the class on an existing item taking into account whether
|
|
|
|
* a class exists there already.
|
|
|
|
*
|
|
|
|
* @param array &$item
|
|
|
|
* @param string $newClass
|
|
|
|
*/
|
2021-06-30 22:55:09 +00:00
|
|
|
private static function appendClassToListItem( &$item, $newClass ) {
|
|
|
|
self::addListItemClass( $item, [ $newClass ] );
|
2021-06-02 22:57:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:09:21 +00:00
|
|
|
/**
|
2021-06-30 22:55:09 +00:00
|
|
|
* Adds an icon to the list item of a menu.
|
|
|
|
*
|
|
|
|
* @param array &$item
|
|
|
|
* @param string $icon_name
|
2020-05-11 22:09:21 +00:00
|
|
|
*/
|
2021-06-30 22:55:09 +00:00
|
|
|
private static function addIconToListItem( &$item, $icon_name ) {
|
|
|
|
// Set the default menu icon classes.
|
2022-03-04 22:11:56 +00:00
|
|
|
$menu_icon_classes = [ 'mw-ui-icon', 'mw-ui-icon-before',
|
|
|
|
// Some extensions declare icons without the wikimedia- prefix. e.g. Echo
|
|
|
|
'mw-ui-icon-' . $icon_name,
|
|
|
|
// FIXME: Some icon names are prefixed with `wikimedia-`.
|
|
|
|
// We should seek to remove all these instances.
|
|
|
|
'mw-ui-icon-wikimedia-' . $icon_name
|
|
|
|
];
|
2021-06-30 22:55:09 +00:00
|
|
|
self::addListItemClass( $item, $menu_icon_classes, true );
|
2020-05-11 22:09:21 +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
|
|
|
*
|
|
|
|
* @param SkinTemplate $sk
|
|
|
|
* @param array &$content_navigation
|
2022-03-04 15:45:45 +00:00
|
|
|
* @suppress PhanTypeArraySuspiciousNullable False positives
|
|
|
|
* @suppress PhanTypePossiblyInvalidDimOffset False positives
|
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
|
|
|
$isTemp = $user->isTemp();
|
|
|
|
$isRegistered = $user->isRegistered();
|
|
|
|
if ( $isTemp ) {
|
|
|
|
if ( isset( $content_navigation['user-page']['tmpuserpage'] ) ) {
|
|
|
|
self::makeMenuItemCollapsible( $content_navigation['user-page']['tmpuserpage'] );
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['user-menu']['tmpuserpage'] ) ) {
|
|
|
|
self::makeMenuItemCollapsible( $content_navigation['user-menu']['tmpuserpage'] );
|
2022-03-28 21:22:50 +00:00
|
|
|
}
|
2022-03-04 01:52:44 +00:00
|
|
|
} elseif ( $isRegistered ) {
|
|
|
|
// Remove user page from personal menu dropdown for logged in use
|
|
|
|
self::makeMenuItemCollapsible(
|
|
|
|
$content_navigation['user-menu']['userpage']
|
|
|
|
);
|
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-01-20 17:42:58 +00:00
|
|
|
self::makeMenuItemCollapsible(
|
2022-03-04 15:45:45 +00:00
|
|
|
$content_navigation['user-menu']['watchlist']
|
2022-01-20 17:42:58 +00:00
|
|
|
);
|
|
|
|
}
|
2021-08-24 21:34:59 +00:00
|
|
|
// Remove logout link from user-menu and recreate it in SkinVector,
|
|
|
|
unset( $content_navigation['user-menu']['logout'] );
|
2022-03-04 01:52:44 +00:00
|
|
|
}
|
|
|
|
if ( $isRegistered ) {
|
2021-08-24 21:34:59 +00:00
|
|
|
// Don't show icons for anon menu items (besides login and create account).
|
|
|
|
// Prefix user link items with associated icon.
|
|
|
|
$user_menu = $content_navigation['user-menu'];
|
|
|
|
// Loop through each menu to check/append its link classes.
|
|
|
|
foreach ( $user_menu as $menu_key => $menu_value ) {
|
|
|
|
$icon_name = $menu_value['icon'] ?? '';
|
|
|
|
self::addIconToListItem( $content_navigation['user-menu'][$menu_key], $icon_name );
|
2021-05-07 21:56:29 +00:00
|
|
|
}
|
2021-08-24 21:34:59 +00:00
|
|
|
} else {
|
|
|
|
// Remove "Not logged in" from personal menu dropdown for anon users.
|
|
|
|
unset( $content_navigation['user-menu']['anonuserpage'] );
|
2022-03-04 01:52:44 +00:00
|
|
|
}
|
|
|
|
if ( !$isRegistered || $isTemp ) {
|
2021-08-24 21:34:59 +00:00
|
|
|
// "Create account" link is handled manually by Vector
|
|
|
|
unset( $content_navigation['user-menu']['createaccount'] );
|
|
|
|
// "Login" link is handled manually by Vector
|
|
|
|
unset( $content_navigation['user-menu']['login'] );
|
|
|
|
// Remove duplicate "Login" link added by SkinTemplate::buildPersonalUrls if group read permissions
|
|
|
|
// are set to false.
|
|
|
|
unset( $content_navigation['user-menu']['login-private'] );
|
|
|
|
}
|
2022-01-18 19:13:34 +00:00
|
|
|
}
|
2021-06-02 22:57:43 +00:00
|
|
|
|
2022-03-04 20:24:10 +00:00
|
|
|
/**
|
|
|
|
* Updates personal navigation menu (user links) overflow items for modern Vector
|
|
|
|
* including 'notification', 'user-interface-preferences', 'user-page', 'vector-user-menu-overflow'
|
|
|
|
*
|
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
|
|
|
private static function updateUserLinksOverflowItems( &$content_navigation ) {
|
|
|
|
// Upgrade preferences, notifications, and watchlist to icon buttons
|
|
|
|
// for extensions that have opted in.
|
|
|
|
if ( isset( $content_navigation['notifications'] ) ) {
|
|
|
|
self::updateMenuItems( $content_navigation, 'notifications' );
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['user-interface-preferences']['uls'] ) ) {
|
|
|
|
$content_navigation['user-interface-preferences']['uls'] += [
|
|
|
|
'collapsible' => true,
|
|
|
|
];
|
|
|
|
self::updateMenuItems( $content_navigation, 'user-interface-preferences' );
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['user-page']['userpage'] ) ) {
|
|
|
|
$content_navigation['user-page']['userpage'] = array_merge( $content_navigation['user-page']['userpage'], [
|
|
|
|
'button' => true,
|
|
|
|
'collapsible' => true,
|
|
|
|
'icon' => null,
|
|
|
|
] );
|
|
|
|
self::updateMenuItems( $content_navigation, 'user-page' );
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['vector-user-menu-overflow']['watchlist'] ) ) {
|
|
|
|
$content_navigation['vector-user-menu-overflow']['watchlist'] += [
|
|
|
|
'button' => true,
|
|
|
|
'collapsible' => true,
|
|
|
|
'text-hidden' => true,
|
|
|
|
'id' => 'pt-watchlist-2',
|
|
|
|
];
|
|
|
|
self::updateMenuItems( $content_navigation, 'vector-user-menu-overflow' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @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-03-16 20:50:23 +00:00
|
|
|
if ( isset( $content_navigation['user-menu'] ) ) {
|
|
|
|
if ( isset( $content_navigation['user-menu']['watchlist'] ) ) {
|
|
|
|
// Copy watchlist data into 'vector-user-menu-overflow'
|
|
|
|
$content_navigation['vector-user-menu-overflow'] = [
|
|
|
|
'watchlist' => $content_navigation['user-menu']['watchlist']
|
|
|
|
];
|
|
|
|
}
|
2021-06-02 22:57:43 +00:00
|
|
|
|
2022-03-04 20:24:10 +00:00
|
|
|
self::updateUserLinksDropdownItems( $sk, $content_navigation );
|
|
|
|
}
|
|
|
|
|
|
|
|
self::updateUserLinksOverflowItems( $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.
|
|
|
|
*
|
|
|
|
* @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-01-12 23:44:18 +00:00
|
|
|
self::appendClassToListItem(
|
|
|
|
$item,
|
|
|
|
$COLLAPSE_MENU_ITEM_CLASS
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
return '<span class="mw-ui-icon mw-ui-icon-' . $name . '"></span>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ) {
|
|
|
|
$hasButton = $item['button'] ?? false;
|
|
|
|
$hideText = $item['text-hidden'] ?? false;
|
2022-01-12 23:44:18 +00:00
|
|
|
$isCollapsible = $item['collapsible'] ?? false;
|
2021-08-26 19:47:02 +00:00
|
|
|
$icon = $item['icon'] ?? '';
|
|
|
|
unset( $item['button'] );
|
|
|
|
unset( $item['icon'] );
|
|
|
|
unset( $item['text-hidden'] );
|
2022-01-12 23:44:18 +00:00
|
|
|
unset( $item['collapsible'] );
|
|
|
|
if ( $isCollapsible ) {
|
|
|
|
self::makeMenuItemCollapsible( $item );
|
|
|
|
}
|
2021-08-26 19:47:02 +00:00
|
|
|
|
|
|
|
if ( $hasButton ) {
|
2022-03-04 20:24:10 +00:00
|
|
|
self::addListItemClass( $item, [ 'mw-ui-button', 'mw-ui-quiet' ], true );
|
2021-08-26 19:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $icon ) {
|
|
|
|
if ( $hideText ) {
|
2022-03-04 20:24:10 +00:00
|
|
|
$iconElementClasses = [ 'mw-ui-icon', 'mw-ui-icon-element',
|
2022-03-04 22:11:56 +00:00
|
|
|
// Some extensions declare icons without the wikimedia- prefix. e.g. Echo
|
2022-03-04 20:24:10 +00:00
|
|
|
'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
|
|
|
|
];
|
|
|
|
self::addListItemClass( $item, $iconElementClasses, true );
|
2021-08-26 19:47:02 +00:00
|
|
|
} else {
|
2021-09-01 22:58:54 +00:00
|
|
|
$item['link-html'] = self::makeIcon( $icon );
|
2021-08-26 19:47:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$content_navigation[$menu][$key] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 ) {
|
|
|
|
$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();
|
|
|
|
if ( self::isVectorSkin( $skinName ) ) {
|
2021-05-07 21:56:29 +00:00
|
|
|
if (
|
|
|
|
$sk->getConfig()->get( 'VectorUseIconWatch' ) &&
|
|
|
|
$title && $title->canExist()
|
|
|
|
) {
|
|
|
|
self::updateActionsMenu( $content_navigation );
|
2020-05-11 22:09:21 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 20:24:10 +00:00
|
|
|
self::updateUserLinksItems( $sk, $content_navigation );
|
2020-05-11 22:09:21 +00:00
|
|
|
}
|
2022-04-27 19:32:19 +00:00
|
|
|
if ( $skinName === Constants::SKIN_NAME_MODERN ) {
|
|
|
|
self::createMoreOverflowMenu( $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 {
|
2021-12-14 21:59:16 +00:00
|
|
|
if ( $skin === Constants::SKIN_NAME_MODERN ) {
|
|
|
|
$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 {
|
2021-12-14 21:59:16 +00:00
|
|
|
if ( $skin === Constants::SKIN_NAME_MODERN ) {
|
|
|
|
$pages['MediaWiki:Vector.js'] = [ 'type' => 'script' ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-14 18:21:12 +00:00
|
|
|
/**
|
|
|
|
* Adds the persistent sidebar hidden API preference.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
|
|
|
$vectorPrefs = [
|
|
|
|
Constants::PREF_KEY_SIDEBAR_VISIBLE => [
|
|
|
|
'type' => 'api',
|
|
|
|
'default' => $config->get(
|
|
|
|
Constants::CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_AUTHORISED_USER
|
|
|
|
),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$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-03-17 23:02:39 +00:00
|
|
|
/**
|
|
|
|
* Returns the necessary TOC classes.
|
|
|
|
*
|
|
|
|
* @param Skin $sk
|
|
|
|
* @param Config $config
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
private static function getTocClasses( Skin $sk, $config ): array {
|
|
|
|
if ( !( $sk instanceof SkinVector22 ) ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$classes = [];
|
|
|
|
|
|
|
|
$isTocABTestEnabled = $sk->isTOCABTestEnabled();
|
|
|
|
if ( $isTocABTestEnabled || $sk->isTOCEnabled() ) {
|
|
|
|
$classes[] = 'vector-toc-enabled';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
$sk->isTableOfContentsVisibleInSidebar() &&
|
|
|
|
$isTocABTestEnabled
|
|
|
|
) {
|
|
|
|
/** @var \WikimediaEvents\WebABTest\WebABTestArticleIdFactory */
|
|
|
|
$webABTestArticleIdFactory = MediaWikiServices::getInstance()->getService(
|
|
|
|
Constants::WEB_AB_TEST_ARTICLE_ID_FACTORY_SERVICE
|
|
|
|
);
|
|
|
|
$experimentConfig = $config->get( Constants::CONFIG_WEB_AB_TEST_ENROLLMENT );
|
|
|
|
$bucketKeys = array_keys( $experimentConfig['buckets'] );
|
|
|
|
|
|
|
|
$ab = $webABTestArticleIdFactory->makeWebABTestArticleIdStrategy(
|
|
|
|
$webABTestArticleIdFactory->filterExcludedBucket( $bucketKeys ),
|
|
|
|
1 - $experimentConfig['buckets']['unsampled']['samplingRate'],
|
|
|
|
Constants::QUERY_PARAM_TABLE_OF_CONTENTS,
|
|
|
|
$sk->getContext()
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( !$ab ) {
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
$bucket = $ab->getBucket();
|
|
|
|
|
|
|
|
if ( $bucket ) {
|
|
|
|
$experimentName = $experimentConfig[ 'name' ];
|
|
|
|
$classes[] = $experimentName;
|
|
|
|
$classes[] = "$experimentName-$bucket";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
|
2020-06-18 12:52:00 +00:00
|
|
|
/**
|
|
|
|
* Called when OutputPage::headElement is creating the body tag to allow skins
|
|
|
|
* and extensions to add attributes they might need to the body of the page.
|
|
|
|
*
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @param Skin $sk
|
|
|
|
* @param string[] &$bodyAttrs
|
|
|
|
*/
|
2021-01-02 13:11:04 +00:00
|
|
|
public function onOutputPageBodyAttributes( $out, $sk, &$bodyAttrs ): void {
|
2021-09-09 22:13:48 +00:00
|
|
|
$skinName = $out->getSkin()->getSkinName();
|
|
|
|
if ( !self::isVectorSkin( $skinName ) ) {
|
2020-08-01 18:05:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-03-17 23:02:39 +00:00
|
|
|
$config = $sk->getConfig();
|
2020-08-01 18:05:57 +00:00
|
|
|
|
2020-08-12 15:05:06 +00:00
|
|
|
// As of 2020/08/13, this CSS class is referred to by the following deployed extensions:
|
|
|
|
//
|
|
|
|
// - VisualEditor
|
|
|
|
// - CodeMirror
|
|
|
|
// - WikimediaEvents
|
|
|
|
//
|
|
|
|
// See https://codesearch.wmcloud.org/deployed/?q=skin-vector-legacy for an up-to-date
|
|
|
|
// list.
|
2022-02-02 21:52:17 +00:00
|
|
|
if ( self::isSkinVersionLegacy( $skinName ) ) {
|
2020-06-18 12:52:00 +00:00
|
|
|
$bodyAttrs['class'] .= ' skin-vector-legacy';
|
2020-11-19 17:12:53 +00:00
|
|
|
}
|
2021-01-06 21:50:19 +00:00
|
|
|
|
2022-03-17 23:02:39 +00:00
|
|
|
$tocClasses = self::getTocClasses( $sk, $config );
|
|
|
|
if ( $tocClasses ) {
|
|
|
|
$bodyAttrs['class'] .= ' ' . implode( ' ', $tocClasses );
|
|
|
|
}
|
|
|
|
|
2021-01-18 19:52:15 +00:00
|
|
|
// Should we disable the max-width styling?
|
2022-02-02 21:52:17 +00:00
|
|
|
if ( !self::isSkinVersionLegacy( $skinName ) && $sk->getTitle() && self::shouldDisableMaxWidth(
|
2021-01-06 21:50:19 +00:00
|
|
|
$config->get( 'VectorMaxWidthOptions' ),
|
|
|
|
$sk->getTitle(),
|
|
|
|
$out->getRequest()->getValues()
|
|
|
|
) ) {
|
|
|
|
$bodyAttrs['class'] .= ' skin-vector-disable-max-width';
|
|
|
|
}
|
2022-04-05 22:33:25 +00:00
|
|
|
|
|
|
|
$featureManager = VectorServices::getFeatureManager();
|
|
|
|
if ( $featureManager->isFeatureEnabled( Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER ) ) {
|
|
|
|
$bodyAttrs['class'] .= ' vector-language-in-header-enabled';
|
|
|
|
}
|
2021-01-06 21:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Per the $options configuration (for use with $wgVectorMaxWidthOptions)
|
|
|
|
* determine whether max-width should be disabled on the page.
|
|
|
|
* For the main page: Check the value of $options['exclude']['mainpage']
|
|
|
|
* For all other pages, the following will happen:
|
|
|
|
* - the array $options['include'] of canonical page names will be checked
|
|
|
|
* against the current page. If a page has been listed there, function will return false
|
|
|
|
* (max-width will not be disabled)
|
|
|
|
* Max width is disabled if:
|
|
|
|
* 1) The current namespace is listed in array $options['exclude']['namespaces']
|
|
|
|
* OR
|
|
|
|
* 2) The query string matches one of the name and value pairs $exclusions['querystring'].
|
|
|
|
* Note the wildcard "*" for a value, will match all query string values for the given
|
|
|
|
* query string parameter.
|
|
|
|
*
|
|
|
|
* @internal only for use inside tests.
|
|
|
|
* @param array $options
|
|
|
|
* @param Title $title
|
|
|
|
* @param array $requestValues
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function shouldDisableMaxWidth( array $options, Title $title, array $requestValues ) {
|
|
|
|
$canonicalTitle = $title->getRootTitle();
|
|
|
|
|
|
|
|
$inclusions = $options['include'] ?? [];
|
|
|
|
$exclusions = $options['exclude'] ?? [];
|
|
|
|
|
|
|
|
if ( $title->isMainPage() ) {
|
|
|
|
// only one check to make
|
|
|
|
return $exclusions['mainpage'] ?? false;
|
|
|
|
} elseif ( $canonicalTitle->isSpecialPage() ) {
|
|
|
|
$canonicalTitle->fixSpecialName();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check the inclusions based on the canonical title
|
|
|
|
// The inclusions are checked first as these trump any exclusions.
|
|
|
|
//
|
|
|
|
// Now we have the canonical title and the inclusions link we look for any matches.
|
|
|
|
foreach ( $inclusions as $titleText ) {
|
|
|
|
$includedTitle = Title::newFromText( $titleText );
|
|
|
|
|
|
|
|
if ( $canonicalTitle->equals( $includedTitle ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check the exclusions
|
|
|
|
// If nothing matches the exclusions to determine what should happen
|
|
|
|
//
|
|
|
|
$excludeNamespaces = $exclusions['namespaces'] ?? [];
|
|
|
|
// Max width is disabled on certain namespaces
|
|
|
|
if ( $title->inNamespaces( $excludeNamespaces ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$excludeQueryString = $exclusions['querystring'] ?? [];
|
|
|
|
|
|
|
|
foreach ( $excludeQueryString as $param => $excludedParamValue ) {
|
|
|
|
$paramValue = $requestValues[$param] ?? false;
|
|
|
|
if ( $paramValue ) {
|
|
|
|
if ( $excludedParamValue === '*' ) {
|
|
|
|
// check wildcard
|
|
|
|
return true;
|
|
|
|
} elseif ( $paramValue === $excludedParamValue ) {
|
|
|
|
// Check if the excluded param value matches
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-06-18 12:52:00 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2020-08-13 14:37:45 +00:00
|
|
|
|
2020-08-12 15:05:06 +00:00
|
|
|
$user = $out->getUser();
|
2020-07-15 21:27:09 +00:00
|
|
|
|
2022-02-02 21:52:17 +00:00
|
|
|
if ( $user->isRegistered() && self::isSkinVersionLegacy( $skinName ) ) {
|
2020-08-12 15:05:06 +00:00
|
|
|
$vars[ 'wgVectorDisableSidebarPersistence' ] =
|
2022-04-05 13:54:23 +00:00
|
|
|
$out->getConfig()->get(
|
2020-07-15 21:27:09 +00:00
|
|
|
Constants::CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* Should mirror SkinVector::isLegacy
|
2020-08-12 15:05:06 +00:00
|
|
|
*
|
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
|
|
|
}
|