mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-12 09:09:25 +00:00
Make namespace and content model lists extensible
This should really be done automatically by resource loader, but merging only works on globals. We use this same hack for plugin modules. Change-Id: I5f729ddb6146565dc839f60353ac8fa5b2a29ca8
This commit is contained in:
parent
02b3d6bad9
commit
6ee6ac7bdf
|
@ -651,10 +651,27 @@ class ApiVisualEditor extends ApiBase {
|
|||
* @return boolean
|
||||
*/
|
||||
public static function isAllowedNamespace( Config $config, $namespaceId ) {
|
||||
$availableNamespaces = $config->get( 'VisualEditorAvailableNamespaces' );
|
||||
$canonicalName = MWNamespace::getCanonicalName( $namespaceId );
|
||||
return ( isset( $availableNamespaces[$namespaceId] ) && $availableNamespaces[$namespaceId] ) ||
|
||||
( isset( $availableNamespaces[$canonicalName] ) && $availableNamespaces[$canonicalName] );
|
||||
$availableNamespaces = self::getAvailableNamespaceIds( $config );
|
||||
return in_array( $namespaceId, $availableNamespaces );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of allowed namespace IDs
|
||||
*
|
||||
* @param Config $config Configuration object
|
||||
* @return array
|
||||
*/
|
||||
public static function getAvailableNamespaceIds( Config $config ) {
|
||||
$availableNamespaces = array_merge(
|
||||
ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorAvailableNamespaces' ),
|
||||
$config->get( 'VisualEditorAvailableNamespaces' )
|
||||
);
|
||||
return array_map( function ( $namespace ) {
|
||||
// Convert canonical namespace names to IDs
|
||||
return is_numeric( $namespace ) ?
|
||||
$namespace :
|
||||
MWNamespace::getCanonicalIndex( strtolower( $namespace ) );
|
||||
}, array_keys( array_filter( $availableNamespaces ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -665,8 +682,13 @@ class ApiVisualEditor extends ApiBase {
|
|||
* @return boolean
|
||||
*/
|
||||
public static function isAllowedContentType( Config $config, $contentModel ) {
|
||||
$availableContentModels = $config->get( 'VisualEditorAvailableContentModels' );
|
||||
return isset( $availableContentModels[ $contentModel ] );
|
||||
$availableContentModels = array_merge(
|
||||
ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorAvailableContentModels' ),
|
||||
$config->get( 'VisualEditorAvailableContentModels' )
|
||||
);
|
||||
return
|
||||
isset( $availableContentModels[ $contentModel ] ) &&
|
||||
$availableContentModels[ $contentModel ];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -508,11 +508,9 @@ class VisualEditorHooks {
|
|||
|
||||
public static function onGetPreferences( User $user, array &$preferences ) {
|
||||
global $wgLang;
|
||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
||||
if ( !class_exists( 'BetaFeatures' ) ) {
|
||||
$namespaces = ConfigFactory::getDefaultInstance()
|
||||
->makeConfig( 'visualeditor' )
|
||||
->get( 'VisualEditorAvailableNamespaces' );
|
||||
$onNamespaces = array_keys( array_filter( $namespaces ) );
|
||||
$namespaces = ApiVisualEditor::getAvailableNamespaceIds( $config );
|
||||
|
||||
$enablePreference = [
|
||||
'type' => 'toggle',
|
||||
|
@ -520,9 +518,9 @@ class VisualEditorHooks {
|
|||
'visualeditor-preference-enable',
|
||||
$wgLang->commaList( array_map(
|
||||
[ 'self', 'convertNs' ],
|
||||
$onNamespaces
|
||||
$namespaces
|
||||
) ),
|
||||
count( $onNamespaces )
|
||||
count( $namespaces )
|
||||
],
|
||||
'section' => 'editing/editor'
|
||||
];
|
||||
|
@ -539,7 +537,6 @@ class VisualEditorHooks {
|
|||
$user->getOption( 'visualeditor-autodisable' )
|
||||
];
|
||||
|
||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
||||
if (
|
||||
$config->get( 'VisualEditorUseSingleEditTab' ) &&
|
||||
!$user->getOption( 'visualeditor-autodisable' ) &&
|
||||
|
@ -667,23 +664,21 @@ class VisualEditorHooks {
|
|||
$defaultUserOptions = $coreConfig->get( 'DefaultUserOptions' );
|
||||
$thumbLimits = $coreConfig->get( 'ThumbLimits' );
|
||||
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
||||
$availableNamespaces = $veConfig->get( 'VisualEditorAvailableNamespaces' );
|
||||
$enabledNamespaces = array_map( function ( $namespace ) {
|
||||
// Convert canonical namespace names to IDs
|
||||
return is_numeric( $namespace ) ?
|
||||
$namespace :
|
||||
MWNamespace::getCanonicalIndex( strtolower( $namespace ) );
|
||||
}, array_keys( array_filter( $availableNamespaces ) ) );
|
||||
$availableContentModels = $veConfig->get( 'VisualEditorAvailableContentModels' );
|
||||
$enabledContentModels = array_keys( array_filter( $availableContentModels ) );
|
||||
$availableNamespaces = ApiVisualEditor::getAvailableNamespaceIds( $veConfig );
|
||||
$availableContentModels = array_keys( array_filter(
|
||||
array_merge(
|
||||
ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorAvailableContentModels' ),
|
||||
$veConfig->get( 'VisualEditorAvailableContentModels' )
|
||||
)
|
||||
) );
|
||||
|
||||
$vars['wgVisualEditorConfig'] = [
|
||||
'disableForAnons' => $veConfig->get( 'VisualEditorDisableForAnons' ),
|
||||
'preferenceModules' => $veConfig->get( 'VisualEditorPreferenceModules' ),
|
||||
'namespaces' => $enabledNamespaces,
|
||||
'contentModels' => $enabledContentModels,
|
||||
'namespaces' => $availableNamespaces,
|
||||
'contentModels' => $availableContentModels,
|
||||
'signatureNamespaces' => array_values(
|
||||
array_filter( $enabledNamespaces, 'MWNamespace::wantSignatures' )
|
||||
array_filter( $availableNamespaces, 'MWNamespace::wantSignatures' )
|
||||
),
|
||||
'pluginModules' => array_merge(
|
||||
ExtensionRegistry::getInstance()->getAttribute( 'VisualEditorPluginModules' ),
|
||||
|
|
Loading…
Reference in a new issue