2020-02-20 16:37:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Service Wirings for Vector skin
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @since 1.35
|
|
|
|
*/
|
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
[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 Vector\Constants;
|
2020-02-20 16:37:33 +00:00
|
|
|
use Vector\FeatureManagement\FeatureManager;
|
2020-03-13 17:22:59 +00:00
|
|
|
use Vector\FeatureManagement\Requirements\DynamicConfigRequirement;
|
2020-04-20 16:38:01 +00:00
|
|
|
use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement;
|
2021-07-12 23:04:09 +00:00
|
|
|
use Vector\FeatureManagement\Requirements\OverridableConfigRequirement;
|
2021-01-26 23:42:00 +00:00
|
|
|
use Vector\FeatureManagement\Requirements\WvuiSearchTreatmentRequirement;
|
2020-04-28 21:02:15 +00:00
|
|
|
use Vector\SkinVersionLookup;
|
2020-02-20 16:37:33 +00:00
|
|
|
|
|
|
|
return [
|
2021-05-03 14:19:12 +00:00
|
|
|
Constants::SERVICE_CONFIG => static function ( MediaWikiServices $services ) {
|
2021-09-09 22:13:48 +00:00
|
|
|
return $services->getService( 'ConfigFactory' )->makeConfig( 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
|
|
|
},
|
2021-05-03 14:19:12 +00:00
|
|
|
Constants::SERVICE_FEATURE_MANAGER => static function ( MediaWikiServices $services ) {
|
2020-03-13 17:22:59 +00:00
|
|
|
$featureManager = new FeatureManager();
|
2020-03-25 20:36:44 +00:00
|
|
|
|
2020-04-29 14:13:27 +00:00
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new DynamicConfigRequirement(
|
2020-03-25 20:36:44 +00:00
|
|
|
$services->getMainConfig(),
|
|
|
|
Constants::CONFIG_KEY_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED
|
2020-04-29 14:13:27 +00:00
|
|
|
)
|
|
|
|
);
|
2020-03-13 17:22:59 +00:00
|
|
|
|
2020-04-20 16:38:01 +00:00
|
|
|
// Feature: Latest skin
|
|
|
|
// ====================
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
|
2020-04-29 14:13:27 +00:00
|
|
|
$featureManager->registerRequirement(
|
2020-04-20 16:38:01 +00:00
|
|
|
new LatestSkinVersionRequirement(
|
2020-04-28 21:02:15 +00:00
|
|
|
new SkinVersionLookup(
|
|
|
|
$context->getRequest(),
|
|
|
|
$context->getUser(),
|
2021-11-23 13:40:35 +00:00
|
|
|
$services->getService( Constants::SERVICE_CONFIG ),
|
|
|
|
$services->getUserOptionsLookup()
|
2020-04-28 21:02:15 +00:00
|
|
|
)
|
2020-04-20 16:38:01 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_LATEST_SKIN,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2020-08-18 21:30:25 +00:00
|
|
|
// Feature: Languages in sidebar
|
|
|
|
// ================================
|
2021-04-29 00:47:25 +00:00
|
|
|
$featureManager->registerRequirement(
|
2021-07-12 23:04:09 +00:00
|
|
|
new OverridableConfigRequirement(
|
2021-04-29 00:47:25 +00:00
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
2021-08-25 17:58:18 +00:00
|
|
|
$services->getCentralIdLookupFactory()->getNonLocalLookup(),
|
2021-07-12 23:04:09 +00:00
|
|
|
Constants::CONFIG_KEY_LANGUAGE_IN_HEADER,
|
|
|
|
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
|
|
|
Constants::QUERY_PARAM_LANGUAGE_IN_HEADER,
|
|
|
|
Constants::CONFIG_LANGUAGE_IN_HEADER_TREATMENT_AB_TEST
|
2021-04-29 00:47:25 +00:00
|
|
|
)
|
2020-08-18 21:30:25 +00:00
|
|
|
);
|
|
|
|
|
2021-08-05 14:30:31 +00:00
|
|
|
// ---
|
|
|
|
|
|
|
|
// Temporary T286932 - remove after languages A/B test is finished.
|
|
|
|
$requirementName = 'T286932';
|
|
|
|
|
|
|
|
// MultiConfig checks each config in turn, allowing us to override the main config for specific keys. In this
|
|
|
|
// case, override the "VectorLanguageInHeaderABTest" configuration value so that the following requirement
|
|
|
|
// always buckets the user as if the language treatment A/B test were running.
|
|
|
|
$config = new MultiConfig( [
|
|
|
|
new HashConfig( [
|
|
|
|
Constants::CONFIG_LANGUAGE_IN_HEADER_TREATMENT_AB_TEST => true,
|
|
|
|
] ),
|
|
|
|
$services->getMainConfig(),
|
|
|
|
] );
|
|
|
|
|
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new OverridableConfigRequirement(
|
|
|
|
$config,
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
2021-08-25 17:58:18 +00:00
|
|
|
$services->getCentralIdLookupFactory()->getNonLocalLookup(),
|
2021-08-05 14:30:31 +00:00
|
|
|
Constants::CONFIG_KEY_LANGUAGE_IN_HEADER,
|
|
|
|
$requirementName,
|
|
|
|
/* $overrideName = */ '',
|
|
|
|
Constants::CONFIG_LANGUAGE_IN_HEADER_TREATMENT_AB_TEST
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2020-08-18 21:30:25 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_LANGUAGE_IN_HEADER,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
|
|
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-12-03 23:33:21 +00:00
|
|
|
// Feature: T293470: Language in main page header
|
|
|
|
// ================================
|
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new OverridableConfigRequirement(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
|
|
|
null,
|
|
|
|
Constants::CONFIG_LANGUAGE_IN_MAIN_PAGE_HEADER,
|
|
|
|
Constants::REQUIREMENT_LANGUAGE_IN_MAIN_PAGE_HEADER,
|
|
|
|
Constants::QUERY_PARAM_LANGUAGE_IN_MAIN_PAGE_HEADER,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$featureManager->registerSimpleRequirement(
|
|
|
|
Constants::REQUIREMENT_IS_MAIN_PAGE,
|
|
|
|
$context->getTitle() ? $context->getTitle()->isMainPage() : false
|
|
|
|
);
|
|
|
|
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
|
|
Constants::REQUIREMENT_IS_MAIN_PAGE,
|
|
|
|
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
|
|
|
Constants::REQUIREMENT_LANGUAGE_IN_MAIN_PAGE_HEADER
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-12-07 20:28:58 +00:00
|
|
|
// Feature: T295555: Language switch alert in sidebar
|
|
|
|
// ================================
|
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new OverridableConfigRequirement(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
|
|
|
null,
|
|
|
|
Constants::CONFIG_LANGUAGE_ALERT_IN_SIDEBAR,
|
|
|
|
Constants::REQUIREMENT_LANGUAGE_ALERT_IN_SIDEBAR,
|
|
|
|
Constants::QUERY_PARAM_LANGUAGE_ALERT_IN_SIDEBAR,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_LANGUAGE_ALERT_IN_SIDEBAR,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
|
|
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
|
|
|
Constants::REQUIREMENT_LANGUAGE_ALERT_IN_SIDEBAR
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-12-14 19:58:54 +00:00
|
|
|
// Feature: T297610: Table of Contents
|
|
|
|
// ================================
|
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new OverridableConfigRequirement(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
|
|
|
null,
|
|
|
|
Constants::CONFIG_TABLE_OF_CONTENTS,
|
|
|
|
Constants::REQUIREMENT_TABLE_OF_CONTENTS,
|
|
|
|
Constants::QUERY_PARAM_TABLE_OF_CONTENTS,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_TABLE_OF_CONTENTS,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_TABLE_OF_CONTENTS
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-01-26 23:42:00 +00:00
|
|
|
// Feature: Use Wvui Search
|
|
|
|
// ================================
|
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new WvuiSearchTreatmentRequirement(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_USE_WVUI_SEARCH,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
|
|
Constants::REQUIREMENT_USE_WVUI_SEARCH
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-08-04 17:54:35 +00:00
|
|
|
// Feature: Sticky header
|
|
|
|
// ================================
|
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new OverridableConfigRequirement(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
|
|
|
null,
|
|
|
|
Constants::CONFIG_STICKY_HEADER,
|
|
|
|
Constants::REQUIREMENT_STICKY_HEADER,
|
|
|
|
Constants::QUERY_PARAM_STICKY_HEADER,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2021-10-26 21:34:05 +00:00
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new OverridableConfigRequirement(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
|
|
|
null,
|
|
|
|
Constants::CONFIG_STICKY_HEADER_EDIT,
|
|
|
|
Constants::REQUIREMENT_STICKY_HEADER_EDIT,
|
|
|
|
Constants::QUERY_PARAM_STICKY_HEADER_EDIT,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2021-12-14 18:12:26 +00:00
|
|
|
// Temporary feature flag for moving watchlist out of user menu
|
|
|
|
// Remove when the new watchlist icon is in OOUI
|
|
|
|
$featureManager->registerRequirement(
|
|
|
|
new OverridableConfigRequirement(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
|
|
|
null,
|
|
|
|
Constants::CONFIG_USER_LINKS_WATCHLIST,
|
|
|
|
Constants::REQUIREMENT_USER_LINKS_WATCHLIST,
|
|
|
|
Constants::QUERY_PARAM_USER_LINKS_WATCHLIST,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2021-08-04 17:54:35 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_STICKY_HEADER,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
|
|
Constants::REQUIREMENT_STICKY_HEADER
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-10-26 21:34:05 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_STICKY_HEADER_EDIT,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
|
|
Constants::REQUIREMENT_STICKY_HEADER,
|
|
|
|
Constants::REQUIREMENT_STICKY_HEADER_EDIT,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-12-14 18:12:26 +00:00
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_USER_LINKS_WATCHLIST,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
|
|
Constants::REQUIREMENT_USER_LINKS_WATCHLIST,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2020-03-13 17:22:59 +00:00
|
|
|
return $featureManager;
|
2020-02-20 16:37:33 +00:00
|
|
|
}
|
|
|
|
];
|