mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-23 14:06:52 +00:00
Fix logic for getting the *available* preferred editor
Factor out getAvailableEditPageEditor from getEditModeFromUri and use instead of getEditPageEditor everywhere. Bug: T316776 Change-Id: I34bab092b829124c52f8bc0e262a9c3aa17f2c52
This commit is contained in:
parent
45b36ad683
commit
a625d0b7b7
|
@ -70,6 +70,7 @@
|
|||
"mw.Api",
|
||||
"mw.Message",
|
||||
"mw.Title",
|
||||
"mw.Uri",
|
||||
"mw.widgets.*Widget"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
"mw.Api",
|
||||
"mw.Message",
|
||||
"mw.Title",
|
||||
"mw.Uri",
|
||||
"mw.widgets.*Widget"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue