Merge "Drop the LatestSkinVersionRequirement"
This commit is contained in:
commit
19f114281a
|
@ -88,16 +88,6 @@ final class Constants {
|
||||||
*/
|
*/
|
||||||
public const REQUIREMENT_FULLY_INITIALISED = 'FullyInitialised';
|
public const REQUIREMENT_FULLY_INITIALISED = 'FullyInitialised';
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public const REQUIREMENT_LATEST_SKIN_VERSION = 'LatestSkinVersion';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public const FEATURE_LATEST_SKIN = 'LatestSkin';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
@ -142,18 +132,6 @@ final class Constants {
|
||||||
*/
|
*/
|
||||||
public const QUERY_PARAM_LANGUAGE_IN_HEADER = 'languageinheader';
|
public const QUERY_PARAM_LANGUAGE_IN_HEADER = 'languageinheader';
|
||||||
|
|
||||||
/**
|
|
||||||
* Override the skin version user preference and site Config. See readme.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public const QUERY_PARAM_SKIN_VERSION = 'useskinversion';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override the skin user preference and site Config. See readme.
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public const QUERY_PARAM_SKIN = 'useskin';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,91 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Vector\FeatureManagement\Requirements;
|
|
||||||
|
|
||||||
use MediaWiki\User\UserOptionsLookup;
|
|
||||||
use User;
|
|
||||||
use Vector\Constants;
|
|
||||||
use Vector\FeatureManagement\Requirement;
|
|
||||||
use WebRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the current skin is modern Vector.
|
|
||||||
*
|
|
||||||
* @unstable
|
|
||||||
*
|
|
||||||
* @package Vector\FeatureManagement\Requirements
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class LatestSkinVersionRequirement implements Requirement {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var WebRequest
|
|
||||||
*/
|
|
||||||
private $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var User
|
|
||||||
*/
|
|
||||||
private $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var UserOptionsLookup
|
|
||||||
*/
|
|
||||||
private $userOptionsLookup;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constructor accepts all dependencies needed to obtain the skin version.
|
|
||||||
*
|
|
||||||
* @param WebRequest $request
|
|
||||||
* @param User $user
|
|
||||||
* @param UserOptionsLookup $userOptionsLookup
|
|
||||||
*/
|
|
||||||
public function __construct( WebRequest $request, User $user, UserOptionsLookup $userOptionsLookup ) {
|
|
||||||
$this->request = $request;
|
|
||||||
$this->user = $user;
|
|
||||||
$this->userOptionsLookup = $userOptionsLookup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getName(): string {
|
|
||||||
return Constants::REQUIREMENT_LATEST_SKIN_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
* @throws \ConfigException
|
|
||||||
*/
|
|
||||||
public function isMet(): bool {
|
|
||||||
$useSkin = $this->request->getVal( 'useskin' );
|
|
||||||
$user = $this->user;
|
|
||||||
if ( !$useSkin && $user->isSafeToLoad() ) {
|
|
||||||
$useSkin = $this->userOptionsLookup->getOption(
|
|
||||||
$user,
|
|
||||||
Constants::PREF_KEY_SKIN
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $useSkin === Constants::SKIN_NAME_MODERN;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -627,13 +627,6 @@ class Hooks {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function isSkinVersionLegacy( $skinName ): bool {
|
private static function isSkinVersionLegacy( $skinName ): bool {
|
||||||
if ( $skinName === Constants::SKIN_NAME_MODERN ) {
|
return $skinName === Constants::SKIN_NAME_LEGACY;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$isLatestSkinFeatureEnabled = VectorServices::getFeatureManager()
|
|
||||||
->isFeatureEnabled( Constants::FEATURE_LATEST_SKIN );
|
|
||||||
|
|
||||||
return !$isLatestSkinFeatureEnabled;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ use MediaWiki\MediaWikiServices;
|
||||||
use Vector\Constants;
|
use Vector\Constants;
|
||||||
use Vector\FeatureManagement\FeatureManager;
|
use Vector\FeatureManagement\FeatureManager;
|
||||||
use Vector\FeatureManagement\Requirements\DynamicConfigRequirement;
|
use Vector\FeatureManagement\Requirements\DynamicConfigRequirement;
|
||||||
use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement;
|
|
||||||
use Vector\FeatureManagement\Requirements\OverridableConfigRequirement;
|
use Vector\FeatureManagement\Requirements\OverridableConfigRequirement;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -44,26 +43,8 @@ return [
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Feature: Latest skin
|
|
||||||
// ====================
|
|
||||||
$context = RequestContext::getMain();
|
$context = RequestContext::getMain();
|
||||||
|
|
||||||
$featureManager->registerRequirement(
|
|
||||||
new LatestSkinVersionRequirement(
|
|
||||||
$context->getRequest(),
|
|
||||||
$context->getUser(),
|
|
||||||
$services->getUserOptionsLookup()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$featureManager->registerFeature(
|
|
||||||
Constants::FEATURE_LATEST_SKIN,
|
|
||||||
[
|
|
||||||
Constants::REQUIREMENT_FULLY_INITIALISED,
|
|
||||||
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Feature: Languages in sidebar
|
// Feature: Languages in sidebar
|
||||||
// ================================
|
// ================================
|
||||||
$featureManager->registerRequirement(
|
$featureManager->registerRequirement(
|
||||||
|
@ -113,7 +94,6 @@ return [
|
||||||
Constants::FEATURE_LANGUAGE_IN_HEADER,
|
Constants::FEATURE_LANGUAGE_IN_HEADER,
|
||||||
[
|
[
|
||||||
Constants::REQUIREMENT_FULLY_INITIALISED,
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
||||||
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
||||||
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -142,7 +122,6 @@ return [
|
||||||
Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER,
|
Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER,
|
||||||
[
|
[
|
||||||
Constants::REQUIREMENT_FULLY_INITIALISED,
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
||||||
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
||||||
Constants::REQUIREMENT_IS_MAIN_PAGE,
|
Constants::REQUIREMENT_IS_MAIN_PAGE,
|
||||||
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
||||||
Constants::REQUIREMENT_LANGUAGE_IN_MAIN_PAGE_HEADER
|
Constants::REQUIREMENT_LANGUAGE_IN_MAIN_PAGE_HEADER
|
||||||
|
@ -168,7 +147,6 @@ return [
|
||||||
Constants::FEATURE_LANGUAGE_ALERT_IN_SIDEBAR,
|
Constants::FEATURE_LANGUAGE_ALERT_IN_SIDEBAR,
|
||||||
[
|
[
|
||||||
Constants::REQUIREMENT_FULLY_INITIALISED,
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
||||||
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
||||||
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
|
||||||
Constants::REQUIREMENT_LANGUAGE_ALERT_IN_SIDEBAR
|
Constants::REQUIREMENT_LANGUAGE_ALERT_IN_SIDEBAR
|
||||||
]
|
]
|
||||||
|
@ -193,7 +171,6 @@ return [
|
||||||
Constants::FEATURE_TABLE_OF_CONTENTS,
|
Constants::FEATURE_TABLE_OF_CONTENTS,
|
||||||
[
|
[
|
||||||
Constants::REQUIREMENT_FULLY_INITIALISED,
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
||||||
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
||||||
Constants::REQUIREMENT_TABLE_OF_CONTENTS
|
Constants::REQUIREMENT_TABLE_OF_CONTENTS
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -230,7 +207,6 @@ return [
|
||||||
Constants::FEATURE_STICKY_HEADER,
|
Constants::FEATURE_STICKY_HEADER,
|
||||||
[
|
[
|
||||||
Constants::REQUIREMENT_FULLY_INITIALISED,
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
||||||
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
||||||
Constants::REQUIREMENT_STICKY_HEADER
|
Constants::REQUIREMENT_STICKY_HEADER
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -239,7 +215,6 @@ return [
|
||||||
Constants::FEATURE_STICKY_HEADER_EDIT,
|
Constants::FEATURE_STICKY_HEADER_EDIT,
|
||||||
[
|
[
|
||||||
Constants::REQUIREMENT_FULLY_INITIALISED,
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
||||||
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
|
||||||
Constants::REQUIREMENT_STICKY_HEADER,
|
Constants::REQUIREMENT_STICKY_HEADER,
|
||||||
Constants::REQUIREMENT_STICKY_HEADER_EDIT,
|
Constants::REQUIREMENT_STICKY_HEADER_EDIT,
|
||||||
]
|
]
|
||||||
|
|
|
@ -418,7 +418,7 @@ abstract class SkinVector extends SkinMustache {
|
||||||
* @param bool $includeEditIcons
|
* @param bool $includeEditIcons
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getStickyHeaderData( $searchBoxData, $includeEditIcons ): array {
|
final protected function getStickyHeaderData( $searchBoxData, $includeEditIcons ): array {
|
||||||
$btns = [
|
$btns = [
|
||||||
self::TALK_ICON,
|
self::TALK_ICON,
|
||||||
self::HISTORY_ICON,
|
self::HISTORY_ICON,
|
||||||
|
@ -534,21 +534,6 @@ abstract class SkinVector extends SkinMustache {
|
||||||
'searchform',
|
'searchform',
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
'data-vector-sticky-header' => $featureManager->isFeatureEnabled(
|
|
||||||
Constants::FEATURE_STICKY_HEADER
|
|
||||||
) ? $this->getStickyHeaderData(
|
|
||||||
$this->getSearchData(
|
|
||||||
$parentData['data-search-box'],
|
|
||||||
// Collapse inside search box is disabled.
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
'vector-sticky-search-form',
|
|
||||||
false
|
|
||||||
),
|
|
||||||
$featureManager->isFeatureEnabled(
|
|
||||||
Constants::FEATURE_STICKY_HEADER_EDIT
|
|
||||||
)
|
|
||||||
) : false,
|
|
||||||
'data-toc' => $this->getTocData( $parentData['data-toc'] ?? [] )
|
'data-toc' => $this->getTocData( $parentData['data-toc'] ?? [] )
|
||||||
] );
|
] );
|
||||||
|
|
||||||
|
@ -635,7 +620,7 @@ abstract class SkinVector extends SkinMustache {
|
||||||
* @param bool $autoExpandWidth
|
* @param bool $autoExpandWidth
|
||||||
* @return array modified version of $searchBoxData
|
* @return array modified version of $searchBoxData
|
||||||
*/
|
*/
|
||||||
private function getSearchData(
|
final protected function getSearchData(
|
||||||
array $searchBoxData,
|
array $searchBoxData,
|
||||||
bool $isCollapsible,
|
bool $isCollapsible,
|
||||||
bool $isPrimary,
|
bool $isPrimary,
|
||||||
|
|
|
@ -46,10 +46,27 @@ class SkinVector22 extends SkinVector {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getTemplateData(): array {
|
public function getTemplateData(): array {
|
||||||
$data = parent::getTemplateData();
|
$featureManager = VectorServices::getFeatureManager();
|
||||||
|
$parentData = parent::getTemplateData();
|
||||||
if ( !$this->isTableOfContentsVisibleInSidebar() ) {
|
if ( !$this->isTableOfContentsVisibleInSidebar() ) {
|
||||||
unset( $data['data-toc'] );
|
unset( $parentData['data-toc'] );
|
||||||
}
|
}
|
||||||
return $data;
|
return $parentData + [
|
||||||
|
'data-vector-sticky-header' => $featureManager->isFeatureEnabled(
|
||||||
|
Constants::FEATURE_STICKY_HEADER
|
||||||
|
) ? $this->getStickyHeaderData(
|
||||||
|
$this->getSearchData(
|
||||||
|
$parentData['data-search-box'],
|
||||||
|
// Collapse inside search box is disabled.
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
'vector-sticky-search-form',
|
||||||
|
false
|
||||||
|
),
|
||||||
|
$featureManager->isFeatureEnabled(
|
||||||
|
Constants::FEATURE_STICKY_HEADER_EDIT
|
||||||
|
)
|
||||||
|
) : false,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,11 @@ class SkinVectorLegacy extends SkinVector {
|
||||||
protected function isLegacy(): bool {
|
protected function isLegacy(): bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
protected function isLanguagesInContentAt( $location ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ use RuntimeException;
|
||||||
use Title;
|
use Title;
|
||||||
use User;
|
use User;
|
||||||
use Vector\Constants;
|
use Vector\Constants;
|
||||||
use Vector\FeatureManagement\FeatureManager;
|
|
||||||
use Vector\Hooks;
|
use Vector\Hooks;
|
||||||
use Vector\SkinVector22;
|
use Vector\SkinVector22;
|
||||||
use Vector\SkinVectorLegacy;
|
use Vector\SkinVectorLegacy;
|
||||||
|
@ -289,16 +288,6 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::getVectorResourceLoaderConfig
|
* @covers ::getVectorResourceLoaderConfig
|
||||||
* @dataProvider provideGetVectorResourceLoaderConfig
|
* @dataProvider provideGetVectorResourceLoaderConfig
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Vector\FeatureManagement\Tests;
|
|
||||||
|
|
||||||
use MediaWiki\User\UserOptionsLookup;
|
|
||||||
use User;
|
|
||||||
use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement;
|
|
||||||
use WebRequest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group Vector
|
|
||||||
* @group FeatureManagement
|
|
||||||
* @coversDefaultClass \Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement
|
|
||||||
*/
|
|
||||||
class LatestSkinVersionRequirementTest extends \MediaWikiUnitTestCase {
|
|
||||||
|
|
||||||
public function provideIsMet() {
|
|
||||||
// $version, $expected, $msg
|
|
||||||
yield 'not met' => [ 'vector', null, false, '"1" isn\'t considered latest.' ];
|
|
||||||
yield 'met' => [ 'vector-2022', null, true, '"2" is considered latest.' ];
|
|
||||||
yield 'met (useskin override)' => [ 'vector', 'vector-2022', true, 'useskin overrides' ];
|
|
||||||
yield 'not met (useskin override)' => [ 'vector-2022', 'vector', false, 'useskin overrides' ];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider provideIsMet
|
|
||||||
* @covers ::isMet
|
|
||||||
*/
|
|
||||||
public function testIsMet( $skin, $useSkin, $expected, $msg ) {
|
|
||||||
$user = $this->createMock( User::class );
|
|
||||||
$user->method( 'isRegistered' )->willReturn( true );
|
|
||||||
$user->method( 'isSafeToLoad' )->willReturn( true );
|
|
||||||
|
|
||||||
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
|
|
||||||
$userOptionsLookup->method( 'getOption' )
|
|
||||||
->willReturn( $skin );
|
|
||||||
|
|
||||||
$request = $this->createMock( WebRequest::class );
|
|
||||||
$request->method( 'getVal' )
|
|
||||||
->willReturn( $useSkin );
|
|
||||||
|
|
||||||
$requirement = new LatestSkinVersionRequirement(
|
|
||||||
$request,
|
|
||||||
$user,
|
|
||||||
$userOptionsLookup
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame( $expected, $requirement->isMet(), $msg );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue