Intercept desktop editor links

Make ?veaction=edit/editsource and ?action=edit trigger the appropriate mobile
editing mode.

Bug: T185729
Change-Id: I2275b011d2b3c03462e3c1711d3135ce672596e8
This commit is contained in:
David Lynch 2018-05-19 22:10:39 +02:00
parent 72d16027de
commit ea0ef071a2

View file

@ -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 );
}
}
}
/**