Alex Monk has uploaded a new change for review. https://gerrit.wikimedia.org/r/247485
Change subject: [WIP] Dialog for switching between wikitext and visual editing ...................................................................... [WIP] Dialog for switching between wikitext and visual editing Change-Id: I7046ffbe318d046b4baee11f4148ab77fc2af7fd --- M VisualEditor.hooks.php M extension.json M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js M modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js 4 files changed, 80 insertions(+), 38 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/85/247485/1 diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 9e351ec..777b24a 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -45,6 +45,9 @@ 'ext.visualEditor.desktopArticleTarget.init', 'ext.visualEditor.targetLoader' ) ); + if ( in_array( Action::getActionName( RequestContext::getMain() ), array( 'edit', 'submit' ) ) ) { + $output->addModules( 'ext.visualEditor.switching' ); + } $output->addModuleStyles( array( 'ext.visualEditor.desktopArticleTarget.noscript' ) ); // add scroll offset js variable to output $veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' ); diff --git a/extension.json b/extension.json index a3194a3..fe17405 100644 --- a/extension.json +++ b/extension.json @@ -950,6 +950,24 @@ "mobile" ] }, + "ext.visualEditor.switching": { + "scripts": [ + "modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js" + ], + "dependencies": [ + "oojs", + "oojs-ui", + "ext.visualEditor.core" + ], + "messages": [ + "visualeditor-mweditmodesource-title", + "visualeditor-mweditmodesource-tool", + "visualeditor-mweditmodesource-warning", + "visualeditor-mweditmodesource-warning-cancel", + "visualeditor-mweditmodesource-warning-switch", + "visualeditor-mweditmodesource-warning-switch-discard" + ] + }, "ext.visualEditor.mwcore": { "scripts": [ "modules/ve-mw/dm/nodes/ve.dm.MWEntityNode.js", @@ -974,7 +992,6 @@ "modules/ve-mw/ui/dialogs/ve.ui.MWWelcomeDialog.js", "modules/ve-mw/ui/dialogs/ve.ui.MWCommandHelpDialog.js", "modules/ve-mw/ui/dialogs/ve.ui.MWCancelConfirmDialog.js", - "modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js", "modules/ve-mw/ui/tools/ve.ui.MWEditModeTool.js", "modules/ve-mw/ui/tools/ve.ui.MWPopupTool.js", "modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js", @@ -999,7 +1016,8 @@ "jquery.byteLimit", "mediawiki.skinning.content.parsoid", "mediawiki.language.specialCharacters", - "mediawiki.widgets" + "mediawiki.widgets", + "ext.visualEditor.switching" ], "messages": [ "visualeditor-beta-label", @@ -1017,12 +1035,6 @@ "visualeditor-help-label", "visualeditor-help-link", "visualeditor-help-title", - "visualeditor-mweditmodesource-title", - "visualeditor-mweditmodesource-tool", - "visualeditor-mweditmodesource-warning", - "visualeditor-mweditmodesource-warning-cancel", - "visualeditor-mweditmodesource-warning-switch", - "visualeditor-mweditmodesource-warning-switch-discard", "visualeditor-pagemenu-tooltip", "visualeditor-pagetranslationwarning", "visualeditor-savedialog-error-badtoken", 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 cabc729..8e3220d 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 @@ -18,7 +18,7 @@ * @singleton */ ( function () { - var conf, tabMessages, uri, pageExists, viewUri, veEditUri, isViewPage, + var conf, tabMessages, uri, pageExists, viewUri, veEditUri, isViewPage, pageCanLoadVE, init, support, targetPromise, enable, tempdisable, autodisable, userPrefEnabled, active = false, progressStep = 0, @@ -143,6 +143,25 @@ return targetPromise; } + function activatePageTarget() { + 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 ); + } + + // Update mw.Uri instance + uri = veEditUri; + + activateTarget(); + } + } /** * Load and activate the target. * @@ -203,16 +222,15 @@ uri = new mw.Uri(); pageExists = !!mw.config.get( 'wgRelevantArticleId' ); viewUri = new mw.Uri( mw.util.getUrl( mw.config.get( 'wgRelevantPageName' ) ) ); - isViewPage = ( - mw.config.get( 'wgIsArticle' ) && - !( 'diff' in uri.query ) - ) || ( + isViewPage = mw.config.get( 'wgIsArticle' ) && !( 'diff' in uri.query ); + pageCanLoadVE = ( + isViewPage || mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ); // On a view page, extend the current URI so parameters like oldid are carried over // On a non-view page, use viewUri - veEditUri = ( isViewPage ? uri : viewUri ).clone().extend( { veaction: 'edit' } ); + veEditUri = ( pageCanLoadVE ? uri : viewUri ).clone().extend( { veaction: 'edit' } ); support = { es5: !!( @@ -326,7 +344,7 @@ // Use url instead of '#'. // So that 1) one can always open it in a new tab, even when // onEditTabClick is bound. - // 2) when onEditTabClick is not bound (!isViewPage) it will + // 2) when onEditTabClick is not bound (!pageCanLoadVE) it will // just work. veEditUri, tabMessages[ action ] !== null ? mw.msg( tabMessages[ action ] ) : $caEditLink.text(), @@ -396,7 +414,7 @@ ); } - if ( isViewPage ) { + if ( pageCanLoadVE ) { // Allow instant switching to edit mode, without refresh $caVeEdit.click( init.onEditTabClick ); } @@ -470,7 +488,7 @@ ); } - if ( isViewPage ) { + if ( pageCanLoadVE ) { // Only init without refresh if we're on a view page. Though section edit links // are rarely shown on non-view pages, they appear in one other case, namely // when on a diff against the latest version of a page. In that case we mustn't @@ -484,6 +502,10 @@ }, onEditTabClick: function ( e ) { + var wikitextModified = true, // TODO: This. + windowManager = new OO.ui.WindowManager, + switchWindow; + // Default mouse button is normalised by jQuery to key code 1. // Only do our handling if no keys are pressed, mouse button is 1 // (e.g. not middle click or right click) and no modifier keys @@ -492,22 +514,27 @@ return; } - trackActivateStart( { type: 'page', mechanism: 'click' } ); + if ( !isViewPage && ( mw.config.get( 'wgAction' ) === 'submit' || wikitextModified ) ) { + // Prompt if either we're on action=submit (the user has previewed) or + // the wikitext hash is different to the value observed upon page load. - 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 ); - } - - // Update mw.Uri instance - uri = veEditUri; - - activateTarget(); + $( 'body' ).append( windowManager.$element ); + switchWindow = new ve.ui.MWWikitextSwitchConfirmDialog; + windowManager.addWindows( [ switchWindow ] ); + windowManager.openWindow( switchWindow ).done( function ( opened ) { + opened.done( function ( closing ) { + closing.done( function ( data ) { + if ( data && data.action === 'keep' ) { + activatePageTarget(); + } else if ( data && data.action === 'discard' ) { + // TODO: Probably some improvements to be made around the way this works. + location.href = veEditUri; + } + } ); + } ); + } ); + } else { + activatePageTarget(); } e.preventDefault(); @@ -608,7 +635,7 @@ isSection; if ( init.isAvailable ) { - if ( isViewPage && uri.query.veaction === 'edit' ) { + if ( pageCanLoadVE && uri.query.veaction === 'edit' ) { isSection = uri.query.vesection !== undefined; trackActivateStart( { type: isSection ? 'section' : 'page', mechanism: 'url' } ); diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js index 2bf9f6d..3f098c6 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js @@ -34,24 +34,24 @@ ve.ui.MWWikitextSwitchConfirmDialog.static.icon = 'help'; ve.ui.MWWikitextSwitchConfirmDialog.static.title = - OO.ui.deferMsg( 'visualeditor-mweditmodesource-title' ); + mw.msg( 'visualeditor-mweditmodesource-title' ); ve.ui.MWWikitextSwitchConfirmDialog.static.message = - OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning' ); + mw.msg( 'visualeditor-mweditmodesource-warning' ); ve.ui.MWWikitextSwitchConfirmDialog.static.actions = [ { - label: OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning-cancel' ), + label: mw.msg( 'visualeditor-mweditmodesource-warning-cancel' ), flags: [ 'safe', 'back' ] }, { action: 'keep', - label: OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning-switch' ), + label: mw.msg( 'visualeditor-mweditmodesource-warning-switch' ), flags: [ 'progressive', 'primary' ] }, { action: 'discard', - label: OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning-switch-discard' ), + label: mw.msg( 'visualeditor-mweditmodesource-warning-switch-discard' ), flags: 'destructive' } ]; -- To view, visit https://gerrit.wikimedia.org/r/247485 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7046ffbe318d046b4baee11f4148ab77fc2af7fd Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Alex Monk <kren...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits