Alex Monk has uploaded a new change for review.

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

Change subject: [WIP] Single edit tab
......................................................................

[WIP] Single edit tab

This doesn't fully work yet.

Bug: T114530
Change-Id: I65d966270491ffe017cb11a0daa915628fadf65c
---
M VisualEditor.hooks.php
M extension.json
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
4 files changed, 115 insertions(+), 26 deletions(-)


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

diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index 101c62b..b11f953 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -59,6 +59,47 @@
        }
 
        /**
+        * Decide whether to bother showing the wikitext editor at all.
+        * If not, we expect the VE initialisation JS to activate.
+        * @param $article Article
+        * @param $user User
+        * @return bool Whether to show the wikitext editor or not.
+        */
+       public static function onCustomEditor( Article $article, User $user ) {
+               $req = RequestContext::getMain()->getRequest();
+               $skin = RequestContext::getMain()->getSkin();
+               $veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 
'visualeditor' );
+
+               if (
+                       !$skin->getUser()->getOption( 'visualeditor-enable' ) ||
+                       $skin->getUser()->getOption( 
'visualeditor-betatempdisable' ) ||
+                       $skin->getUser()->getOption( 'visualeditor-autodisable' 
) ||
+                       ( $veConfig->get( 'VisualEditorDisableForAnons' ) && 
$skin->getUser()->isAnon() ) ||
+                       false // TODO: Detect incompatibility
+               ) {
+                       $req->response()->setCookie( 'editor-preference', 
'wikitext' );
+                       $user->setOption( 'editor-preference', 'wikitext' );
+                       return true;
+               }
+
+               $title = $article->getTitle();
+
+               $availableNamespaces = $veConfig->get( 
'VisualEditorAvailableNamespaces' );
+
+               $params = $req->getValueNames();
+
+               return $req->getVal( 'action' ) !== 'edit' ||
+                       !$veConfig->get( 'VisualEditorUseSingleEditTab' ) ||
+                       $req->getCookie( 'editor-preference' ) === 'wikitext' ||
+                       $user->getOption( 'editor-preference' ) === 'wikitext' 
||
+                       !$title->inNamespaces( array_keys( array_filter( 
$availableNamespaces ) ) ) ||
+                       $title->getContentModel() !== CONTENT_MODEL_WIKITEXT ||
+                       // check for parameters that VE does not handle
+                       in_array( 'preload', $params ) ||
+                       in_array( 'editintro', $params );
+       }
+
+       /**
         * Convert the content model of messages that are actually JSON to JSON.
         * This only affects validation and UI when saving and editing, not
         * loading the content.
@@ -91,6 +132,11 @@
         */
        public static function onSkinTemplateNavigation( SkinTemplate &$skin, 
array &$links ) {
                $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'visualeditor' );
+
+               // Exit if we're using the single edit tab.
+               if ( $config->get( 'VisualEditorUseSingleEditTab' ) ) {
+                       return true;
+               }
 
                // Exit if the user doesn't have VE enabled
                if (
@@ -238,6 +284,11 @@
        ) {
                $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'visualeditor' );
 
+               // Exit if we're using the single edit tab.
+               if ( $config->get( 'VisualEditorUseSingleEditTab' ) ) {
+                       return true;
+               }
+
                // Exit if we're in parserTests
                if ( isset( $GLOBALS[ 'wgVisualEditorInParserTests' ] ) ) {
                        return true;
@@ -344,6 +395,7 @@
                );
                $api = array( 'type' => 'api' );
                $preferences['visualeditor-autodisable'] = $api;
+               $preferences['editor-preference'] = $api; // TODO: Rename?
                $preferences['visualeditor-hidebetawelcome'] = $api;
                $preferences['visualeditor-findAndReplace-findText'] = $api;
                $preferences['visualeditor-findAndReplace-replaceText'] = $api;
@@ -463,6 +515,7 @@
                        'skins' => $veConfig->get( 'VisualEditorSupportedSkins' 
),
                        'tabPosition' => $veConfig->get( 
'VisualEditorTabPosition' ),
                        'tabMessages' => $veConfig->get( 
'VisualEditorTabMessages' ),
+                       'singleEditTab' => $veConfig->get( 
'VisualEditorUseSingleEditTab' ),
                        'showBetaWelcome' => $veConfig->get( 
'VisualEditorShowBetaWelcome' ),
                        'enableTocWidget' => $veConfig->get( 
'VisualEditorEnableTocWidget' ),
                        'svgMaxSize' => $coreConfig->get( 'SVGMaxSize' ),
diff --git a/extension.json b/extension.json
index 90d3dfc..0d3b795 100644
--- a/extension.json
+++ b/extension.json
@@ -107,7 +107,8 @@
                        "_merge_strategy": "array_plus"
                },
                "VisualEditorSkinToolbarScrollOffset": [],
-               "VisualEditorParsoidTimeout": 100
+               "VisualEditorParsoidTimeout": 100,
+               "VisualEditorUseSingleEditTab": true
        },
        "APIModules": {
                "visualeditor": {
@@ -186,6 +187,9 @@
                ],
                "AuthPluginAutoCreate": [
                        "VisualEditorHooks::onAuthPluginAutoCreate"
+               ],
+               "CustomEditor": [
+                       "VisualEditorHooks::onCustomEditor"
                ]
        },
        "ResourceModules": {
@@ -259,6 +263,7 @@
                                "mediawiki.Title",
                                "mediawiki.Uri",
                                "mediawiki.util",
+                               "mediawiki.api.options",
                                "user.options",
                                "ext.visualEditor.track"
                        ],
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 4b39277..339076c 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
@@ -168,6 +168,11 @@
                                incrementLoadingProgress();
                        } );
 
+               $.cookie( 'editor-preference', 'visualeditor' );
+               localStorage.setItem( 'editor-preference', 'visualeditor' );
+               new mw.Api().saveOption( 'editor-preference', 'visualeditor' );
+               mw.user.options.set( 'editor-preference', 'visualeditor' );
+
                $( 'html' ).addClass( 've-activated ve-loading' );
                showLoading();
                incrementLoadingProgress();
@@ -206,6 +211,10 @@
        isViewPage = (
                mw.config.get( 'wgIsArticle' ) &&
                !( 'diff' in uri.query )
+       ) ||
+       (
+               uri.query.action === 'edit' ||
+               uri.query.action === 'submit'
        );
        // On a view page, extend the current URI so parameters like oldid are 
carried over
        // On a non-view page, use viewUri
@@ -492,17 +501,19 @@
                        trackActivateStart( { type: 'page', mechanism: 'click' 
} );
 
                        if ( !active ) {
-                               if ( history.pushState ) {
-                                       // Replace the current state with one 
that is tagged as ours, to prevent the
-                                       // back button from breaking when used 
to exit VE. FIXME: there should be a better
-                                       // way to do this. See also similar 
code in the DesktopArticleTarget constructor.
-                                       history.replaceState( { tag: 
'visualeditor' }, document.title, uri );
-                                       // Set veaction to edit
-                                       history.pushState( { tag: 
'visualeditor' }, document.title, veEditUri );
-                               }
+                               if ( uri.query.action !== 'edit' ) {
+                                       if ( history.pushState ) {
+                                               // Replace the current state 
with one that is tagged as ours, to prevent the
+                                               // back button from breaking 
when used to exit VE. FIXME: there should be a better
+                                               // way to do this. See also 
similar code in the DesktopArticleTarget constructor.
+                                               history.replaceState( { tag: 
'visualeditor' }, document.title, uri );
+                                               // Set veaction to edit
+                                               history.pushState( { tag: 
'visualeditor' }, document.title, veEditUri );
+                                       }
 
-                               // Update mw.Uri instance
-                               uri = veEditUri;
+                                       // Update mw.Uri instance
+                                       uri = veEditUri;
+                               }
 
                                activateTarget();
                        }
@@ -601,32 +612,47 @@
        }
 
        $( function () {
-               var currentUri = new mw.Uri( location.href ),
-                       isSection;
-
-               if ( init.isAvailable ) {
-                       if ( isViewPage && uri.query.veaction === 'edit' ) {
-                               isSection = uri.query.vesection !== undefined;
-
-                               trackActivateStart( { type: isSection ? 
'section' : 'page', mechanism: 'url' } );
-                               activateTarget();
-                       }
+               if (
+                       init.isAvailable && isViewPage &&
+                       ( uri.query.veaction === 'edit' || uri.query.action === 
'edit' )
+               ) {
+                       trackActivateStart( {
+                               type: uri.query.vesection === undefined ? 
'page' : 'section',
+                               mechanism: 'url'
+                       } );
+                       activateTarget();
                }
 
                if ( userPrefEnabled ) {
-                       init.setupSkin();
+                       if ( conf.singleEditTab ) {
+                               // Allow instant switching to edit mode, 
without refresh
+                               $( '#ca-edit' ).click( function ( e ) {
+                                       if (
+                                               init.isAvailable &&
+                                               $.cookie( 'editor-preference' ) 
!== 'wikitext' &&
+                                               localStorage.getItem( 
'editor-preference' ) !== 'wikitext' &&
+                                               mw.user.options.get( 
'editor-preference' ) !== 'wikitext'
+                                       ) {
+                                               trackActivateStart( { type: 
'page', mechanism: 'click' } );
+                                               activateTarget();
+                                               e.preventDefault();
+                                       }
+                               } );
+                       } else {
+                               init.setupSkin();
+                       }
                }
 
-               if ( currentUri.query.venotify ) {
+               if ( uri.query.venotify ) {
                        // The following messages can be used here:
                        // postedit-confirmation-saved
                        // postedit-confirmation-created
                        // postedit-confirmation-restored
                        mw.hook( 'postEdit' ).fire( {
-                               message: mw.msg( 'postedit-confirmation-' + 
currentUri.query.venotify, mw.user )
+                               message: mw.msg( 'postedit-confirmation-' + 
uri.query.venotify, mw.user )
                        } );
 
-                       delete currentUri.query.venotify;
+                       delete uri.query.venotify;
                }
        } );
 }() );
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js 
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
index 6c1404d..8c2a263 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
@@ -997,7 +997,12 @@
 
        // Push veaction=edit url in history (if not already. If we got here by 
a veaction=edit
        // permalink then it will be there already and the constructor called 
#activate)
-       if ( !this.actFromPopState && history.pushState && 
this.currentUri.query.veaction !== 'edit' ) {
+       if (
+               !this.actFromPopState &&
+               history.pushState &&
+               this.currentUri.query.veaction !== 'edit' &&
+               this.currentUri.query.action !== 'edit'
+       ) {
                // Set the current URL
                uri = this.currentUri;
                uri.query.veaction = 'edit';

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I65d966270491ffe017cb11a0daa915628fadf65c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to