mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-24 10:48:42 +00:00
DAT.init#setEditorPreference: Change section edit alongside tab labels
When our remember-last preference changes work, alongside changing the label of the edit tab, also change the label of the edit section links. I seriously have no idea WTF I was thinking back in December when I put some of this code into #activatePageTarget. Bug: T137424 Change-Id: I581c0acf0a3ad11ad3bcf4e2e46242907ca9166f
This commit is contained in:
parent
750078ab63
commit
16c38ec27a
|
@ -428,14 +428,6 @@ class VisualEditorHooks {
|
||||||
) {
|
) {
|
||||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' );
|
$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
|
// Exit if we're in parserTests
|
||||||
if ( isset( $GLOBALS[ 'wgVisualEditorInParserTests' ] ) ) {
|
if ( isset( $GLOBALS[ 'wgVisualEditorInParserTests' ] ) ) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -460,11 +452,29 @@ class VisualEditorHooks {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tabMessages = $config->get( 'VisualEditorTabMessages' );
|
$editor = self::getUserEditor( $skin->getUser(), RequestContext::getMain()->getRequest() );
|
||||||
$sourceEditSection = $tabMessages['editsectionsource'] !== null ?
|
if (
|
||||||
$tabMessages['editsectionsource'] : 'editsection';
|
!$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
|
// add VE edit section in VE available namespaces
|
||||||
if ( ApiVisualEditor::isAllowedNamespace( $config, $title->getNamespace() ) ) {
|
if ( ApiVisualEditor::isAllowedNamespace( $config, $title->getNamespace() ) ) {
|
||||||
|
|
|
@ -300,6 +300,7 @@
|
||||||
"create",
|
"create",
|
||||||
"create-local",
|
"create-local",
|
||||||
"edit",
|
"edit",
|
||||||
|
"editsection",
|
||||||
"edit-local",
|
"edit-local",
|
||||||
"pipe-separator",
|
"pipe-separator",
|
||||||
"postedit-confirmation-created",
|
"postedit-confirmation-created",
|
||||||
|
|
|
@ -171,22 +171,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function activatePageTarget( modified ) {
|
function activatePageTarget( modified ) {
|
||||||
var key;
|
|
||||||
trackActivateStart( { type: 'page', mechanism: 'click' } );
|
trackActivateStart( { type: 'page', mechanism: 'click' } );
|
||||||
|
|
||||||
if ( !active ) {
|
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 ( uri.query.action !== 'edit' && uri.query.veaction !== 'edit' ) {
|
||||||
if ( history.pushState ) {
|
if ( history.pushState ) {
|
||||||
// Replace the current state with one that is tagged as ours, to prevent the
|
// Replace the current state with one that is tagged as ours, to prevent the
|
||||||
|
@ -269,10 +256,29 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function setEditorPreference( editor ) {
|
function setEditorPreference( editor ) {
|
||||||
|
var key = pageExists ? 'edit' : 'create',
|
||||||
|
sectionKey = 'editsection';
|
||||||
|
|
||||||
if ( editor !== 'visualeditor' && editor !== 'wikitext' ) {
|
if ( editor !== 'visualeditor' && editor !== 'wikitext' ) {
|
||||||
throw new Error( 'setEditorPreference called with invalid option: ', editor );
|
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 } );
|
$.cookie( 'VEE', editor, { path: '/', expires: 30 } );
|
||||||
if ( mw.user.isAnon() ) {
|
if ( mw.user.isAnon() ) {
|
||||||
return $.Deferred().resolve();
|
return $.Deferred().resolve();
|
||||||
|
|
Loading…
Reference in a new issue