Merge "Allow extensions to support extra namespaces and content models"

This commit is contained in:
jenkins-bot 2016-06-01 01:02:51 +00:00 committed by Gerrit Code Review
commit d70485244d
4 changed files with 18 additions and 8 deletions

View file

@ -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 ] );
}
/**

View file

@ -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' )
),

View file

@ -103,6 +103,7 @@
"Category": true,
"_merge_strategy": "array_plus"
},
"VisualEditorAvailableContentModels": [ "wikitext" ],
"VisualEditorSkinToolbarScrollOffset": [],
"VisualEditorParsoidTimeout": 100,
"VisualEditorUseSingleEditTab": false,

View file

@ -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