ve.collab: Move BetaFeature into its own file

Avoids requiring a dependency on the BetaFeatures extension.

Tell the phan config to include the BetaFeatures checkout so it'll pass
on that file, though. (Same as DiscussionTools.)

Change-Id: I258d3be59ea9cf0a798d93f0f8b1fd18a455d45a
This commit is contained in:
David Lynch 2024-03-06 14:26:18 -06:00
parent b3853721c8
commit 49d5c26c08
4 changed files with 80 additions and 35 deletions

View file

@ -1,3 +1,19 @@
<?php
return 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'],
[
'../../extensions/BetaFeatures',
]
);
return $cfg;

View file

@ -226,7 +226,7 @@
"TextSlotDiffRendererTablePrefix": "VisualEditorHooks",
"EditPage::showEditForm:fields": "VisualEditorHooks",
"GetPreferences": "VisualEditorHooks",
"GetBetaFeaturePreferences": "VisualEditorHooks",
"GetBetaFeaturePreferences": "betapreferences",
"ListDefinedTags": "VisualEditorHooks",
"MakeGlobalVariablesScript": "VisualEditorHooks",
"OutputPageBodyAttributes": "VisualEditorHooks",
@ -243,6 +243,13 @@
"HookHandlers": {
"VisualEditorHooks": {
"class": "MediaWiki\\Extension\\VisualEditor\\Hooks"
},
"betapreferences": {
"class": "MediaWiki\\Extension\\VisualEditor\\BetaPreferenceHooks",
"services": [
"MainConfig",
"ConfigFactory"
]
}
},
"ResourceModules": {

View file

@ -0,0 +1,55 @@
<?php
namespace MediaWiki\Extension\VisualEditor;
use MediaWiki\Config\Config;
use MediaWiki\Config\ConfigFactory;
use MediaWiki\Extension\BetaFeatures\Hooks\GetBetaFeaturePreferencesHook;
use MediaWiki\MainConfigNames;
use MediaWiki\User\User;
/**
* Hooks from BetaFeatures extension,
* which is optional to use with this extension.
*/
class BetaPreferenceHooks 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 GetBetaFeaturePreferences hook, to add and hide user beta preferences as configured
*
* @param User $user
* @param array &$preferences
*/
public function onGetBetaFeaturePreferences( User $user, array &$preferences ) {
if ( $this->config->get( 'VisualEditorEnableCollabBeta' ) ) {
$iconpath = $this->coreConfig->get( MainConfigNames::ExtensionAssetsPath ) . '/VisualEditor/images';
$preferences['visualeditor-collab'] = [
'version' => '1.0',
'label-message' => 'visualeditor-preference-collab-label',
'desc-message' => 'visualeditor-preference-collab-description',
'screenshot' => [
'ltr' => "$iconpath/betafeatures-icon-collab-ltr.svg",
'rtl' => "$iconpath/betafeatures-icon-collab-rtl.svg",
],
'info-message' => 'visualeditor-preference-collab-info-link',
'discussion-message' => 'visualeditor-preference-collab-discussion-link',
'requirements' => [
'javascript' => true
]
];
}
}
}

View file

@ -25,7 +25,6 @@ use MediaWiki\ChangeTags\Hook\ListDefinedTagsHook;
use MediaWiki\Diff\Hook\DifferenceEngineViewHeaderHook;
use MediaWiki\Diff\Hook\TextSlotDiffRendererTablePrefixHook;
use MediaWiki\EditPage\EditPage;
use MediaWiki\Extension\BetaFeatures\Hooks\GetBetaFeaturePreferencesHook;
use MediaWiki\Hook\BeforeInitializeHook;
use MediaWiki\Hook\BeforePageDisplayHook;
use MediaWiki\Hook\CustomEditorHook;
@ -69,7 +68,6 @@ class Hooks implements
DifferenceEngineViewHeaderHook,
EditPage__showEditForm_fieldsHook,
GetPreferencesHook,
GetBetaFeaturePreferencesHook,
ListDefinedTagsHook,
MakeGlobalVariablesScriptHook,
OutputPageBodyAttributesHook,
@ -1050,37 +1048,6 @@ class Hooks implements
$preferences['visualeditor-findAndReplace-word'] = $api;
}
/**
* Handler for the GetBetaFeaturePreferences hook, to add and hide user beta preferences as configured
*
* @param User $user
* @param array &$preferences
*/
public function onGetBetaFeaturePreferences( User $user, array &$preferences ) {
$services = MediaWikiServices::getInstance();
$veConfig = $services->getConfigFactory()->makeConfig( 'visualeditor' );
if ( $veConfig->get( 'VisualEditorEnableCollabBeta' ) ) {
$coreConfig = RequestContext::getMain()->getConfig();
$iconpath = $coreConfig->get( 'ExtensionAssetsPath' ) . '/VisualEditor/images';
$preferences['visualeditor-collab'] = [
'version' => '1.0',
'label-message' => 'visualeditor-preference-collab-label',
'desc-message' => 'visualeditor-preference-collab-description',
'screenshot' => [
'ltr' => "$iconpath/betafeatures-icon-collab-ltr.svg",
'rtl' => "$iconpath/betafeatures-icon-collab-rtl.svg",
],
'info-message' => 'visualeditor-preference-collab-info-link',
'discussion-message' => 'visualeditor-preference-collab-discussion-link',
'requirements' => [
'javascript' => true
]
];
}
}
/**
* Implements the PreferencesFormPreSave hook, to remove the 'autodisable' flag
* when the user it was set on explicitly enables VE.