[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
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* @file
|
|
|
|
* @ingroup skins
|
|
|
|
*/
|
|
|
|
|
2022-03-04 13:35:05 +00:00
|
|
|
namespace MediaWiki\Skins\Vector\Tests\Integration;
|
|
|
|
|
|
|
|
use HashConfig;
|
2021-03-30 21:50:11 +00:00
|
|
|
use MediaWiki\User\UserOptionsManager;
|
2022-03-04 13:35:05 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2022-03-04 15:45:45 +00:00
|
|
|
use ReflectionMethod;
|
2022-03-04 13:35:05 +00:00
|
|
|
use ResourceLoaderContext;
|
|
|
|
use RuntimeException;
|
|
|
|
use Title;
|
|
|
|
use User;
|
2020-08-12 15:05:06 +00:00
|
|
|
use Vector\Constants;
|
|
|
|
use Vector\FeatureManagement\FeatureManager;
|
[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\Hooks;
|
2022-03-04 20:24:10 +00:00
|
|
|
use Vector\SkinVector22;
|
2022-03-17 16:25:02 +00:00
|
|
|
use Vector\SkinVectorLegacy;
|
[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
|
|
|
|
|
|
|
/**
|
|
|
|
* Integration tests for Vector Hooks.
|
|
|
|
*
|
|
|
|
* @group Vector
|
|
|
|
* @coversDefaultClass \Vector\Hooks
|
|
|
|
*/
|
2021-03-25 04:06:14 +00:00
|
|
|
class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
2022-01-16 13:01:54 +00:00
|
|
|
private const HIDE_IF = [ '!==', 'skin', Constants::SKIN_NAME_LEGACY ];
|
2021-03-25 04:06:14 +00:00
|
|
|
|
|
|
|
private const SKIN_PREFS_SECTION = 'rendering/skin/skin-prefs';
|
2021-01-06 21:50:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $excludeMainPage
|
|
|
|
* @param array $excludeNamespaces
|
|
|
|
* @param array $include
|
|
|
|
* @param array $querystring
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private static function makeMaxWidthConfig(
|
|
|
|
$excludeMainPage,
|
|
|
|
$excludeNamespaces = [],
|
|
|
|
$include = [],
|
|
|
|
$querystring = []
|
|
|
|
) {
|
|
|
|
return [
|
|
|
|
'exclude' => [
|
|
|
|
'mainpage' => $excludeMainPage,
|
|
|
|
'namespaces' => $excludeNamespaces,
|
|
|
|
'querystring' => $querystring,
|
|
|
|
],
|
|
|
|
'include' => $include
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-12-14 19:24:32 +00:00
|
|
|
public function provideGetVectorResourceLoaderConfig() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'VectorWebABTestEnrollment' => [],
|
|
|
|
'VectorSearchHost' => 'en.wikipedia.org'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'wgVectorSearchHost' => 'en.wikipedia.org',
|
|
|
|
'wgVectorWebABTestEnrollment' => [],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'VectorWebABTestEnrollment' => [
|
|
|
|
'name' => 'vector.sticky_header',
|
|
|
|
'enabled' => true,
|
|
|
|
'buckets' => [
|
|
|
|
'unsampled' => [
|
|
|
|
'samplingRate' => 1,
|
|
|
|
],
|
|
|
|
'control' => [
|
|
|
|
'samplingRate' => 0
|
|
|
|
],
|
|
|
|
'stickyHeaderEnabled' => [
|
|
|
|
'samplingRate' => 0
|
|
|
|
],
|
|
|
|
'stickyHeaderDisabled' => [
|
|
|
|
'samplingRate' => 0
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'VectorSearchHost' => 'en.wikipedia.org'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'wgVectorSearchHost' => 'en.wikipedia.org',
|
|
|
|
'wgVectorWebABTestEnrollment' => [
|
|
|
|
'name' => 'vector.sticky_header',
|
|
|
|
'enabled' => true,
|
|
|
|
'buckets' => [
|
|
|
|
'unsampled' => [
|
|
|
|
'samplingRate' => 1,
|
|
|
|
],
|
|
|
|
'control' => [
|
|
|
|
'samplingRate' => 0
|
|
|
|
],
|
|
|
|
'stickyHeaderEnabled' => [
|
|
|
|
'samplingRate' => 0
|
|
|
|
],
|
|
|
|
'stickyHeaderDisabled' => [
|
|
|
|
'samplingRate' => 0
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideGetVectorResourceLoaderConfigWithExceptions() {
|
|
|
|
return [
|
|
|
|
# Bad experiment (no buckets)
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'VectorSearchHost' => 'en.wikipedia.org',
|
|
|
|
'VectorWebABTestEnrollment' => [
|
|
|
|
'name' => 'vector.sticky_header',
|
|
|
|
'enabled' => true,
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
# Bad experiment (no unsampled bucket)
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'VectorSearchHost' => 'en.wikipedia.org',
|
|
|
|
'VectorWebABTestEnrollment' => [
|
|
|
|
'name' => 'vector.sticky_header',
|
|
|
|
'enabled' => true,
|
|
|
|
'buckets' => [
|
|
|
|
'a' => [
|
|
|
|
'samplingRate' => 0
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
# Bad experiment (wrong format)
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'VectorSearchHost' => 'en.wikipedia.org',
|
|
|
|
'VectorWebABTestEnrollment' => [
|
|
|
|
'name' => 'vector.sticky_header',
|
|
|
|
'enabled' => true,
|
|
|
|
'buckets' => [
|
|
|
|
'unsampled' => 1,
|
|
|
|
]
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
# Bad experiment (samplingRate defined as string)
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'VectorSearchHost' => 'en.wikipedia.org',
|
|
|
|
'VectorWebABTestEnrollment' => [
|
|
|
|
'name' => 'vector.sticky_header',
|
|
|
|
'enabled' => true,
|
|
|
|
'buckets' => [
|
|
|
|
'unsampled' => [
|
|
|
|
'samplingRate' => '1'
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-01-06 21:50:19 +00:00
|
|
|
/**
|
|
|
|
* @covers ::shouldDisableMaxWidth
|
|
|
|
*/
|
|
|
|
public function providerShouldDisableMaxWidth() {
|
|
|
|
$excludeTalkFooConfig = self::makeMaxWidthConfig(
|
|
|
|
false,
|
|
|
|
[ NS_TALK ],
|
|
|
|
[ 'Talk:Foo' ],
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'No options, nothing disables max width',
|
|
|
|
[],
|
|
|
|
Title::makeTitle( NS_MAIN, 'Foo' ),
|
|
|
|
[],
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Main page disables max width if exclude.mainpage set',
|
|
|
|
self::makeMaxWidthConfig( true ),
|
|
|
|
Title::newMainPage(),
|
|
|
|
[],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Namespaces can be excluded',
|
|
|
|
self::makeMaxWidthConfig( false, [ NS_CATEGORY ] ),
|
|
|
|
Title::makeTitle( NS_CATEGORY, 'Category' ),
|
|
|
|
[],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Namespaces are included if not excluded',
|
|
|
|
self::makeMaxWidthConfig( false, [ NS_CATEGORY ] ),
|
|
|
|
Title::makeTitle( NS_SPECIAL, 'SpecialPages' ),
|
|
|
|
[],
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'More than one namespace can be included',
|
|
|
|
self::makeMaxWidthConfig( false, [ NS_CATEGORY, NS_SPECIAL ] ),
|
|
|
|
Title::makeTitle( NS_SPECIAL, 'Specialpages' ),
|
|
|
|
[],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Can be disabled on history page',
|
|
|
|
self::makeMaxWidthConfig(
|
|
|
|
false,
|
|
|
|
[
|
|
|
|
/* no namespaces excluded */
|
|
|
|
],
|
|
|
|
[
|
|
|
|
/* no includes */
|
|
|
|
],
|
|
|
|
[ 'action' => 'history' ]
|
|
|
|
),
|
|
|
|
Title::makeTitle( NS_MAIN, 'History page' ),
|
|
|
|
[ 'action' => 'history' ],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Include can override exclusions',
|
|
|
|
self::makeMaxWidthConfig(
|
|
|
|
false,
|
|
|
|
[ NS_CATEGORY, NS_SPECIAL ],
|
|
|
|
[ 'Special:Specialpages' ],
|
|
|
|
[ 'action' => 'history' ]
|
|
|
|
),
|
|
|
|
Title::makeTitle( NS_SPECIAL, 'Specialpages' ),
|
|
|
|
[ 'action' => 'history' ],
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Max width can be disabled on talk pages',
|
|
|
|
$excludeTalkFooConfig,
|
|
|
|
Title::makeTitle( NS_TALK, 'A talk page' ),
|
|
|
|
[],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'includes can be used to override any page in a disabled namespace',
|
|
|
|
$excludeTalkFooConfig,
|
|
|
|
Title::makeTitle( NS_TALK, 'Foo' ),
|
|
|
|
[],
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Excludes/includes are based on root title so should apply to subpages',
|
|
|
|
$excludeTalkFooConfig,
|
|
|
|
Title::makeTitle( NS_TALK, 'Foo/subpage' ),
|
|
|
|
[],
|
|
|
|
false
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::shouldDisableMaxWidth
|
|
|
|
* @dataProvider providerShouldDisableMaxWidth
|
|
|
|
*/
|
|
|
|
public function testShouldDisableMaxWidth(
|
|
|
|
$msg,
|
|
|
|
$options,
|
|
|
|
$title,
|
|
|
|
$requestValues,
|
|
|
|
$shouldDisableMaxWidth
|
|
|
|
) {
|
|
|
|
$this->assertSame(
|
|
|
|
$shouldDisableMaxWidth,
|
2021-03-25 04:06:14 +00:00
|
|
|
Hooks::shouldDisableMaxWidth( $options, $title, $requestValues ),
|
2021-01-06 21:50:19 +00:00
|
|
|
$msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:05:06 +00:00
|
|
|
private function setFeatureLatestSkinVersionIsEnabled( $isEnabled ) {
|
|
|
|
$featureManager = new FeatureManager();
|
|
|
|
$featureManager->registerSimpleRequirement( Constants::REQUIREMENT_LATEST_SKIN_VERSION, $isEnabled );
|
|
|
|
$featureManager->registerFeature( Constants::FEATURE_LATEST_SKIN, [
|
|
|
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION
|
|
|
|
] );
|
|
|
|
|
|
|
|
$this->setService( Constants::SERVICE_FEATURE_MANAGER, $featureManager );
|
|
|
|
}
|
|
|
|
|
2021-12-14 19:24:32 +00:00
|
|
|
/**
|
|
|
|
* @covers ::getVectorResourceLoaderConfig
|
|
|
|
* @dataProvider provideGetVectorResourceLoaderConfig
|
|
|
|
*/
|
|
|
|
public function testGetVectorResourceLoaderConfig( $configData, $expected ) {
|
|
|
|
$config = new HashConfig( $configData );
|
|
|
|
$vectorConfig = Hooks::getVectorResourceLoaderConfig(
|
|
|
|
$this->createMock( ResourceLoaderContext::class ),
|
|
|
|
$config
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
$vectorConfig,
|
|
|
|
$expected
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getVectorResourceLoaderConfig
|
|
|
|
* @dataProvider provideGetVectorResourceLoaderConfigWithExceptions
|
|
|
|
*/
|
|
|
|
public function testGetVectorResourceLoaderConfigWithExceptions( $configData ) {
|
|
|
|
$config = new HashConfig( $configData );
|
|
|
|
$this->expectException( RuntimeException::class );
|
|
|
|
$vectorConfig = Hooks::getVectorResourceLoaderConfig(
|
|
|
|
$this->createMock( ResourceLoaderContext::class ),
|
|
|
|
$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
|
|
|
/**
|
|
|
|
* @covers ::onLocalUserCreated
|
|
|
|
*/
|
|
|
|
public function testOnLocalUserCreatedLegacy() {
|
|
|
|
$config = new HashConfig( [
|
2020-08-11 14:13:12 +00:00
|
|
|
'VectorDefaultSkinVersionForNewAccounts' => Constants::SKIN_VERSION_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
|
|
|
] );
|
|
|
|
$this->setService( 'Vector.Config', $config );
|
|
|
|
|
2021-03-25 04:06:14 +00:00
|
|
|
$user = $this->createMock( User::class );
|
2021-03-30 21:50:11 +00:00
|
|
|
$userOptionsManager = $this->createMock( UserOptionsManager::class );
|
|
|
|
$userOptionsManager->expects( $this->once() )
|
2020-08-11 14:13:12 +00:00
|
|
|
->method( 'setOption' )
|
2022-01-20 22:14:19 +00:00
|
|
|
->with( $user, 'skin', Constants::SKIN_NAME_LEGACY );
|
2021-03-30 21:50:11 +00:00
|
|
|
$this->setService( 'UserOptionsManager', $userOptionsManager );
|
[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
|
|
|
$isAutoCreated = false;
|
|
|
|
Hooks::onLocalUserCreated( $user, $isAutoCreated );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::onLocalUserCreated
|
|
|
|
*/
|
|
|
|
public function testOnLocalUserCreatedLatest() {
|
|
|
|
$config = new HashConfig( [
|
2020-08-11 14:13:12 +00:00
|
|
|
'VectorDefaultSkinVersionForNewAccounts' => Constants::SKIN_VERSION_LATEST,
|
[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
|
|
|
] );
|
|
|
|
$this->setService( 'Vector.Config', $config );
|
|
|
|
|
2021-03-25 04:06:14 +00:00
|
|
|
$user = $this->createMock( User::class );
|
2021-03-30 21:50:11 +00:00
|
|
|
$userOptionsManager = $this->createMock( UserOptionsManager::class );
|
|
|
|
$userOptionsManager->expects( $this->once() )
|
2020-08-11 14:13:12 +00:00
|
|
|
->method( 'setOption' )
|
2022-01-20 22:14:19 +00:00
|
|
|
->with( $user, 'skin', Constants::SKIN_NAME_MODERN );
|
2021-03-30 21:50:11 +00:00
|
|
|
$this->setService( 'UserOptionsManager', $userOptionsManager );
|
[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
|
|
|
$isAutoCreated = false;
|
|
|
|
Hooks::onLocalUserCreated( $user, $isAutoCreated );
|
|
|
|
}
|
2020-05-11 22:09:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::onSkinTemplateNavigation
|
|
|
|
*/
|
|
|
|
public function testOnSkinTemplateNavigation() {
|
|
|
|
$this->setMwGlobals( [
|
|
|
|
'wgVectorUseIconWatch' => true
|
|
|
|
] );
|
2022-01-20 22:14:19 +00:00
|
|
|
$skin = new SkinVector22( [ 'name' => 'vector' ] );
|
2020-06-12 21:43:58 +00:00
|
|
|
$skin->getContext()->setTitle( Title::newFromText( 'Foo' ) );
|
2020-05-11 22:09:21 +00:00
|
|
|
$contentNavWatch = [
|
|
|
|
'actions' => [
|
|
|
|
'watch' => [ 'class' => 'watch' ],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$contentNavUnWatch = [
|
|
|
|
'actions' => [
|
|
|
|
'move' => [ 'class' => 'move' ],
|
|
|
|
'unwatch' => [],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
Hooks::onSkinTemplateNavigation( $skin, $contentNavUnWatch );
|
|
|
|
Hooks::onSkinTemplateNavigation( $skin, $contentNavWatch );
|
|
|
|
|
|
|
|
$this->assertTrue(
|
2021-06-30 22:55:09 +00:00
|
|
|
in_array( 'icon', $contentNavWatch['views']['watch']['class'] ) !== false,
|
2020-05-11 22:09:21 +00:00
|
|
|
'Watch list items require an "icon" class'
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
2021-06-30 22:55:09 +00:00
|
|
|
in_array( 'icon', $contentNavUnWatch['views']['unwatch']['class'] ) !== false,
|
2020-05-11 22:09:21 +00:00
|
|
|
'Unwatch list items require an "icon" class'
|
|
|
|
);
|
|
|
|
$this->assertFalse(
|
|
|
|
strpos( $contentNavUnWatch['actions']['move']['class'], 'icon' ) !== false,
|
|
|
|
'List item other than watch or unwatch should not have an "icon" class'
|
|
|
|
);
|
|
|
|
}
|
2022-03-04 15:45:45 +00:00
|
|
|
|
2022-03-17 16:25:02 +00:00
|
|
|
/**
|
|
|
|
* @covers ::updateUserLinksItems
|
|
|
|
*/
|
|
|
|
public function testUpdateUserLinksItems() {
|
|
|
|
$vector2022Skin = new SkinVector22( [ 'name' => 'vector-2022' ] );
|
|
|
|
$contentNav = [
|
|
|
|
'user-page' => [
|
|
|
|
'userpage' => [ 'class' => [], 'icon' => 'userpage' ],
|
|
|
|
],
|
|
|
|
'user-menu' => [
|
|
|
|
'login' => [ 'class' => [], 'icon' => 'login' ],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$contentNavWatchlist = [
|
|
|
|
'user-menu' => [
|
|
|
|
'watchlist' => [ 'class' => [], 'icon' => 'watchlist' ],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$vectorLegacySkin = new SkinVectorLegacy( [ 'name' => 'vector' ] );
|
|
|
|
$contentNavLegacy = [
|
|
|
|
'user-page' => [
|
|
|
|
'userpage' => [ 'class' => [], 'icon' => 'userpage' ],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
Hooks::onSkinTemplateNavigation( $vector2022Skin, $contentNav );
|
|
|
|
$this->assertFalse( isset( $contentNav['vector-user-menu-overflow'] ),
|
|
|
|
'watchlist data is not copied to vector-user-menu-overflow when not provided'
|
|
|
|
);
|
|
|
|
$this->assertFalse( isset( $contentNav['user-page']['login'] ),
|
|
|
|
'updateUserLinksDropdownItems is called when user-page is defined'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'mw-ui-button',
|
|
|
|
$contentNav['user-page']['userpage']['link-class'],
|
|
|
|
'updateUserLinksOverflowItems is called when not legacy'
|
|
|
|
);
|
|
|
|
|
|
|
|
Hooks::onSkinTemplateNavigation( $vector2022Skin, $contentNavWatchlist );
|
|
|
|
$this->assertTrue( isset( $contentNavWatchlist['vector-user-menu-overflow'] ),
|
|
|
|
'watchlist data is copied to vector-user-menu-overflow when provided'
|
|
|
|
);
|
|
|
|
|
|
|
|
Hooks::onSkinTemplateNavigation( $vectorLegacySkin, $contentNavLegacy );
|
|
|
|
$this->assertFalse( isset( $contentNavLegacy['user-page'] ),
|
|
|
|
'user-page is unset for legacy vector'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-04 15:45:45 +00:00
|
|
|
/**
|
|
|
|
* @covers ::updateUserLinksDropdownItems
|
|
|
|
*/
|
|
|
|
public function testUpdateUserLinksDropdownItems() {
|
|
|
|
$updateUserLinksDropdownItems = new ReflectionMethod(
|
|
|
|
Hooks::class,
|
|
|
|
'updateUserLinksDropdownItems'
|
|
|
|
);
|
|
|
|
$updateUserLinksDropdownItems->setAccessible( true );
|
2022-03-04 20:24:10 +00:00
|
|
|
$skin = new SkinVector22( [ 'name' => 'vector-2022' ] );
|
2022-03-04 15:45:45 +00:00
|
|
|
$contentAnon = [
|
|
|
|
'user-menu' => [
|
|
|
|
'anonuserpage' => [ 'class' => [], 'icon' => 'anonuserpage' ],
|
|
|
|
'createaccount' => [ 'class' => [], 'icon' => 'createaccount' ],
|
|
|
|
'login' => [ 'class' => [], 'icon' => 'login' ],
|
|
|
|
'login-private' => [ 'class' => [], 'icon' => 'login-private' ],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$updateUserLinksDropdownItems->invokeArgs( null, [ $skin, &$contentAnon ] );
|
|
|
|
$this->assertTrue(
|
|
|
|
count( $contentAnon['user-menu'] ) === 0,
|
|
|
|
'Anon user page, create account, login, and login private links are removed from anon user links dropdown'
|
|
|
|
);
|
|
|
|
// Registered user
|
|
|
|
$skin->getUser()->setId( '1' );
|
|
|
|
$contentRegistered = [
|
|
|
|
'user-menu' => [
|
|
|
|
'userpage' => [ 'class' => [], 'icon' => 'userpage' ],
|
|
|
|
'watchlist' => [ 'class' => [], 'icon' => 'watchlist' ],
|
|
|
|
'logout' => [ 'class' => [], 'icon' => 'logout' ],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$updateUserLinksDropdownItems->invokeArgs( null, [ $skin, &$contentRegistered ] );
|
|
|
|
$this->assertContains( 'user-links-collapsible-item', $contentRegistered['user-menu']['userpage']['class'],
|
|
|
|
'User page link in user links dropdown requires collapsible class'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'mw-ui-icon-before', $contentRegistered['user-menu']['userpage']['link-class'],
|
2022-03-04 20:24:10 +00:00
|
|
|
'User page link in user links dropdown requires before icon classes'
|
2022-03-04 15:45:45 +00:00
|
|
|
);
|
|
|
|
$this->assertContains( 'user-links-collapsible-item', $contentRegistered['user-menu']['watchlist']['class'],
|
|
|
|
'Watchlist link in user links dropdown requires collapsible class'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'mw-ui-icon-before', $contentRegistered['user-menu']['watchlist']['link-class'],
|
2022-03-04 20:24:10 +00:00
|
|
|
'Watchlist link in user links dropdown requires before icon classes'
|
2022-03-04 15:45:45 +00:00
|
|
|
);
|
|
|
|
$this->assertFalse( isset( $contentRegistered['user-menu']['logout'] ),
|
|
|
|
'Logout link in user links dropdown is not set'
|
|
|
|
);
|
|
|
|
}
|
2022-03-04 20:24:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::updateUserLinksOverflowItems
|
|
|
|
*/
|
|
|
|
public function testUpdateUserLinksOverflowItems() {
|
|
|
|
$updateUserLinksOverflowItems = new ReflectionMethod(
|
|
|
|
Hooks::class,
|
|
|
|
'updateUserLinksOverflowItems'
|
|
|
|
);
|
|
|
|
$updateUserLinksOverflowItems->setAccessible( true );
|
|
|
|
$content = [
|
|
|
|
'notifications' => [
|
|
|
|
'alert' => [ 'class' => [], 'icon' => 'alert' ],
|
|
|
|
],
|
|
|
|
'user-interface-preferences' => [
|
|
|
|
'uls' => [ 'class' => [], 'icon' => 'uls' ],
|
|
|
|
],
|
|
|
|
'user-page' => [
|
|
|
|
'userpage' => [ 'class' => [], 'icon' => 'userpage' ],
|
|
|
|
],
|
|
|
|
'vector-user-menu-overflow' => [
|
|
|
|
'watchlist' => [ 'class' => [], 'icon' => 'watchlist' ],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$updateUserLinksOverflowItems->invokeArgs( null, [ &$content ] );
|
|
|
|
$this->assertContains( 'user-links-collapsible-item',
|
|
|
|
$content['user-interface-preferences']['uls']['class'],
|
|
|
|
'ULS link in user links overflow requires collapsible class'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'user-links-collapsible-item',
|
|
|
|
$content['user-page']['userpage']['class'],
|
|
|
|
'User page link in user links overflow requires collapsible class'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'mw-ui-button',
|
|
|
|
$content['user-page']['userpage']['link-class'],
|
|
|
|
'User page link in user links overflow requires button classes'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'mw-ui-quiet',
|
|
|
|
$content['user-page']['userpage']['link-class'],
|
|
|
|
'User page link in user links overflow requires quiet button classes'
|
|
|
|
);
|
|
|
|
$this->assertNotContains( 'mw-ui-icon',
|
|
|
|
$content['user-page']['userpage']['class'],
|
|
|
|
'User page link in user links overflow does not have icon classes'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'user-links-collapsible-item',
|
|
|
|
$content['vector-user-menu-overflow']['watchlist']['class'],
|
|
|
|
'Watchlist link in user links overflow requires collapsible class'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'mw-ui-button',
|
|
|
|
$content['vector-user-menu-overflow']['watchlist']['link-class'],
|
|
|
|
'Watchlist link in user links overflow requires button classes'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'mw-ui-quiet',
|
|
|
|
$content['vector-user-menu-overflow']['watchlist']['link-class'],
|
|
|
|
'Watchlist link in user links overflow requires quiet button classes'
|
|
|
|
);
|
|
|
|
$this->assertContains( 'mw-ui-icon-element',
|
|
|
|
$content['vector-user-menu-overflow']['watchlist']['link-class'],
|
|
|
|
'Watchlist link in user links overflow hides text'
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$content['vector-user-menu-overflow']['watchlist']['id'] === 'pt-watchlist-2',
|
|
|
|
'Watchlist link in user links has unique id'
|
|
|
|
);
|
|
|
|
}
|
[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
|
|
|
}
|