jenkins-bot has submitted this change and it was merged.

Change subject: Allow extensions to support extra namespaces and content models
......................................................................


Allow extensions to support extra namespaces and content models

Change-Id: If67bab93da355da609b6df274514b5c72a6ed91a
---
M ApiVisualEditor.php
M VisualEditor.hooks.php
M extension.json
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
4 files changed, 18 insertions(+), 8 deletions(-)

Approvals:
  Alex Monk: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index ab62ee0..5676b26 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -655,7 +655,18 @@
                $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 ] );
        }
 
        /**
diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index cd87ced..30145ed 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -124,7 +124,6 @@
                }
 
                $title = $article->getTitle();
-
                $params = $req->getValues();
 
                if ( isset( $params['venoscript'] ) ) {
@@ -143,7 +142,7 @@
                        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 @@
                $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 @@
                        'disableForAnons' => $veConfig->get( 
'VisualEditorDisableForAnons' ),
                        'preferenceModules' => $veConfig->get( 
'VisualEditorPreferenceModules' ),
                        'namespaces' => $enabledNamespaces,
+                       'contentModels' => $veConfig->get( 
'VisualEditorAvailableContentModels' ),
                        'signatureNamespaces' => array_values(
                                array_filter( $enabledNamespaces, 
'MWNamespace::wantSignatures' )
                        ),
diff --git a/extension.json b/extension.json
index 3223ee6..c700131 100644
--- a/extension.json
+++ b/extension.json
@@ -103,6 +103,7 @@
                        "Category": true,
                        "_merge_strategy": "array_plus"
                },
+               "VisualEditorAvailableContentModels": [ "wikitext" ],
                "VisualEditorSkinToolbarScrollOffset": [],
                "VisualEditorParsoidTimeout": 100,
                "VisualEditorUseSingleEditTab": false,
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js 
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
index 40ec83f..cd4446f 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
@@ -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

-- 
To view, visit https://gerrit.wikimedia.org/r/284680
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If67bab93da355da609b6df274514b5c72a6ed91a
Gerrit-PatchSet: 13
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Alex Monk <kren...@gmail.com>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Tpt <thoma...@hotmail.fr>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to