diff --git a/.jsduck/categories.json b/.jsduck/categories.json index 231e935eb8..30501f2a7c 100644 --- a/.jsduck/categories.json +++ b/.jsduck/categories.json @@ -70,6 +70,7 @@ "mw.Api", "mw.Message", "mw.Title", + "mw.Uri", "mw.widgets.*Widget" ] }, diff --git a/.jsduck/external.js b/.jsduck/external.js index c6d86eff0b..837de01367 100644 --- a/.jsduck/external.js +++ b/.jsduck/external.js @@ -13,6 +13,11 @@ * @source */ +/** + * @class mw.Uri + * @source + */ + /** * @class mw.widgets.TitleInputWidget * @source diff --git a/.jsduck/mw-categories.json b/.jsduck/mw-categories.json index 7d74223e29..8a30f23d71 100644 --- a/.jsduck/mw-categories.json +++ b/.jsduck/mw-categories.json @@ -70,6 +70,7 @@ "mw.Api", "mw.Message", "mw.Title", + "mw.Uri", "mw.widgets.*Widget" ] }, diff --git a/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js index 8540d96901..98a960b8c3 100644 --- a/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js +++ b/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js @@ -670,6 +670,13 @@ return editor; } + /** + * Get the preferred editor for this edit page + * + * For the preferred *available* editor, use getAvailableEditPageEditor. + * + * @return {string} 'visualeditor' or 'wikitext' + */ function getEditPageEditor() { // This logic matches VisualEditorHooks::getEditPageEditor // !!+ casts '0' to false @@ -697,6 +704,28 @@ } } + /** + * Get the preferred editor which is also available on this edit page + * + * @return {string} 'visual' or 'source' + */ + function getAvailableEditPageEditor() { + switch ( getEditPageEditor() ) { + case 'visualeditor': + if ( init.isVisualAvailable ) { + return 'visual'; + } + if ( init.isWikitextAvailable ) { + return 'source'; + } + return null; + + case 'wikitext': + default: + return init.isWikitextAvailable ? 'source' : null; + } + } + function checkPreferenceOrStorage( prefName, storageKey, cookieName ) { storageKey = storageKey || prefName; cookieName = cookieName || storageKey; @@ -760,11 +789,11 @@ tabPreference = mw.user.options.get( 'visualeditor-tabs' ); function isOnlyTabVE() { - return conf.singleEditTab && getEditPageEditor() === 'visualeditor'; + return conf.singleEditTab && getAvailableEditPageEditor() === 'visual'; } function isOnlyTabWikitext() { - return conf.singleEditTab && getEditPageEditor() === 'wikitext'; + return conf.singleEditTab && getAvailableEditPageEditor() === 'source'; } init = { @@ -1447,6 +1476,12 @@ } ); } + /** + * Get the edit mode for the given URI + * + * @param {mw.Uri} editUri Edit URI + * @return {string} 'visual' or 'source' + */ function getEditModeFromUri( editUri ) { if ( mw.config.get( 'wgDiscussionToolsStartNewTopicTool' ) ) { // Avoid conflicts with DiscussionTools @@ -1467,19 +1502,7 @@ if ( !enabledForUser || $( '#ca-viewsource' ).length || mw.config.get( 'wgAction' ) === 'submit' ) { return null; } - switch ( getEditPageEditor() ) { - case 'visualeditor': - if ( init.isVisualAvailable ) { - return 'visual'; - } - if ( init.isWikitextAvailable ) { - return 'source'; - } - return null; - - case 'wikitext': - return init.isWikitextAvailable ? 'source' : null; - } + return getAvailableEditPageEditor(); } return null; }