diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 97bdf1abd7..0ed1d0f80e 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -428,14 +428,6 @@ class VisualEditorHooks { ) { $config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' ); - // Exit if we're using the single edit tab. - if ( - $config->get( 'VisualEditorUseSingleEditTab' ) && - $skin->getUser()->getOption( 'visualeditor-tabs' ) !== 'multi-tab' - ) { - return true; - } - // Exit if we're in parserTests if ( isset( $GLOBALS[ 'wgVisualEditorInParserTests' ] ) ) { return true; @@ -460,11 +452,29 @@ class VisualEditorHooks { return true; } - $tabMessages = $config->get( 'VisualEditorTabMessages' ); - $sourceEditSection = $tabMessages['editsectionsource'] !== null ? - $tabMessages['editsectionsource'] : 'editsection'; + $editor = self::getUserEditor( $skin->getUser(), RequestContext::getMain()->getRequest() ); + if ( + !$config->get( 'VisualEditorUseSingleEditTab' ) || + $skin->getUser()->getOption( 'visualeditor-tabs' ) === 'multi-tab' || + ( + $skin->getUser()->getOption( 'visualeditor-tabs' ) === 'remember-last' && + $editor === 'wikitext' + ) + ) { + // Don't add ve-edit, but do update the edit tab (e.g. "Edit source"). + $tabMessages = $config->get( 'VisualEditorTabMessages' ); + $sourceEditSection = $tabMessages['editsectionsource'] !== null ? + $tabMessages['editsectionsource'] : 'editsection'; + $result['editsection']['text'] = $skin->msg( $sourceEditSection )->inLanguage( $lang )->text(); + } - $result['editsection']['text'] = $skin->msg( $sourceEditSection )->inLanguage( $lang )->text(); + // Exit if we're using the single edit tab. + if ( + $config->get( 'VisualEditorUseSingleEditTab' ) && + $skin->getUser()->getOption( 'visualeditor-tabs' ) !== 'multi-tab' + ) { + return true; + } // add VE edit section in VE available namespaces if ( ApiVisualEditor::isAllowedNamespace( $config, $title->getNamespace() ) ) { diff --git a/extension.json b/extension.json index 97c3ff9867..5a51d3d1e5 100644 --- a/extension.json +++ b/extension.json @@ -300,6 +300,7 @@ "create", "create-local", "edit", + "editsection", "edit-local", "pipe-separator", "postedit-confirmation-created", 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 9a5fa19ef2..64c6d4ed42 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 @@ -172,22 +172,9 @@ } function activatePageTarget( modified ) { - var key; trackActivateStart( { type: 'page', mechanism: 'click' } ); if ( !active ) { - if ( - mw.config.get( 'wgVisualEditorConfig' ).singleEditTab && - tabPreference === 'remember-last' - ) { - key = pageExists ? 'edit' : 'create'; - if ( $( '#ca-view-foreign' ).length ) { - key += '-local'; - } - - $( '#ca-edit a' ).text( mw.msg( key ) ); - } - if ( uri.query.action !== 'edit' && uri.query.veaction !== 'edit' ) { if ( history.pushState ) { // Replace the current state with one that is tagged as ours, to prevent the @@ -270,10 +257,29 @@ } function setEditorPreference( editor ) { + var key = pageExists ? 'edit' : 'create', + sectionKey = 'editsection'; + if ( editor !== 'visualeditor' && editor !== 'wikitext' ) { throw new Error( 'setEditorPreference called with invalid option: ', editor ); } + if ( + mw.config.get( 'wgVisualEditorConfig' ).singleEditTab && + tabPreference === 'remember-last' + ) { + if ( $( '#ca-view-foreign' ).length ) { + key += 'localdescription'; + } + if ( editor === 'wikitext' ) { + key += 'source'; + sectionKey += 'source'; + } + + $( '#ca-edit a' ).text( mw.msg( tabMessages[ key ] || 'edit' ) ); + $( '.mw-editsection a' ).text( mw.msg( tabMessages[ sectionKey ] || 'editsection' ) ); + } + $.cookie( 'VEE', editor, { path: '/', expires: 30 } ); if ( mw.user.isAnon() ) { return $.Deferred().resolve();