Merge "Allow preview on certain article titles"

This commit is contained in:
jenkins-bot 2022-08-09 16:02:46 +00:00 committed by Gerrit Code Review
commit 6129fef3a0
2 changed files with 37 additions and 2 deletions

View File

@ -3,9 +3,11 @@
namespace MediaWiki\Skins\Vector;
use Config;
use IContextSource;
use MediaWiki\Auth\Hook\LocalUserCreatedHook;
use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
use MediaWiki\Hook\OutputPageBodyAttributesHook;
use MediaWiki\Hook\RequestContextCreateSkinHook;
use MediaWiki\MediaWikiServices;
use MediaWiki\Preferences\Hook\GetPreferencesHook;
use MediaWiki\ResourceLoader as RL;
@ -34,6 +36,7 @@ class Hooks implements
OutputPageBodyAttributesHook,
ResourceLoaderSiteModulePagesHook,
ResourceLoaderSiteStylesModulePagesHook,
RequestContextCreateSkinHook,
SkinPageReadyConfigHook
{
/**
@ -621,6 +624,31 @@ class Hooks implements
}
}
/**
* Temporary RequestContextCreateSkin hook handler.
* Switches to new Vector on certain pages.
*
* @see https://www.mediawiki.org/wiki/Manual:Hooks/RequestContextCreateSkin
*
* @param IContextSource $context The RequestContext object the skin is being created for.
* @param Skin|null|string &$skin A variable reference you may set a Skin instance or string
* key on to override the skin that will be used for the context.
* @return bool|void
*/
public function onRequestContextCreateSkin( $context, &$skin ) {
if ( !$skin ) {
// user is anonymous
$user = $context->getUser();
$config = $context->getConfig();
$titles = $config->get( 'Vector2022PreviewPages' );
$title = $context->getTitle();
$titleText = $title ? $title->getPrefixedText() : null;
if ( $titleText && $user->isAnon() && in_array( $titleText, $titles ) ) {
$skin = 'vector-2022';
}
}
}
/**
* Per the $options configuration (for use with $wgVectorMaxWidthOptions)
* determine whether max-width should be disabled on the page.
@ -708,15 +736,17 @@ class Hooks implements
if ( !self::isVectorSkin( $skinName ) ) {
return;
}
$config = $out->getConfig();
$user = $out->getUser();
if ( $user->isRegistered() && self::isSkinVersionLegacy( $skinName ) ) {
$vars[ 'wgVectorDisableSidebarPersistence' ] =
$out->getConfig()->get(
$config->get(
Constants::CONFIG_KEY_DISABLE_SIDEBAR_PERSISTENCE
);
}
// Must be exposed to CentralNotice banners via mw.config
$vars[ 'wgVector2022PreviewPages' ] = $config->get( 'Vector2022PreviewPages' );
}
/**

View File

@ -147,6 +147,7 @@
}
},
"Hooks": {
"RequestContextCreateSkin": "VectorHooks",
"GetPreferences": "VectorHooks",
"LocalUserCreated": "VectorHooks",
"MakeGlobalVariablesScript": "VectorHooks",
@ -419,6 +420,10 @@
}
},
"config": {
"Vector2022PreviewPages": {
"value": [],
"description": "Temporary configuration flag for allowing users to preview the new Vector skin."
},
"VectorSearchHost": {
"value": "",
"description": "Override default search API. Can be used with $wgDisableTextSearch and $wgSearchForwardUrl to mimic user experience on production."