Alex Monk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311860

Change subject: Split isAvailable from visual-specific checks
......................................................................

Split isAvailable from visual-specific checks

Not fully tested

Bug: T146182
Change-Id: I5d7ae6e49991660ecdc2daf46b319947f83a1018
---
M ApiVisualEditor.php
M ApiVisualEditorEdit.php
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
3 files changed, 36 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/60/311860/1

diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index 1e047b5..0cf9198 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -11,12 +11,6 @@
 use \MediaWiki\Logger\LoggerFactory;
 
 class ApiVisualEditor extends ApiBase {
-       // These are safe even if VE is not enabled on the page.
-       // This is intended for other VE interfaces, such as Flow's.
-       protected static $SAFE_ACTIONS = [
-               'parsefragment',
-       ];
-
        /**
         * @var Config
         */
@@ -293,12 +287,6 @@
                $title = Title::newFromText( $params['page'] );
                if ( !$title ) {
                        $this->dieUsageMsg( 'invalidtitle', $params['page'] );
-               }
-
-               $isSafeAction = in_array( $params['paction'], 
self::$SAFE_ACTIONS, true );
-
-               if ( !$isSafeAction ) {
-                       $this->checkAllowedNamespace( $title->getNamespace() );
                }
 
                $parserParams = [];
@@ -667,19 +655,6 @@
                }
 
                $this->getResult()->addValue( null, $this->getModuleName(), 
$result );
-       }
-
-       /**
-        * Check if the request is allowed to proceed in the current namespace, 
and abort if not
-        *
-        * @param int $namespaceId Namespace ID
-        */
-       public function checkAllowedNamespace( $namespaceId ) {
-               if ( !self::isAllowedNamespace( $this->veConfig, $namespaceId ) 
) {
-                       $this->dieUsage( "VisualEditor is not enabled in '" .
-                               MWNamespace::getCanonicalName( $namespaceId ) . 
"' namespace ",
-                       'novenamespace' );
-               }
        }
 
        /**
diff --git a/ApiVisualEditorEdit.php b/ApiVisualEditorEdit.php
index 01cdb7a..d7bee07 100644
--- a/ApiVisualEditorEdit.php
+++ b/ApiVisualEditorEdit.php
@@ -119,8 +119,6 @@
                        $this->dieUsageMsg( 'invalidtitle', $params['page'] );
                }
 
-               $this->checkAllowedNamespace( $title->getNamespace() );
-
                $parserParams = [];
                if ( isset( $params['oldid'] ) ) {
                        $parserParams['oldid'] = $params['oldid'];
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 e7a207e..e1d6aee 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
@@ -455,7 +455,7 @@
                        }
 
                        // If the edit tab is hidden, remove it.
-                       if ( !( init.isAvailable && userPrefPreferShow ) ) {
+                       if ( !( init.isVisualAvailable && userPrefPreferShow ) 
) {
                                $caVeEdit.remove();
                        } else if ( pageCanLoadVE ) {
                                // Allow instant switching to edit mode, 
without refresh
@@ -476,7 +476,7 @@
                                }
                        }
 
-                       if ( init.isAvailable ) {
+                       if ( init.isVisualAvailable ) {
                                if ( conf.tabPosition === 'before' ) {
                                        $caEdit.addClass( 'collapsible' );
                                } else {
@@ -724,11 +724,14 @@
                // Only in supported skins
                conf.skins.indexOf( mw.config.get( 'skin' ) ) !== -1 &&
 
+               // Not on pages like Special:RevisionDelete
+               mw.config.get( 'wgNamespaceNumber' ) !== -1
+       );
+       init.isVisualAvailable = (
+               init.isAvailable &&
+
                // Only in enabled namespaces
                conf.namespaces.indexOf( new mw.Title( mw.config.get( 
'wgRelevantPageName' ) ).getNamespaceId() ) !== -1 &&
-
-               // Not on pages like Special:RevisionDelete
-               mw.config.get( 'wgNamespaceNumber' ) !== -1 &&
 
                // Not on pages which are outputs of the Page Translation 
feature
                mw.config.get( 'wgTranslatePageTranslation' ) !== 'translation' 
&&
@@ -747,12 +750,12 @@
        // The VE global was once available always, but now that platform 
integration initialisation
        // is properly separated, it doesn't exist until the platform loads 
VisualEditor core.
        //
-       // Most of mw.libs.ve is considered subject to change and private.  The 
exception is that
-       // mw.libs.ve.isAvailable is public, and indicates whether the VE 
editor itself can be loaded
+       // Most of mw.libs.ve is considered subject to change and private.  An 
exception is that
+       // mw.libs.ve.isVisualAvailable is public, and indicates whether the VE 
editor itself can be loaded
        // on this page. See above for why it may be false.
        mw.libs.ve = $.extend( mw.libs.ve || {}, init );
 
-       if ( init.isAvailable && userPrefPreferShow ) {
+       if ( init.isVisualAvailable && userPrefPreferShow ) {
                $( 'html' ).addClass( 've-available' );
        } else {
                $( 'html' ).addClass( 've-not-available' );
@@ -786,7 +789,14 @@
                        ) {
                                if (
                                        // … if on a ?veaction=edit/editsource 
page
-                                       ( isViewPage && uri.query.veaction in 
editModes ) ||
+                                       (
+                                               isViewPage &&
+                                               uri.query.veaction in editModes 
&&
+                                               (
+                                                       uri.query.veaction === 
'editsource' ||
+                                                       init.isVisualAvailable
+                                               )
+                                       ) ||
                                        // … or if on ?action=edit in single 
edit mode and the user wants it
                                        (
                                                isEditPage &&
@@ -800,7 +810,8 @@
                                                                (
                                                                        (
                                                                                
tabPreference === 'prefer-ve' &&
-                                                                               
mw.config.get( 'wgAction' ) !== 'submit'
+                                                                               
mw.config.get( 'wgAction' ) !== 'submit' &&
+                                                                               
init.isVisualAvailable
                                                                        ) ||
                                                                        (
                                                                                
tabPreference === 'prefer-wte' &&
@@ -810,7 +821,10 @@
                                                                        (
                                                                                
tabPreference === 'remember-last' &&
                                                                                
(
-                                                                               
        getLastEditor() !== 'wikitext' ||
+                                                                               
        (
+                                                                               
                getLastEditor() !== 'wikitext' &&
+                                                                               
                init.isVisualAvailable
+                                                                               
        ) ||
                                                                                
        (
                                                                                
                conf.enableWikitext &&
                                                                                
                mw.user.options.get( 'visualeditor-newwikitext' )
@@ -845,7 +859,11 @@
                                                }
                                                activateTarget( editModes[ 
action ] );
                                        }
-                               } else if ( pageCanLoadVE && userPrefEnabled ) {
+                               } else if (
+                                       init.isVisualAvailable &&
+                                       pageCanLoadVE &&
+                                       userPrefEnabled
+                               ) {
                                        // Page can be edited in VE, parameters 
are good, user prefs are mostly good
                                        // but have 
visualeditor-tabs=prefer-wt? Add a keyboard shortcut to go to
                                        // VE.
@@ -856,7 +874,10 @@
                        }
 
                        // Add the switch button to wikitext ?action=edit or 
?action=submit pages
-                       if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 
'wgAction' ) ) !== -1 ) {
+                       if (
+                               init.isVisualAvailable &&
+                               [ 'edit', 'submit' ].indexOf( mw.config.get( 
'wgAction' ) ) !== -1
+                       ) {
                                mw.loader.load( 'ext.visualEditor.switching' );
                                $( '#wpTextbox1' ).on( 
'wikiEditor-toolbar-doneInitialSections', function () {
                                        mw.loader.using( 
'ext.visualEditor.switching' ).done( function () {
@@ -944,7 +965,7 @@
                        }
 
                        // Set up the tabs appropriately if the user has VE on
-                       if ( userPrefPreferShow ) {
+                       if ( init.isVisualAvailable && userPrefPreferShow ) {
                                // … on two-edit-tab wikis, or single-edit-tab 
wikis, where the user wants both …
                                if ( !conf.singleEditTab || tabPreference === 
'multi-tab' ) {
                                        // … set the skin up with both tabs and 
both section edit links.
@@ -990,7 +1011,7 @@
                                windowManager.openWindow(
                                        welcomeDialog,
                                        {
-                                               switchable: init.isAvailable,
+                                               switchable: 
init.isVisualAvailable,
                                                editor: 'source'
                                        }
                                )

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5d7ae6e49991660ecdc2daf46b319947f83a1018
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <a...@wikimedia.org>

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

Reply via email to