Restore gadget support to new internal skins

For vector-2022 skin:
* MediaWiki:Vector.css and MediaWiki:Vector.js are added via the
existing ResourceLoader hook.
* User:<name>/vector.js and User:<name>/vector.css are added via new
VectorResourceLoader modules

Bug: T297758
Change-Id: I37e9a9d353695502213c7a651530995252d9505f
This commit is contained in:
jdlrobson 2021-12-14 13:59:16 -08:00 committed by Jdlrobson
parent 7d2d50873f
commit 99cf6eb5be
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",