Alex Monk has uploaded a new change for review.

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

Change subject: Add a hidden link with accesskey=v in SET prefer-wt mode
......................................................................

Add a hidden link with accesskey=v in SET prefer-wt mode

Try to tidy up a bit of code in DAT.init.js as well

Bug: T116406
Change-Id: Iad1713e14ea1f982886ba06e0b722c554ab2b892
---
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
1 file changed, 60 insertions(+), 46 deletions(-)


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

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 26d940b..423206e 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
@@ -22,7 +22,8 @@
 ( function () {
        var conf, tabMessages, uri, pageExists, viewUri, veEditUri, isViewPage, 
isEditPage,
                pageCanLoadVE, init, targetPromise, enable, tempdisable, 
autodisable,
-               tabPreference, userPrefEnabled, initialWikitext, oldid, 
multipleSectionEditLinks,
+               tabPreference, userPrefEnabled, userPrefPreferShow, 
initialWikitext, oldid,
+               multipleSectionEditLinks,
                active = false,
                progressStep = 0,
                progressSteps = [
@@ -429,7 +430,7 @@
                        }
 
                        // If the edit tab is hidden, remove it.
-                       if ( !( init.isAvailable && userPrefEnabled ) ) {
+                       if ( !( init.isAvailable && userPrefPreferShow ) ) {
                                $caVeEdit.remove();
                        } else if ( pageCanLoadVE ) {
                                // Allow instant switching to edit mode, 
without refresh
@@ -625,7 +626,10 @@
                // User has 'visualeditor-enable' preference enabled (for alpha 
opt-in)
                // User has 'visualeditor-betatempdisable' preference disabled
                // User has 'visualeditor-autodisable' preference disabled
-               enable && !tempdisable && !autodisable &&
+               enable && !tempdisable && !autodisable
+       );
+       userPrefPreferShow = (
+               userPrefEnabled &&
 
                // If in two-edit-tab mode, or the user doesn't prefer wikitext 
always
                ( !conf.singleEditTab || tabPreference !== 'prefer-wt' )
@@ -672,7 +676,7 @@
        // on this page. See above for why it may be false.
        mw.libs.ve = $.extend( mw.libs.ve || {}, init );
 
-       if ( init.isAvailable && userPrefEnabled ) {
+       if ( init.isAvailable && userPrefPreferShow ) {
                $( 'html' ).addClass( 've-available' );
        } else {
                $( 'html' ).addClass( 've-not-available' );
@@ -688,7 +692,17 @@
                if ( init.isAvailable ) {
                        // Load the editor …
                        if (
-                               (
+                               uri.query.undo === undefined &&
+                               uri.query.undoafter === undefined &&
+                               uri.query.editintro === undefined &&
+                               uri.query.preload === undefined &&
+                               uri.query.preloadtitle === undefined &&
+                               uri.query.preloadparams === undefined &&
+                               uri.query.veswitched === undefined
+                               // Known-good parameters: edit, veaction, 
section, vesection
+                               // TODO: other params too? See identical list 
in VisualEditor.hooks.php)
+                       ) {
+                               if (
                                        // … if on a ?veaction=edit page
                                        ( isViewPage && uri.query.veaction === 
'edit' ) ||
                                        // … or if on ?action=edit in single 
edit mode and the user wants it
@@ -698,7 +712,7 @@
                                                        uri.query.wteswitched 
=== '1' ||
                                                        (
                                                                tabPreference 
!== 'multi-tab' &&
-                                                               userPrefEnabled 
&&
+                                                               
userPrefPreferShow &&
                                                                // If it's a 
view-source situation, we don't want to show VE on-load
                                                                !$( 
'#ca-viewsource' ).length &&
                                                                (
@@ -714,22 +728,26 @@
                                                        )
                                                )
                                        )
-                               ) &&
-                               uri.query.undo === undefined &&
-                               uri.query.undoafter === undefined &&
-                               uri.query.editintro === undefined &&
-                               uri.query.preload === undefined &&
-                               uri.query.preloadtitle === undefined &&
-                               uri.query.preloadparams === undefined &&
-                               uri.query.veswitched === undefined
-                               // Known-good parameters: edit, veaction, 
section, vesection
-                               // TODO: other params too? See identical list 
in VisualEditor.hooks.php
-                       ) {
-                               trackActivateStart( {
-                                       type: uri.query.vesection === undefined 
? 'page' : 'section',
-                                       mechanism: 'url'
-                               } );
-                               activateTarget();
+                               ) {
+                                       trackActivateStart( {
+                                               type: uri.query.vesection === 
undefined ? 'page' : 'section',
+                                               mechanism: 'url'
+                                       } );
+                                       activateTarget();
+                               } else if ( pageCanLoadVE && userPrefEnabled && 
!userPrefPreferShow ) {
+                                       // 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.
+                                       $( 'body' ).append(
+                                               $( '<a>' )
+                                                       .attr( 'accesskey', 'v' 
)
+                                                       .attr(
+                                                               'href',
+                                                               
uri.clone().extend( { veaction: 'edit' } ).toString()
+                                                       )
+                                                       .hide()
+                                       );
+                               }
                        }
 
                        // Add the switch button to wikitext ?action=edit or 
?action=submit pages
@@ -819,37 +837,33 @@
                        }
 
                        // Set up the tabs appropriately if the user has VE on
-                       if (
-                               userPrefEnabled
-                       ) {
+                       multipleSectionEditLinks = false;
+                       if ( 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.
                                        multipleSectionEditLinks = true;
                                        init.setupSkin();
-                               } else {
-                                       multipleSectionEditLinks = false;
+                               } else if (
                                        // … on single-edit-tab wikis, where VE 
is the user's preferred editor
-                                       if (
-                                               pageCanLoadVE && (
-                                                       tabPreference === 
'prefer-ve' ||
-                                                       (
-                                                               tabPreference 
=== 'remember-last' &&
-                                                               getLastEditor() 
!== 'wikitext'
-                                                       )
+                                       pageCanLoadVE && (
+                                               tabPreference === 'prefer-ve' ||
+                                               (
+                                                       tabPreference === 
'remember-last' &&
+                                                       getLastEditor() !== 
'wikitext'
                                                )
-                                       ) {
-                                               // Handle section edit link 
clicks
-                                               $( '.mw-editsection a' ).on( 
'click', function ( e ) {
-                                                       
init.onEditSectionLinkClick( e );
-                                               } );
-                                               // Allow instant switching to 
edit mode, without refresh
-                                               $( '#ca-edit' ).on( 'click', 
function ( e ) {
-                                                       trackActivateStart( { 
type: 'page', mechanism: 'click' } );
-                                                       activateTarget();
-                                                       e.preventDefault();
-                                               } );
-                                       }
+                                       )
+                               ) {
+                                       // Handle section edit link clicks
+                                       $( '.mw-editsection a' ).on( 'click', 
function ( e ) {
+                                               init.onEditSectionLinkClick( e 
);
+                                       } );
+                                       // Allow instant switching to edit 
mode, without refresh
+                                       $( '#ca-edit' ).on( 'click', function ( 
e ) {
+                                               trackActivateStart( { type: 
'page', mechanism: 'click' } );
+                                               activateTarget();
+                                               e.preventDefault();
+                                       } );
                                }
                        }
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad1713e14ea1f982886ba06e0b722c554ab2b892
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