From ea0ef071a27f716d14fe937778e3d35c5700d24f Mon Sep 17 00:00:00 2001 From: David Lynch Date: Sat, 19 May 2018 22:10:39 +0200 Subject: [PATCH] Intercept desktop editor links Make ?veaction=edit/editsource and ?action=edit trigger the appropriate mobile editing mode. Bug: T185729 Change-Id: I2275b011d2b3c03462e3c1711d3135ce672596e8 --- resources/skins.minerva.editor/init.js | 36 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/resources/skins.minerva.editor/init.js b/resources/skins.minerva.editor/init.js index bbf095d4e..ab0e8b2eb 100644 --- a/resources/skins.minerva.editor/init.js +++ b/resources/skins.minerva.editor/init.js @@ -151,7 +151,8 @@ * @param {Page} page The page to edit. */ function setupEditor( page ) { - var isNewPage = page.options.id === 0, + var uri, fragment, editorOverride, + isNewPage = page.options.id === 0, leadSection = page.getLeadSectionElement(); if ( mw.util.getParamValue( 'undo' ) ) { @@ -237,9 +238,15 @@ // Not on pages which are outputs of the Page Translation feature mw.config.get( 'wgTranslatePageTranslation' ) !== 'translation' && - // If the user prefers the VisualEditor or the user has no preference and - // the VisualEditor is the default editor for this wiki - preferredEditor === 'VisualEditor' + ( + // If the user prefers the VisualEditor or the user has no preference and + // the VisualEditor is the default editor for this wiki + preferredEditor === 'VisualEditor' || + // We've loaded it via the URL for this request + editorOverride === 'VisualEditor' + ) && + + editorOverride !== 'SourceEditor' ) { logInit( 'visualeditor' ); loader.loadModule( 'mobile.editor.ve' ).done( function () { @@ -302,6 +309,27 @@ // prevent folding section when clicking Edit ev.stopPropagation(); } ); + + if ( !router.getPath() && ( mw.util.getParamValue( 'veaction' ) || mw.util.getParamValue( 'action' ) ) ) { + if ( mw.util.getParamValue( 'veaction' ) === 'edit' ) { + editorOverride = 'VisualEditor'; + } else if ( mw.util.getParamValue( 'veaction' ) === 'editsource' ) { + editorOverride = 'SourceEditor'; + } + // else: action=edit, for which we allow the default to take effect + fragment = '#/editor/' + ( mw.util.getParamValue( 'section' ) || '0' ); + if ( window.history && history.pushState ) { + uri = mw.Uri(); + delete uri.query.action; + delete uri.query.veaction; + // Note: replaceState rather than pushState, because we're + // just reformatting the URL to the equivalent-meaning for the + // mobile site. + history.replaceState( null, document.title, uri.toString() + fragment ); + } else { + router.navigate( fragment ); + } + } } /**