Merge "Restore gadget support to new internal skins"

This commit is contained in:
jenkins-bot 2022-01-07 20:41:44 +00:00 committed by Gerrit Code Review
commit 0488310612
5 changed files with 104 additions and 0 deletions

View File

@ -430,6 +430,30 @@ class Hooks {
}
}
/**
* Adds MediaWiki:Vector.css as the skin style that controls classic Vector.
*
* @param string $skin
* @param array &$pages
*/
public static function onResourceLoaderSiteStylesModulePages( string $skin, array &$pages ) {
if ( $skin === Constants::SKIN_NAME_MODERN ) {
$pages['MediaWiki:Vector.css'] = [ 'type' => 'style' ];
}
}
/**
* Adds MediaWiki:Vector.css as the skin style that controls classic Vector.
*
* @param string $skin
* @param array &$pages
*/
public static function onResourceLoaderSiteModulePages( string $skin, array &$pages ) {
if ( $skin === Constants::SKIN_NAME_MODERN ) {
$pages['MediaWiki:Vector.js'] = [ 'type' => 'script' ];
}
}
/**
* Hook executed on user's Special:Preferences form save. This is used to convert the boolean
* presentation of skin version to a version string. That is, a single preference change by the
@ -659,6 +683,25 @@ class Hooks {
Constants::CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE
);
}
// [[phab:T297758]] ensure old Vector is the same as new Vector
// from a user script / gadget point of view.
if ( self::isSkinVersionLegacy() ) {
$vars[ 'skin' ] = 'vector';
}
}
/**
* @param array &$vars Array of variables to be added into the output.
* @param string $skin
* @param Config $config
*/
public static function onResourceLoaderGetConfigVars( array &$vars, string $skin, Config $config ) {
// [[phab:T297758]] ensure old Vector is the same as new Vector
// from a user script / gadget point of view.
if ( self::isVectorSkin( $skin ) ) {
$vars['skin'] = 'vector';
}
}
/**

View File

@ -0,0 +1,25 @@
<?php
namespace Vector\ResourceLoader;
use ResourceLoaderContext;
use ResourceLoaderUserModule;
use Vector\Constants;
class VectorResourceLoaderUserModule extends ResourceLoaderUserModule {
/**
* @inheritDoc
*/
protected function getPages( ResourceLoaderContext $context ) {
$skin = $context->getSkin();
$config = $this->getConfig();
$user = $context->getUserObj();
$pages = [];
if ( $config->get( 'AllowUserCss' ) && !$user->isAnon() && ( $skin === Constants::SKIN_NAME_MODERN ) ) {
$pages = parent::getPages( $context );
$userPage = $user->getUserPage()->getPrefixedDBkey();
$pages["$userPage/vector.js"] = [ 'type' => 'script' ];
}
return $pages;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Vector\ResourceLoader;
use ResourceLoaderContext;
use ResourceLoaderUserStylesModule;
use Vector\Constants;
class VectorResourceLoaderUserStylesModule extends ResourceLoaderUserStylesModule {
/**
* @inheritDoc
*/
protected function getPages( ResourceLoaderContext $context ) {
$skin = $context->getSkin();
$config = $this->getConfig();
$user = $context->getUserObj();
$pages = [];
if ( $config->get( 'AllowUserCss' ) && !$user->isAnon() && ( $skin === Constants::SKIN_NAME_MODERN ) ) {
$pages = parent::getPages( $context );
$userPage = $user->getUserPage()->getPrefixedDBkey();
$pages["$userPage/vector.css"] = [ 'type' => 'style' ];
}
return $pages;
}
}

View File

@ -33,6 +33,7 @@ class SkinVector22 extends SkinVector {
*/
public static function getScriptsOption() {
return [
'skins.vector.user',
'skins.vector.js',
'skins.vector.es6',
];
@ -47,6 +48,7 @@ class SkinVector22 extends SkinVector {
return [
'mediawiki.ui.button',
'skins.vector.styles',
'skins.vector.user.styles',
'skins.vector.icons',
'mediawiki.ui.icon',
];

View File

@ -115,6 +115,9 @@
"vector": "GlobalVarConfig::newInstance"
},
"Hooks": {
"ResourceLoaderGetConfigVars": "Vector\\Hooks::onResourceLoaderGetConfigVars",
"ResourceLoaderSiteModulePages": "Vector\\Hooks::onResourceLoaderSiteModulePages",
"ResourceLoaderSiteStylesModulePages": "Vector\\Hooks::onResourceLoaderSiteStylesModulePages",
"SkinPageReadyConfig": "Vector\\Hooks::onSkinPageReadyConfig",
"GetPreferences": "Vector\\Hooks::onGetPreferences",
"PreferencesFormPreSave": "Vector\\Hooks::onPreferencesFormPreSave",
@ -124,6 +127,12 @@
},
"@note": "When modifying skins.vector.styles definition, make sure the installer still works",
"ResourceModules": {
"skins.vector.user": {
"class": "Vector\\ResourceLoader\\VectorResourceLoaderUserModule"
},
"skins.vector.user.styles": {
"class": "Vector\\ResourceLoader\\VectorResourceLoaderUserStylesModule"
},
"skins.vector.search": {
"dependencies": [
"mediawiki.Uri",