Merge "Fix logic for getting the *available* preferred editor"

This commit is contained in:
jenkins-bot 2022-09-01 20:41:25 +00:00 committed by Gerrit Code Review
commit 4687e27ffa
4 changed files with 45 additions and 15 deletions

View file

@ -70,6 +70,7 @@
"mw.Api",
"mw.Message",
"mw.Title",
"mw.Uri",
"mw.widgets.*Widget"
]
},

View file

@ -13,6 +13,11 @@
* @source <https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Title>
*/
/**
* @class mw.Uri
* @source <https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Uri>
*/
/**
* @class mw.widgets.TitleInputWidget
* @source <https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.widgets.TitleInputWidget>

View file

@ -70,6 +70,7 @@
"mw.Api",
"mw.Message",
"mw.Title",
"mw.Uri",
"mw.widgets.*Widget"
]
},

View file

@ -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;
}