mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-23 23:33:54 +00:00
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:
parent
7d2d50873f
commit
99cf6eb5be
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
25
includes/ResourceLoader/VectorResourceLoaderUserModule.php
Normal file
25
includes/ResourceLoader/VectorResourceLoaderUserModule.php
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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',
|
||||
];
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue