diff --git a/includes/Hooks.php b/includes/Hooks.php index 3a7e950cd..d5badcac7 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -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'; + } } /** diff --git a/includes/ResourceLoader/VectorResourceLoaderUserModule.php b/includes/ResourceLoader/VectorResourceLoaderUserModule.php new file mode 100644 index 000000000..edcd580e5 --- /dev/null +++ b/includes/ResourceLoader/VectorResourceLoaderUserModule.php @@ -0,0 +1,25 @@ +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; + } +} diff --git a/includes/ResourceLoader/VectorResourceLoaderUserStylesModule.php b/includes/ResourceLoader/VectorResourceLoaderUserStylesModule.php new file mode 100644 index 000000000..2dfff04b8 --- /dev/null +++ b/includes/ResourceLoader/VectorResourceLoaderUserStylesModule.php @@ -0,0 +1,25 @@ +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; + } +} diff --git a/includes/SkinVector22.php b/includes/SkinVector22.php index b596f3a3d..30397cd59 100644 --- a/includes/SkinVector22.php +++ b/includes/SkinVector22.php @@ -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', ]; diff --git a/skin.json b/skin.json index 38ad9a7ac..120d6f170 100644 --- a/skin.json +++ b/skin.json @@ -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",