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;
|
2020-06-12 12:31:08 +00:00
|
|
|
use ExtensionRegistry;
|
[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-11-19 17:12:53 +00:00
|
|
|
use ResourceLoader;
|
2020-07-14 13:07:09 +00:00
|
|
|
use ResourceLoaderContext;
|
2020-06-18 12:52:00 +00:00
|
|
|
use Skin;
|
2018-03-12 23:52:48 +00:00
|
|
|
use SkinTemplate;
|
2020-07-09 16:42:33 +00:00
|
|
|
use SkinVector;
|
[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 {
|
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 [
|
|
|
|
'wgVectorUseCoreSearch' => $config->get( 'VectorUseCoreSearch' ),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:58:10 +00:00
|
|
|
/**
|
|
|
|
* Passes config variables to skins.vector.search ResourceLoader module.
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
* @param Config $config
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getVectorWvuiSearchResourceLoaderConfig(
|
|
|
|
ResourceLoaderContext $context,
|
|
|
|
Config $config
|
|
|
|
) {
|
|
|
|
return $config->get( 'VectorWvuiSearchOptions' );
|
|
|
|
}
|
|
|
|
|
2017-06-30 19:21:16 +00:00
|
|
|
/**
|
|
|
|
* BeforePageDisplayMobile hook handler
|
|
|
|
*
|
2020-06-12 12:31:08 +00:00
|
|
|
* Make Legacy Vector responsive when $wgVectorResponsive = true
|
2017-06-30 19:21:16 +00:00
|
|
|
*
|
2020-06-12 12:31:08 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
|
2017-06-30 19:21:16 +00:00
|
|
|
* @param OutputPage $out
|
|
|
|
* @param SkinTemplate $sk
|
|
|
|
*/
|
2020-06-12 12:31:08 +00:00
|
|
|
public static function onBeforePageDisplay( OutputPage $out, $sk ) {
|
2020-07-09 16:42:33 +00:00
|
|
|
if ( !$sk instanceof SkinVector ) {
|
2020-06-12 12:31:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$mobile = false;
|
|
|
|
if ( ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) {
|
|
|
|
|
|
|
|
$mobFrontContext = MediaWikiServices::getInstance()->getService( 'MobileFrontend.Context' );
|
|
|
|
$mobile = $mobFrontContext->shouldDisplayMobileView();
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:05:06 +00:00
|
|
|
if (
|
|
|
|
self::isSkinVersionLegacy()
|
|
|
|
&& ( $mobile || $sk->getConfig()->get( 'VectorResponsive' ) ) ) {
|
2020-06-12 12:31:08 +00:00
|
|
|
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1' );
|
|
|
|
$out->addModuleStyles( 'skins.vector.styles.responsive' );
|
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
|
|
|
|
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
|
|
|
|
if ( $context->getSkin() !== 'vector' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the `mediawiki.page.ready` module not to wire up search.
|
|
|
|
// This allows us to use $wgVectorUseCoreSearch to decide to load
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:09:21 +00:00
|
|
|
/**
|
|
|
|
* Add icon class to an existing navigation item inside a menu hook.
|
|
|
|
* See self::onSkinTemplateNavigation.
|
|
|
|
* @param array $item
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private static function navigationLinkToIcon( array $item ) {
|
|
|
|
if ( !isset( $item['class'] ) ) {
|
|
|
|
$item['class'] = '';
|
|
|
|
}
|
|
|
|
$item['class'] = rtrim( 'icon ' . $item['class'], ' ' );
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upgrades Vector's watch action to a watchstar.
|
|
|
|
*
|
|
|
|
* @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();
|
2020-05-11 22:09:21 +00:00
|
|
|
if (
|
2020-06-12 21:43:58 +00:00
|
|
|
$sk->getConfig()->get( 'VectorUseIconWatch' ) &&
|
2020-05-11 22:09:21 +00:00
|
|
|
$sk->getSkinName() === 'vector' &&
|
2020-06-12 21:43:58 +00:00
|
|
|
$title && $title->canExist()
|
2020-05-11 22:09:21 +00:00
|
|
|
) {
|
|
|
|
$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 ) {
|
|
|
|
$content_navigation['views'][$key] = self::navigationLinkToIcon(
|
|
|
|
$content_navigation['actions'][$key]
|
|
|
|
);
|
|
|
|
unset( $content_navigation['actions'][$key] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
/**
|
|
|
|
* Add Vector preferences to the user's Special:Preferences page directly underneath skins.
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2020-08-11 14:13:12 +00:00
|
|
|
'hide-if' => [ '!==', 'wpskin', Constants::SKIN_NAME ],
|
[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.
|
|
|
|
$skinSectionIndex = array_search( 'skin', array_keys( $prefs ) );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param array $formData Form data submitted by user
|
|
|
|
* @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(
|
|
|
|
array $formData,
|
|
|
|
HTMLForm $form,
|
|
|
|
User $user,
|
|
|
|
&$result,
|
|
|
|
$oldPreferences
|
|
|
|
) {
|
|
|
|
$isVectorEnabled = ( $formData[ 'skin' ] ?? '' ) === Constants::SKIN_NAME;
|
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.
|
2020-08-11 14:13:12 +00:00
|
|
|
$user->setOption(
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 );
|
|
|
|
// Permanently set the default preference. The user can later change this preference, however,
|
|
|
|
// self::onLocalUserCreated() will not be executed for that account again.
|
|
|
|
$user->setOption( Constants::PREF_KEY_SKIN_VERSION, $default );
|
|
|
|
}
|
|
|
|
|
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 ) {
|
2020-08-01 18:05:57 +00:00
|
|
|
if ( !$sk instanceof SkinVector ) {
|
|
|
|
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';
|
2020-08-13 13:44:05 +00:00
|
|
|
|
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
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:12:53 +00:00
|
|
|
if ( !$out->getConfig()->get( 'VectorUseCoreSearch' ) ) {
|
|
|
|
$bodyAttrs['class'] .= ' skin-vector-search-vue';
|
|
|
|
}
|
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 ) {
|
2020-08-12 15:05:06 +00:00
|
|
|
if ( !$out->getSkin() instanceof SkinVector ) {
|
|
|
|
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-08-12 15:05:06 +00:00
|
|
|
if ( $user->isLoggedIn() && self::isSkinVersionLegacy() ) {
|
|
|
|
$vars[ 'wgVectorDisableSidebarPersistence' ] =
|
2020-07-15 21:27:09 +00:00
|
|
|
self::getConfig(
|
|
|
|
Constants::CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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 );
|
|
|
|
}
|
2020-11-19 17:12:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ResourceLoaderRegisterModules hook handler
|
|
|
|
*
|
|
|
|
* Register the new search module.
|
|
|
|
* This hook will be removed when wvui is available in core when the patch
|
|
|
|
* https://gerrit.wikimedia.org/r/c/mediawiki/core/+/641052 is merged.
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderRegisterModules
|
|
|
|
* @param ResourceLoader $rl
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderRegisterModules( ResourceLoader $rl ) {
|
|
|
|
if ( $rl->isModuleRegistered( 'wvui' ) ) {
|
|
|
|
$module = [
|
|
|
|
'localBasePath' => __DIR__ . '/..',
|
|
|
|
'remoteExtPath' => 'Vector',
|
|
|
|
'dependencies' => [
|
|
|
|
'mediawiki.util',
|
|
|
|
],
|
|
|
|
"packageFiles" => [
|
|
|
|
"resources/skins.vector.search/skins.vector.search.js",
|
2020-11-26 00:58:10 +00:00
|
|
|
"resources/skins.vector.search/App.vue",
|
|
|
|
[
|
|
|
|
"name" => "resources/skins.vector.search/config.json",
|
|
|
|
"callback" => "Vector\\Hooks::getVectorWvuiSearchResourceLoaderConfig"
|
|
|
|
]
|
2020-11-19 17:12:53 +00:00
|
|
|
],
|
|
|
|
"dependencies" => [
|
|
|
|
"wvui"
|
|
|
|
],
|
|
|
|
"messages" => [
|
|
|
|
"search",
|
|
|
|
"searchresults",
|
|
|
|
"searchsuggest-containing"
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$rl->register( 'skins.vector.search', $module );
|
|
|
|
}
|
|
|
|
}
|
2017-06-30 19:21:16 +00:00
|
|
|
}
|