Use HookHandlers for BetaFeatures hook

Bug: T271034
Change-Id: I74ca4a6645c05795c83df5474314d3d1dc556eb0
This commit is contained in:
Umherirrender 2023-08-15 18:10:31 +02:00 committed by Jforrester
parent 9690fcfee6
commit 08b33b2a7d
4 changed files with 100 additions and 60 deletions

View file

@ -2,10 +2,20 @@
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php'; $cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
$cfg['directory_list'] = array_merge(
$cfg['directory_list'],
[
'../../extensions/BetaFeatures',
]
);
$cfg['exclude_analysis_directory_list'] = array_merge( $cfg['exclude_analysis_directory_list'] = array_merge(
$cfg['exclude_analysis_directory_list'], $cfg['exclude_analysis_directory_list'],
[
'../../extensions/BetaFeatures',
# Don't analyze imported Parsoid code, it uses a different phan config # Don't analyze imported Parsoid code, it uses a different phan config
[ 'includes/VEParsoid' ] 'includes/VEParsoid'
]
); );
return $cfg; return $cfg;

View file

@ -231,7 +231,7 @@
"CustomEditor": "MediaWiki\\Extension\\VisualEditor\\Hooks::onCustomEditor", "CustomEditor": "MediaWiki\\Extension\\VisualEditor\\Hooks::onCustomEditor",
"TextSlotDiffRendererTablePrefix": "VisualEditorHooks", "TextSlotDiffRendererTablePrefix": "VisualEditorHooks",
"EditPage::showEditForm:fields": "MediaWiki\\Extension\\VisualEditor\\Hooks::onEditPageShowEditFormFields", "EditPage::showEditForm:fields": "MediaWiki\\Extension\\VisualEditor\\Hooks::onEditPageShowEditFormFields",
"GetBetaFeaturePreferences": "MediaWiki\\Extension\\VisualEditor\\Hooks::onGetBetaPreferences", "GetBetaFeaturePreferences": "VisualEditorBetaFeaturesHooks",
"GetPreferences": "MediaWiki\\Extension\\VisualEditor\\Hooks::onGetPreferences", "GetPreferences": "MediaWiki\\Extension\\VisualEditor\\Hooks::onGetPreferences",
"ListDefinedTags": "MediaWiki\\Extension\\VisualEditor\\Hooks::onListDefinedTags", "ListDefinedTags": "MediaWiki\\Extension\\VisualEditor\\Hooks::onListDefinedTags",
"MakeGlobalVariablesScript": "MediaWiki\\Extension\\VisualEditor\\Hooks::onMakeGlobalVariablesScript", "MakeGlobalVariablesScript": "MediaWiki\\Extension\\VisualEditor\\Hooks::onMakeGlobalVariablesScript",
@ -252,6 +252,13 @@
"HookHandlers": { "HookHandlers": {
"VisualEditorHooks": { "VisualEditorHooks": {
"class": "MediaWiki\\Extension\\VisualEditor\\Hooks" "class": "MediaWiki\\Extension\\VisualEditor\\Hooks"
},
"VisualEditorBetaFeaturesHooks": {
"class": "MediaWiki\\Extension\\VisualEditor\\BetaFeaturesHooks",
"services": [
"MainConfig",
"ConfigFactory"
]
} }
}, },
"ResourceModules": { "ResourceModules": {

View file

@ -0,0 +1,80 @@
<?php
namespace MediaWiki\Extension\VisualEditor;
use Config;
use ConfigFactory;
use MediaWiki\Extension\BetaFeatures\Hooks\GetBetaFeaturePreferencesHook;
use MediaWiki\MainConfigNames;
use User;
/**
* Hooks from BetaFeatures extension,
* which is optional to use with this extension.
*/
class BetaFeaturesHooks implements GetBetaFeaturePreferencesHook {
private Config $coreConfig;
private Config $config;
public function __construct(
Config $coreConfig,
ConfigFactory $configFactory
) {
$this->coreConfig = $coreConfig;
$this->config = $configFactory->makeConfig( 'visualeditor' );
}
/**
* Handler for the GetBetaPreferences hook, to add and hide user beta preferences as configured
*
* @param User $user
* @param array &$preferences Their preferences object
*/
public function onGetBetaFeaturePreferences( User $user, array &$preferences ) {
$iconpath = $this->coreConfig->get( MainConfigNames::ExtensionAssetsPath ) . '/VisualEditor/images';
if (
!$this->config->get( 'VisualEditorUnifiedPreference' ) &&
$this->config->get( 'VisualEditorEnableBetaFeature' )
) {
$preferences['visualeditor-enable'] = [
'version' => '1.0',
'label-message' => 'visualeditor-preference-core-label',
'desc-message' => 'visualeditor-preference-core-description',
'screenshot' => [
'ltr' => "$iconpath/betafeatures-icon-VisualEditor-ltr.svg",
'rtl' => "$iconpath/betafeatures-icon-VisualEditor-rtl.svg",
],
'info-message' => 'visualeditor-preference-core-info-link',
'discussion-message' => 'visualeditor-preference-core-discussion-link',
'requirements' => [
'javascript' => true,
'unsupportedList' => $this->config->get( 'VisualEditorBrowserUnsupportedList' ),
]
];
}
if (
$this->config->get( 'VisualEditorEnableWikitextBetaFeature' ) &&
// Don't try to register as a beta feature if enabled by default
!$this->config->get( 'VisualEditorEnableWikitext' )
) {
$preferences['visualeditor-newwikitext'] = [
'version' => '1.0',
'label-message' => 'visualeditor-preference-newwikitexteditor-label',
'desc-message' => 'visualeditor-preference-newwikitexteditor-description',
'screenshot' => [
'ltr' => "$iconpath/betafeatures-icon-WikitextEditor-ltr.svg",
'rtl' => "$iconpath/betafeatures-icon-WikitextEditor-rtl.svg",
],
'info-message' => 'visualeditor-preference-newwikitexteditor-info-link',
'discussion-message' => 'visualeditor-preference-newwikitexteditor-discussion-link',
'requirements' => [
'javascript' => true,
'unsupportedList' => $this->config->get( 'VisualEditorBrowserUnsupportedList' ),
]
];
}
}
}

View file

@ -926,63 +926,6 @@ class Hooks implements TextSlotDiffRendererTablePrefixHook {
$preferences['visualeditor-findAndReplace-word'] = $api; $preferences['visualeditor-findAndReplace-word'] = $api;
} }
/**
* Handler for the GetBetaPreferences hook, to add and hide user beta preferences as configured
*
* @param User $user
* @param array &$preferences Their preferences object
*/
public static function onGetBetaPreferences( User $user, array &$preferences ) {
$coreConfig = RequestContext::getMain()->getConfig();
$iconpath = $coreConfig->get( 'ExtensionAssetsPath' ) . "/VisualEditor/images";
$veConfig = MediaWikiServices::getInstance()->getConfigFactory()
->makeConfig( 'visualeditor' );
if (
!$veConfig->get( 'VisualEditorUnifiedPreference' ) &&
$veConfig->get( 'VisualEditorEnableBetaFeature' )
) {
$preferences['visualeditor-enable'] = [
'version' => '1.0',
'label-message' => 'visualeditor-preference-core-label',
'desc-message' => 'visualeditor-preference-core-description',
'screenshot' => [
'ltr' => "$iconpath/betafeatures-icon-VisualEditor-ltr.svg",
'rtl' => "$iconpath/betafeatures-icon-VisualEditor-rtl.svg",
],
'info-message' => 'visualeditor-preference-core-info-link',
'discussion-message' => 'visualeditor-preference-core-discussion-link',
'requirements' => [
'javascript' => true,
'unsupportedList' => $veConfig->get( 'VisualEditorBrowserUnsupportedList' ),
]
];
}
if (
$veConfig->get( 'VisualEditorEnableWikitextBetaFeature' ) &&
// Don't try to register as a beta feature if enabled by default
!$veConfig->get( 'VisualEditorEnableWikitext' )
) {
$preferences['visualeditor-newwikitext'] = [
'version' => '1.0',
'label-message' => 'visualeditor-preference-newwikitexteditor-label',
'desc-message' => 'visualeditor-preference-newwikitexteditor-description',
'screenshot' => [
'ltr' => "$iconpath/betafeatures-icon-WikitextEditor-ltr.svg",
'rtl' => "$iconpath/betafeatures-icon-WikitextEditor-rtl.svg",
],
'info-message' => 'visualeditor-preference-newwikitexteditor-info-link',
'discussion-message' => 'visualeditor-preference-newwikitexteditor-discussion-link',
'requirements' => [
'javascript' => true,
'unsupportedList' => $veConfig->get( 'VisualEditorBrowserUnsupportedList' ),
]
];
}
}
/** /**
* Implements the PreferencesFormPreSave hook, to remove the 'autodisable' flag * Implements the PreferencesFormPreSave hook, to remove the 'autodisable' flag
* when the user it was set on explicitly enables VE. * when the user it was set on explicitly enables VE.