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;
|
[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 HTMLForm;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
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;
|
2020-08-11 14:13:12 +00:00
|
|
|
use Vector\HTMLForm\Fields\HTMLLegacySkinVersionField;
|
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
|
|
|
*/
|
2018-03-12 23:52:48 +00:00
|
|
|
class Hooks {
|
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(
|
|
|
|
Constants::CONFIG_STICKY_HEADER_TREATMENT_AB_TEST_ENROLLMENT
|
|
|
|
);
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public static function onSkinPageReadyConfig(
|
|
|
|
ResourceLoaderContext $context,
|
|
|
|
array &$config
|
|
|
|
) {
|
|
|
|
// 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.
|
2021-01-22 23:16:31 +00:00
|
|
|
// This allows us to use $wgVectorUseWvuiSearch to decide to load
|
2020-07-14 13:07:09 +00:00
|
|
|
// the historic jquery autocomplete search or the new Vue implementation.
|
|
|
|
// 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.
|
|
|
|
$menu_icon_classes = [ 'mw-ui-icon', 'mw-ui-icon-before', 'mw-ui-icon-wikimedia-' . $icon_name ];
|
|
|
|
self::addListItemClass( $item, $menu_icon_classes, true );
|
2020-05-11 22:09:21 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 21:56:29 +00:00
|
|
|
/**
|
2021-08-24 21:34:59 +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.
|
2021-05-07 21:56:29 +00:00
|
|
|
*
|
|
|
|
* @param SkinTemplate $sk
|
|
|
|
* @param array &$content_navigation
|
|
|
|
*/
|
|
|
|
private static function updateUserLinksItems( $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-01-12 23:44:18 +00:00
|
|
|
if ( $sk->getUser()->isRegistered() ) {
|
2021-08-24 21:34:59 +00:00
|
|
|
// Remove user page from personal menu dropdown for logged in users at higher resolutions.
|
2022-01-12 23:44:18 +00:00
|
|
|
self::makeMenuItemCollapsible(
|
|
|
|
$content_navigation['user-menu']['userpage']
|
|
|
|
);
|
|
|
|
self::makeMenuItemCollapsible(
|
|
|
|
$content_navigation['user-menu']['watchlist']
|
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'] );
|
|
|
|
// 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'] );
|
|
|
|
// "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'] );
|
|
|
|
}
|
2021-06-02 22:57:43 +00:00
|
|
|
|
2021-08-24 21:34:59 +00:00
|
|
|
// ULS and user page links are hidden at lower resolutions.
|
|
|
|
if ( $content_navigation['user-interface-preferences'] ) {
|
2022-01-12 23:44:18 +00:00
|
|
|
self::makeMenuItemCollapsible(
|
|
|
|
$content_navigation['user-interface-preferences']['uls']
|
2021-08-24 21:34:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( $content_navigation['user-page'] ) {
|
2022-01-12 23:44:18 +00:00
|
|
|
self::makeMenuItemCollapsible(
|
|
|
|
$content_navigation['user-page']['userpage']
|
2021-08-24 21:34:59 +00:00
|
|
|
);
|
2021-06-02 22:57:43 +00:00
|
|
|
|
2021-08-24 21:34:59 +00:00
|
|
|
// Style the user page link as mw-ui-button.
|
|
|
|
self::addListItemClass(
|
|
|
|
$content_navigation['user-page']['userpage'],
|
|
|
|
[ 'mw-ui-button', 'mw-ui-quiet' ],
|
|
|
|
true
|
|
|
|
);
|
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
|
|
|
|
*/
|
|
|
|
private static function makeMenuItemCollapsible( array &$item ) {
|
|
|
|
$COLLAPSE_MENU_ITEM_CLASS = 'user-links-collapsible-item';
|
|
|
|
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 ) {
|
|
|
|
$item['link-class'][] = 'mw-ui-button mw-ui-quiet';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $icon ) {
|
|
|
|
if ( $hideText ) {
|
2022-01-12 23:44:18 +00:00
|
|
|
$item['link-class'][] = 'mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-' . $icon;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-11 23:30:03 +00:00
|
|
|
if ( self::isVectorSkin( $sk->getSkinName() ) ) {
|
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-01-12 23:44:18 +00:00
|
|
|
// watchlist item is not present if not logged in.
|
|
|
|
$wlItem = $content_navigation['user-menu']['watchlist'] ?? null;
|
|
|
|
if ( $wlItem !== null ) {
|
|
|
|
$content_navigation['vector-user-menu-overflow'] = [
|
|
|
|
'watchlist' => $wlItem + [
|
|
|
|
'button' => true,
|
|
|
|
'collapsible' => true,
|
|
|
|
'text-hidden' => true,
|
|
|
|
'id' => 'pt-watchlist-2',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
self::updateMenuItems( $content_navigation, 'vector-user-menu-overflow' );
|
|
|
|
}
|
|
|
|
|
2021-08-24 21:34:59 +00:00
|
|
|
if ( isset( $content_navigation['user-menu'] ) ) {
|
|
|
|
if ( self::isSkinVersionLegacy() ) {
|
|
|
|
// 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 {
|
|
|
|
// For modern Vector, rearrange some links in the personal toolbar.
|
|
|
|
self::updateUserLinksItems( $sk, $content_navigation );
|
|
|
|
}
|
2020-05-11 22:09:21 +00:00
|
|
|
}
|
2021-08-26 19:47:02 +00:00
|
|
|
|
|
|
|
if ( !self::isSkinVersionLegacy() ) {
|
|
|
|
// Upgrade preferences and notifications to icon buttons
|
|
|
|
// for extensions that have opted in.
|
|
|
|
if ( isset( $content_navigation['user-interface-preferences'] ) ) {
|
|
|
|
self::updateMenuItems(
|
2021-12-14 18:12:26 +00:00
|
|
|
$content_navigation, 'user-interface-preferences'
|
2021-08-26 19:47:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( isset( $content_navigation['notifications'] ) ) {
|
|
|
|
self::updateMenuItems(
|
2021-12-14 18:12:26 +00:00
|
|
|
$content_navigation, 'notifications'
|
2021-08-26 19:47:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 22:09:21 +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
|
|
|
/**
|
2021-09-09 22:13:48 +00:00
|
|
|
* Add Vector preferences to the user's Special:Preferences page directly underneath skins
|
|
|
|
* provided that $wgVectorSkinMigrationMode is not enabled.
|
[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
|
|
|
*
|
|
|
|
* @param User $user User whose preferences are being modified.
|
|
|
|
* @param array[] &$prefs Preferences description array, to be fed to a HTMLForm object.
|
|
|
|
*/
|
|
|
|
public static function onGetPreferences( User $user, array &$prefs ) {
|
|
|
|
if ( !self::getConfig( Constants::CONFIG_KEY_SHOW_SKIN_PREFERENCES ) ) {
|
|
|
|
// Do not add Vector skin specific preferences.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
// If migration mode was enabled, and the skin version is set to modern,
|
|
|
|
// switch over the skin.
|
|
|
|
if ( self::isMigrationMode() && !self::isSkinVersionLegacy() ) {
|
|
|
|
MediaWikiServices::getInstance()->getUserOptionsManager()->setOption(
|
|
|
|
$user,
|
|
|
|
Constants::PREF_KEY_SKIN,
|
|
|
|
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
|
|
|
// Preferences to add.
|
|
|
|
$vectorPrefs = [
|
|
|
|
Constants::PREF_KEY_SKIN_VERSION => [
|
2020-08-11 14:13:12 +00:00
|
|
|
'class' => HTMLLegacySkinVersionField::class,
|
[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
|
|
|
// The checkbox title.
|
|
|
|
'label-message' => 'prefs-vector-enable-vector-1-label',
|
|
|
|
// Show a little informational snippet underneath the checkbox.
|
|
|
|
'help-message' => 'prefs-vector-enable-vector-1-help',
|
|
|
|
// The tab location and title of the section to insert the checkbox. The bit after the slash
|
|
|
|
// indicates that a prefs-skin-prefs string will be provided.
|
2020-02-26 23:35:28 +00:00
|
|
|
'section' => 'rendering/skin/skin-prefs',
|
2020-08-11 14:13:12 +00:00
|
|
|
'default' => self::isSkinVersionLegacy(),
|
[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
|
|
|
// Only show this section when the Vector skin is checked. The JavaScript client also uses
|
|
|
|
// this state to determine whether to show or hide the whole section.
|
2021-09-09 22:13:48 +00:00
|
|
|
// If migration mode is enabled, the section is always hidden.
|
2022-01-16 13:01:54 +00:00
|
|
|
'hide-if' => self::isMigrationMode() ? [ '!==', 'skin', '0' ] :
|
|
|
|
[ '!==', 'skin', Constants::SKIN_NAME_LEGACY ],
|
[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-06-30 22:39:09 +00:00
|
|
|
Constants::PREF_KEY_SIDEBAR_VISIBLE => [
|
|
|
|
'type' => 'api',
|
|
|
|
'default' => self::getConfig( Constants::CONFIG_KEY_DEFAULT_SIDEBAR_VISIBLE_FOR_AUTHORISED_USER )
|
|
|
|
],
|
[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
|
|
|
];
|
|
|
|
|
|
|
|
// Seek the skin preference section to add Vector preferences just below it.
|
2021-09-09 22:13:48 +00:00
|
|
|
$skinSectionIndex = array_search(
|
|
|
|
Constants::PREF_KEY_SKIN, array_keys( $prefs )
|
|
|
|
);
|
[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
|
|
|
if ( $skinSectionIndex !== false ) {
|
|
|
|
// Skin preference section found. Inject Vector skin-specific preferences just below it.
|
|
|
|
// This pattern can be found in Popups too. See T246162.
|
|
|
|
$vectorSectionIndex = $skinSectionIndex + 1;
|
|
|
|
$prefs = array_slice( $prefs, 0, $vectorSectionIndex, true )
|
|
|
|
+ $vectorPrefs
|
|
|
|
+ array_slice( $prefs, $vectorSectionIndex, null, true );
|
|
|
|
} else {
|
|
|
|
// Skin preference section not found. Just append Vector skin-specific preferences.
|
|
|
|
$prefs += $vectorPrefs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderSiteStylesModulePages( string $skin, array &$pages ) {
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderSiteModulePages( string $skin, array &$pages ) {
|
|
|
|
if ( $skin === Constants::SKIN_NAME_MODERN ) {
|
|
|
|
$pages['MediaWiki:Vector.js'] = [ 'type' => 'script' ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
/**
|
|
|
|
* Hook executed on user's Special:Preferences form save. This is used to convert the boolean
|
|
|
|
* presentation of skin version to a version string. That is, a single preference change by the
|
|
|
|
* user may trigger two writes: a boolean followed by a string.
|
|
|
|
*
|
2021-09-09 22:13:48 +00:00
|
|
|
* @param array &$formData Form data submitted by user
|
[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
|
|
|
* @param HTMLForm $form A preferences form
|
|
|
|
* @param User $user Logged-in user
|
|
|
|
* @param bool &$result Variable defining is form save successful
|
|
|
|
* @param array $oldPreferences
|
|
|
|
*/
|
|
|
|
public static function onPreferencesFormPreSave(
|
2021-09-09 22:13:48 +00:00
|
|
|
array &$formData,
|
[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
|
|
|
HTMLForm $form,
|
|
|
|
User $user,
|
|
|
|
&$result,
|
|
|
|
$oldPreferences
|
|
|
|
) {
|
2021-09-09 22:13:48 +00:00
|
|
|
$userManager = MediaWikiServices::getInstance()->getUserOptionsManager();
|
|
|
|
$skinVersion = $formData[ Constants::PREF_KEY_SKIN_VERSION ] ?? '';
|
|
|
|
$skin = $formData[ Constants::PREF_KEY_SKIN ] ?? '';
|
|
|
|
$isVectorEnabled = self::isVectorSkin( $skin );
|
|
|
|
|
|
|
|
if (
|
|
|
|
self::isMigrationMode() &&
|
|
|
|
$skin === Constants::SKIN_NAME_LEGACY &&
|
|
|
|
$skinVersion === Constants::SKIN_VERSION_LATEST
|
|
|
|
) {
|
|
|
|
// Mismatch between skin and version. Use skin.
|
|
|
|
$userManager->setOption(
|
|
|
|
$user,
|
|
|
|
Constants::PREF_KEY_SKIN_VERSION,
|
|
|
|
Constants::SKIN_VERSION_LEGACY
|
|
|
|
);
|
|
|
|
}
|
2020-08-11 14:13:12 +00:00
|
|
|
|
|
|
|
if ( !$isVectorEnabled && array_key_exists( Constants::PREF_KEY_SKIN_VERSION, $oldPreferences ) ) {
|
[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
|
|
|
// The setting was cleared. However, this is likely because a different skin was chosen and
|
|
|
|
// the skin version preference was hidden.
|
2021-09-09 22:13:48 +00:00
|
|
|
$userManager->setOption(
|
2021-03-30 21:50:11 +00:00
|
|
|
$user,
|
2020-08-11 14:13:12 +00:00
|
|
|
Constants::PREF_KEY_SKIN_VERSION,
|
|
|
|
$oldPreferences[ Constants::PREF_KEY_SKIN_VERSION ]
|
|
|
|
);
|
[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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 22:13:48 +00:00
|
|
|
/**
|
|
|
|
* Check whether we can start migrating users to use skin preference.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private static function isMigrationMode(): bool {
|
|
|
|
return self::getConfig( 'VectorSkinMigrationMode' );
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
|
*/
|
|
|
|
public static function onLocalUserCreated( User $user, $isAutoCreated ) {
|
|
|
|
$default = self::getConfig( Constants::CONFIG_KEY_DEFAULT_SKIN_VERSION_FOR_NEW_ACCOUNTS );
|
2021-09-09 22:13:48 +00:00
|
|
|
$optionsManager = MediaWikiServices::getInstance()->getUserOptionsManager();
|
[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
|
|
|
// Permanently set the default preference. The user can later change this preference, however,
|
|
|
|
// self::onLocalUserCreated() will not be executed for that account again.
|
2021-09-09 22:13:48 +00:00
|
|
|
$optionsManager->setOption(
|
2021-03-30 21:50:11 +00:00
|
|
|
$user,
|
|
|
|
Constants::PREF_KEY_SKIN_VERSION,
|
|
|
|
$default
|
|
|
|
);
|
2021-09-09 22:13:48 +00:00
|
|
|
|
|
|
|
// Also set the skin key if migration mode is enabled.
|
|
|
|
if ( self::isMigrationMode() ) {
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public static function onOutputPageBodyAttributes( OutputPage $out, Skin $sk, &$bodyAttrs ) {
|
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;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
if ( self::isSkinVersionLegacy() ) {
|
2020-06-18 12:52:00 +00:00
|
|
|
$bodyAttrs['class'] .= ' skin-vector-legacy';
|
2021-09-09 22:13:48 +00:00
|
|
|
} else {
|
|
|
|
// The modern Vector skin must also carry skin-vector for compatibility with older
|
|
|
|
// skins.
|
|
|
|
$bodyAttrs['class'] .= ' skin-vector';
|
Implement Page, Workspace, Content, and Article Toolbar Containers
This patch closely follows the desired guidelines/desired
styles Alex Hollender has put forth in his prototype, but uses
multiple containers to achieve this look since our DOM order/structure
is different than the DOM structure in the prototype. The following
containers are used, but unlike his prototype, they are sometimes used
more than once:
* Page Container: Contains every other container and limits the overall
max-width of the white part of the page.
* Workspace Container: Contains the sidebar and content container. The
sidebar is displaced ~30 pixels to the start (left) of the workspace
container at all times.
* Content Container: Contains the content. The max-width of this changes
depending on whether you are on a special page/history page vs. other
pages.
* Article Toolbar Container: Contains the article toolbar. The max-width
of this is always the same as the max-width of the article content as we
don't want the toolbar to move when going from the article page to the
history/special page.
Changes to be aware:
* To test locally, `$wgVectorLayoutMaxWidth = true;`. This design is
temporarily feature flagged and defaults to being "off".
* Note that layout-max-width.less is a temporary file made to meet the
feature flag requirement of T246420 (intended to derisk the deployment).
After the deploy, we should merge most if not all of the rules into
layout.less where the max-width design will become the default.
* Per Jon's code review comment, I have relaxed the indenting of
skin.mustache to make the diff easier to reason about. If desired, the
correct indenting can be achieved in a (much less risky) follow-up
commit.
Bug: T246420
Bug: T153043
Change-Id: Ie49f629bc705850c6996164a516957476c034048
2020-06-23 18:02:32 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 19:52:15 +00:00
|
|
|
// Determine the search widget treatment to send to the user
|
2021-01-26 23:42:00 +00:00
|
|
|
if ( VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_USE_WVUI_SEARCH ) ) {
|
2020-11-19 17:12:53 +00:00
|
|
|
$bodyAttrs['class'] .= ' skin-vector-search-vue';
|
|
|
|
}
|
2021-01-06 21:50:19 +00:00
|
|
|
|
2021-01-26 23:42:00 +00:00
|
|
|
$config = $sk->getConfig();
|
2021-01-18 19:52:15 +00:00
|
|
|
// Should we disable the max-width styling?
|
2021-01-26 23:42:00 +00:00
|
|
|
if ( !self::isSkinVersionLegacy() && $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';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public static function onMakeGlobalVariablesScript( &$vars, OutputPage $out ) {
|
2021-09-09 22:13:48 +00:00
|
|
|
$skin = $out->getSkin();
|
|
|
|
if ( !self::isVectorSkin( $skin->getSkinName() ) ) {
|
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
|
|
|
|
2020-12-18 02:51:28 +00:00
|
|
|
if ( $user->isRegistered() && self::isSkinVersionLegacy() ) {
|
2020-08-12 15:05:06 +00:00
|
|
|
$vars[ 'wgVectorDisableSidebarPersistence' ] =
|
2020-07-15 21:27:09 +00:00
|
|
|
self::getConfig(
|
|
|
|
Constants::CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE
|
|
|
|
);
|
|
|
|
}
|
2021-12-14 21:59:16 +00:00
|
|
|
|
|
|
|
// [[phab:T297758]] ensure old Vector is the same as new Vector
|
|
|
|
// from a user script / gadget point of view.
|
|
|
|
if ( self::isSkinVersionLegacy() ) {
|
|
|
|
$vars[ 'skin' ] = 'vector';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array &$vars Array of variables to be added into the output.
|
|
|
|
* @param string $skin
|
|
|
|
* @param Config $config
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderGetConfigVars( array &$vars, string $skin, Config $config ) {
|
|
|
|
// [[phab:T297758]] ensure old Vector is the same as new Vector
|
|
|
|
// from a user script / gadget point of view.
|
|
|
|
if ( self::isVectorSkin( $skin ) ) {
|
|
|
|
$vars['skin'] = 'vector';
|
|
|
|
}
|
2020-07-15 21:27:09 +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
|
|
|
/**
|
|
|
|
* Get a configuration variable such as `Constants::CONFIG_KEY_SHOW_SKIN_PREFERENCES`.
|
|
|
|
*
|
|
|
|
* @param string $name Name of configuration option.
|
|
|
|
* @return mixed Value configured.
|
|
|
|
* @throws \ConfigException
|
|
|
|
*/
|
|
|
|
private static function getConfig( $name ) {
|
2020-04-28 21:02:15 +00:00
|
|
|
return self::getServiceConfig()->get( $name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Config
|
|
|
|
*/
|
|
|
|
private static function getServiceConfig() {
|
|
|
|
return MediaWikiServices::getInstance()->getService( Constants::SERVICE_CONFIG );
|
[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.
|
|
|
|
*
|
|
|
|
* @see VectorServices::getFeatureManager
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private static function isSkinVersionLegacy(): bool {
|
|
|
|
return !VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_LATEST_SKIN );
|
|
|
|
}
|
2017-06-30 19:21:16 +00:00
|
|
|
}
|