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;
|
2021-04-29 00:47:25 +00:00
|
|
|
use Vector\FeatureManagement\Requirements\LanguageInHeaderTreatmentRequirement;
|
2020-04-20 16:38:01 +00:00
|
|
|
use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement;
|
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 ) {
|
[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
|
|
|
return $services->getService( 'ConfigFactory' )->makeConfig( Constants::SKIN_NAME );
|
|
|
|
},
|
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(),
|
|
|
|
$services->getService( Constants::SERVICE_CONFIG )
|
|
|
|
)
|
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(
|
|
|
|
new LanguageInHeaderTreatmentRequirement(
|
|
|
|
$services->getMainConfig(),
|
|
|
|
$context->getUser(),
|
|
|
|
$context->getRequest(),
|
|
|
|
CentralIdLookup::factoryNonLocal()
|
|
|
|
)
|
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-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-04-30 02:54:54 +00:00
|
|
|
// Feature: Consolidate personal menu links
|
|
|
|
// ================================
|
|
|
|
$consolidateUserLinksConfig = $services->getMainConfig()->get( Constants::CONFIG_CONSOLIDATE_USER_LINKS );
|
|
|
|
$featureManager->registerSimpleRequirement(
|
|
|
|
Constants::REQUIREMENT_CONSOLIDATE_USER_LINKS,
|
|
|
|
$consolidateUserLinksConfig[ $context->getUser()->isRegistered() ? 'logged_in' : 'logged_out' ]
|
|
|
|
);
|
|
|
|
|
|
|
|
$featureManager->registerFeature(
|
|
|
|
Constants::FEATURE_CONSOLIDATE_USER_LINKS,
|
|
|
|
[
|
|
|
|
Constants::REQUIREMENT_CONSOLIDATE_USER_LINKS
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2020-03-13 17:22:59 +00:00
|
|
|
return $featureManager;
|
2020-02-20 16:37:33 +00:00
|
|
|
}
|
|
|
|
];
|