mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-27 15:50:29 +00:00
Allow extensions to support extra namespaces and content models
Change-Id: If67bab93da355da609b6df274514b5c72a6ed91a
This commit is contained in:
parent
ce149e49d7
commit
796da84576
|
@ -655,7 +655,18 @@ class ApiVisualEditor extends ApiBase {
|
|||
$canonicalName = MWNamespace::getCanonicalName( $namespaceId );
|
||||
return ( isset( $availableNamespaces[$namespaceId] ) && $availableNamespaces[$namespaceId] ) ||
|
||||
( isset( $availableNamespaces[$canonicalName] ) && $availableNamespaces[$canonicalName] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the configured allowed content models include the specified content model
|
||||
*
|
||||
* @param Config $config Configuration object
|
||||
* @param string $contentModel Content model ID
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isAllowedContentType( Config $config, $contentModel ) {
|
||||
$availableContentModels = $config->get( 'VisualEditorAvailableContentModels' );
|
||||
return isset( $availableContentModels[ $contentModel ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -124,7 +124,6 @@ class VisualEditorHooks {
|
|||
}
|
||||
|
||||
$title = $article->getTitle();
|
||||
|
||||
$params = $req->getValues();
|
||||
|
||||
if ( isset( $params['venoscript'] ) ) {
|
||||
|
@ -143,7 +142,7 @@ class VisualEditorHooks {
|
|||
self::getUserEditor( $user, $req ) === 'wikitext' ||
|
||||
!$title->quickUserCan( 'edit' ) ||
|
||||
!ApiVisualEditor::isAllowedNamespace( $veConfig, $title->getNamespace() ) ||
|
||||
$title->getContentModel() !== CONTENT_MODEL_WIKITEXT ||
|
||||
!ApiVisualEditor::isAllowedContentType( $veConfig, $title->getContentModel() ) ||
|
||||
// Known parameters that VE does not handle
|
||||
// TODO: Other params too? See identical list in ve.init.mw.DesktopArticleTarget.init.js
|
||||
isset( $params['undo'] ) ||
|
||||
|
@ -273,12 +272,10 @@ class VisualEditorHooks {
|
|||
$title = $skin->getRelevantTitle();
|
||||
$namespaceEnabled = ApiVisualEditor::isAllowedNamespace( $config, $title->getNamespace() );
|
||||
$pageContentModel = $title->getContentModel();
|
||||
$contentModelEnabled = ApiVisualEditor::isAllowedContentType( $veConfig, $pageContentModel );
|
||||
// Don't exit if this page isn't VE-enabled, since we should still
|
||||
// change "Edit" to "Edit source".
|
||||
$isAvailable = (
|
||||
$namespaceEnabled &&
|
||||
$pageContentModel === CONTENT_MODEL_WIKITEXT
|
||||
);
|
||||
$isAvailable = $namespaceEnabled && $contentModelEnabled;
|
||||
|
||||
// HACK: Exit if we're in the Education Program namespace (even though it's content)
|
||||
if ( defined( 'EP_NS' ) && $title->inNamespace( EP_NS ) ) {
|
||||
|
@ -682,6 +679,7 @@ class VisualEditorHooks {
|
|||
'disableForAnons' => $veConfig->get( 'VisualEditorDisableForAnons' ),
|
||||
'preferenceModules' => $veConfig->get( 'VisualEditorPreferenceModules' ),
|
||||
'namespaces' => $enabledNamespaces,
|
||||
'contentModels' => $veConfig->get( 'VisualEditorAvailableContentModels' ),
|
||||
'signatureNamespaces' => array_values(
|
||||
array_filter( $enabledNamespaces, 'MWNamespace::wantSignatures' )
|
||||
),
|
||||
|
|
|
@ -103,6 +103,7 @@
|
|||
"Category": true,
|
||||
"_merge_strategy": "array_plus"
|
||||
},
|
||||
"VisualEditorAvailableContentModels": [ "wikitext" ],
|
||||
"VisualEditorSkinToolbarScrollOffset": [],
|
||||
"VisualEditorParsoidTimeout": 100,
|
||||
"VisualEditorUseSingleEditTab": false,
|
||||
|
|
|
@ -669,8 +669,8 @@
|
|||
// Not on pages which are outputs of the Page Translation feature
|
||||
mw.config.get( 'wgTranslatePageTranslation' ) !== 'translation' &&
|
||||
|
||||
// Only for pages with a wikitext content model
|
||||
mw.config.get( 'wgPageContentModel' ) === 'wikitext'
|
||||
// Only for pages with a supported content model
|
||||
conf.contentModels.indexOf( mw.config.get( 'wgPageContentModel' ) ) !== -1
|
||||
);
|
||||
|
||||
// FIXME: We should do this more elegantly
|
||||
|
|
Loading…
Reference in a new issue