DesktopArticleTarget.init: Fix wrong message used for 'Edit' tab in rare cases

If a new namespace was added to $wgVisualEditorAvailableNamespaces,
but VE was loaded on a page with old cached HTML, the 'Edit' tab's
text would incorrectly be 'Edit source'.

If $wgVisualEditorTabMessages['edit'] or ...['create'] was changed
from non-null to null, but VE was loaded on a page with old cached
HTML, the tab would still use the old text.

Change-Id: I2d5c7b922ba480eb90fa0a6da7a1901f062c96df
This commit is contained in:
Bartosz Dziewoński 2019-05-13 23:51:30 +02:00
parent a76d3daf54
commit aadec90f0f

View file

@ -267,10 +267,22 @@
mw.libs.ve.activationStart = ve.now();
}
function getTabMessage( key ) {
var tabMsg = tabMessages[ key ];
if ( !tabMsg && ( key === 'edit' || key === 'create' ) ) {
// Some skins don't use the default 'edit' and 'create' message keys.
// e.g. vector-view-edit, vector-view-create
tabMsg = mw.config.get( 'skin' ) + '-view-' + key;
if ( !mw.message( tabMsg ).exists() ) {
tabMsg = key;
}
}
return tabMsg;
}
function setEditorPreference( editor ) {
var key = pageExists ? 'edit' : 'create',
sectionKey = 'editsection',
tabMsg;
sectionKey = 'editsection';
if ( editor !== 'visualeditor' && editor !== 'wikitext' ) {
throw new Error( 'setEditorPreference called with invalid option: ', editor );
@ -288,16 +300,7 @@
sectionKey += 'source';
}
tabMsg = tabMessages[ key ];
if ( !tabMsg && ( key === 'edit' || key === 'create' ) ) {
// e.g. vector-view-edit, vector-view-create
tabMsg = mw.config.get( 'skin' ) + '-view-' + key;
if ( !mw.message( tabMsg ).exists() ) {
tabMsg = key;
}
}
$( '#ca-edit a' ).text( mw.msg( tabMsg ) );
$( '#ca-edit a' ).text( mw.msg( getTabMessage( key ) ) );
$( '.mw-editsection a' ).text( mw.msg( tabMessages[ sectionKey ] ) );
}
@ -634,7 +637,7 @@
// 2) when onEditTabClick is not bound (!pageCanLoadEditor) it will
// just work.
veEditUri,
tabMessages[ action ] !== null ? mw.msg( tabMessages[ action ] ) : $caEditLink.text(),
mw.msg( getTabMessage( action ) ),
'ca-ve-edit',
mw.msg( 'tooltip-ca-ve-edit' ),
mw.msg( 'accesskey-ca-ve-edit' ),
@ -660,9 +663,7 @@
$caEdit.after( $caVeEdit );
}
}
if ( tabMessages[ action ] !== null ) {
$caVeEditLink.text( mw.msg( tabMessages[ action ] ) );
}
$caVeEditLink.text( mw.msg( getTabMessage( action ) ) );
}
// If the edit tab is hidden, remove it.