Merge "hooks: Don't use SkinVersionLookup directly"
This commit is contained in:
commit
de6ff025cc
|
@ -7,7 +7,6 @@ use ExtensionRegistry;
|
|||
use HTMLForm;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use OutputPage;
|
||||
use RequestContext;
|
||||
use ResourceLoaderContext;
|
||||
use Skin;
|
||||
use SkinTemplate;
|
||||
|
@ -52,10 +51,6 @@ class Hooks {
|
|||
return;
|
||||
}
|
||||
|
||||
$skinVersionLookup = new SkinVersionLookup(
|
||||
$out->getRequest(), $sk->getUser(), self::getServiceConfig()
|
||||
);
|
||||
|
||||
$mobile = false;
|
||||
if ( ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) ) {
|
||||
|
||||
|
@ -63,9 +58,9 @@ class Hooks {
|
|||
$mobile = $mobFrontContext->shouldDisplayMobileView();
|
||||
}
|
||||
|
||||
if ( $skinVersionLookup->isLegacy()
|
||||
&& ( $mobile || $sk->getConfig()->get( 'VectorResponsive' ) )
|
||||
) {
|
||||
if (
|
||||
self::isSkinVersionLegacy()
|
||||
&& ( $mobile || $sk->getConfig()->get( 'VectorResponsive' ) ) ) {
|
||||
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1' );
|
||||
$out->addModuleStyles( 'skins.vector.styles.responsive' );
|
||||
}
|
||||
|
@ -158,10 +153,6 @@ class Hooks {
|
|||
return;
|
||||
}
|
||||
|
||||
$skinVersionLookup = new SkinVersionLookup(
|
||||
RequestContext::getMain()->getRequest(), $user, self::getServiceConfig()
|
||||
);
|
||||
|
||||
// Preferences to add.
|
||||
$vectorPrefs = [
|
||||
Constants::PREF_KEY_SKIN_VERSION => [
|
||||
|
@ -174,7 +165,7 @@ class Hooks {
|
|||
// indicates that a prefs-skin-prefs string will be provided.
|
||||
'section' => 'rendering/skin/skin-prefs',
|
||||
// Convert the preference string to a boolean presentation.
|
||||
'default' => $skinVersionLookup->isLegacy() ? '1' : '0',
|
||||
'default' => self::isSkinVersionLegacy() ? '1' : '0',
|
||||
// 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.
|
||||
'hide-if' => [ '!==', 'wpskin', Constants::SKIN_NAME ]
|
||||
|
@ -264,20 +255,15 @@ class Hooks {
|
|||
return;
|
||||
}
|
||||
|
||||
$skinVersionLookup = new SkinVersionLookup(
|
||||
$out->getRequest(), $sk->getUser(), self::getServiceConfig()
|
||||
);
|
||||
|
||||
if ( $skinVersionLookup->isLegacy() ) {
|
||||
|
||||
// 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.
|
||||
// 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() ) {
|
||||
$bodyAttrs['class'] .= ' skin-vector-legacy';
|
||||
|
||||
return;
|
||||
|
@ -313,21 +299,17 @@ class Hooks {
|
|||
* @param OutputPage $out OutputPage instance calling the hook
|
||||
*/
|
||||
public static function onMakeGlobalVariablesScript( &$vars, OutputPage $out ) {
|
||||
if ( !$out->getSkin() instanceof SkinVector ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $out->getUser();
|
||||
|
||||
if ( $out->getSkin() instanceof SkinVector && $user->isRegistered() ) {
|
||||
$skinVersionLookup = new SkinVersionLookup(
|
||||
$out->getRequest(),
|
||||
$user,
|
||||
self::getServiceConfig()
|
||||
);
|
||||
|
||||
if ( !$skinVersionLookup->isLegacy() ) {
|
||||
$vars[ 'wgVectorDisableSidebarPersistence' ] =
|
||||
if ( $user->isLoggedIn() && self::isSkinVersionLegacy() ) {
|
||||
$vars[ 'wgVectorDisableSidebarPersistence' ] =
|
||||
self::getConfig(
|
||||
Constants::CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,4 +330,15 @@ class Hooks {
|
|||
private static function getServiceConfig() {
|
||||
return MediaWikiServices::getInstance()->getService( Constants::SERVICE_CONFIG );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Vector;
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Vector\FeatureManagement\FeatureManager;
|
||||
|
||||
/**
|
||||
* A service locator for services specific to Vector.
|
||||
*
|
||||
* @package Vector
|
||||
* @internal
|
||||
*/
|
||||
final class VectorServices {
|
||||
|
||||
/**
|
||||
* Gets the feature manager service.
|
||||
*
|
||||
* Per its definition in ServiceWiring.php, the feature manager service is bound to the global
|
||||
* request and user objects and to the _Vector.Config_ service.
|
||||
*
|
||||
* @return FeatureManager
|
||||
*/
|
||||
public static function getFeatureManager(): FeatureManager {
|
||||
return MediaWikiServices::getInstance()->getService( Constants::SERVICE_FEATURE_MANAGER );
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
* @ingroup skins
|
||||
*/
|
||||
|
||||
use Vector\Constants;
|
||||
use Vector\FeatureManagement\FeatureManager;
|
||||
use Vector\Hooks;
|
||||
|
||||
const SKIN_PREFS_SECTION = 'rendering/skin/skin-prefs';
|
||||
|
@ -29,17 +31,21 @@ class VectorHooksTest extends \MediaWikiTestCase {
|
|||
$this->assertSame( $prefs, [], 'No preferences are added.' );
|
||||
}
|
||||
|
||||
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 ::onGetPreferences
|
||||
*/
|
||||
public function testOnGetPreferencesShowPreferencesEnabledSkinSectionFoundLegacy() {
|
||||
$config = new HashConfig( [
|
||||
'VectorShowSkinPreferences' => true,
|
||||
// '1' is Legacy.
|
||||
'VectorDefaultSkinVersionForExistingAccounts' => '1',
|
||||
'VectorDefaultSidebarVisibleForAuthorisedUser' => true
|
||||
] );
|
||||
$this->setService( 'Vector.Config', $config );
|
||||
$this->setFeatureLatestSkinVersionIsEnabled( false );
|
||||
|
||||
$prefs = [
|
||||
'foo' => [],
|
||||
|
@ -75,13 +81,7 @@ class VectorHooksTest extends \MediaWikiTestCase {
|
|||
* @covers ::onGetPreferences
|
||||
*/
|
||||
public function testOnGetPreferencesShowPreferencesEnabledSkinSectionMissingLegacy() {
|
||||
$config = new HashConfig( [
|
||||
'VectorShowSkinPreferences' => true,
|
||||
// '1' is Legacy.
|
||||
'VectorDefaultSkinVersionForExistingAccounts' => '1',
|
||||
'VectorDefaultSidebarVisibleForAuthorisedUser' => true
|
||||
] );
|
||||
$this->setService( 'Vector.Config', $config );
|
||||
$this->setFeatureLatestSkinVersionIsEnabled( false );
|
||||
|
||||
$prefs = [
|
||||
'foo' => [],
|
||||
|
@ -115,13 +115,7 @@ class VectorHooksTest extends \MediaWikiTestCase {
|
|||
* @covers ::onGetPreferences
|
||||
*/
|
||||
public function testOnGetPreferencesShowPreferencesEnabledSkinSectionMissingLatest() {
|
||||
$config = new HashConfig( [
|
||||
'VectorShowSkinPreferences' => true,
|
||||
// '2' is latest.
|
||||
'VectorDefaultSkinVersionForExistingAccounts' => '2',
|
||||
'VectorDefaultSidebarVisibleForAuthorisedUser' => true
|
||||
] );
|
||||
$this->setService( 'Vector.Config', $config );
|
||||
$this->setFeatureLatestSkinVersionIsEnabled( true );
|
||||
|
||||
$prefs = [
|
||||
'foo' => [],
|
||||
|
|
Loading…
Reference in New Issue