mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-23 14:06:52 +00:00
DesktopArticleTarget.init: Remove code for updating edit links
This JS code duplicates the PHP implementation in VisualEditorHooks
in order to allow changes to the configuration of edit tabs
(e.g. wgVisualEditorUseSingleEditTab and wgVisualEditorTabPosition)
to take effect for logged-out users immediately, without waiting
for the HTML caches to clear.
It was worthwhile 10 years ago when VisualEditor was being rolled out
to new wikis or reconfigured daily, but it is not today when we hardly
ever change these settings.
It proved difficult to maintain as the skins change, it has several
known bugs (T292125, T306807, T346944), and probably several more
unknown ones, given that it hasn't been tested in about 10 years.
Let's remove it and save ourselves the headache. (Also also reduce the
amount of code we ship on all page views by almost a kilobyte.)
Bug: T292125
Bug: T306807
Bug: T346944
Change-Id: Ib82f5402872a2429445463a1e1ef92806d3326f9
(cherry picked from commit be36f1fab1
)
This commit is contained in:
parent
8687237a05
commit
200062ea5c
|
@ -403,13 +403,7 @@
|
|||
"ext.visualEditor.tempWikitextEditorWidget"
|
||||
],
|
||||
"messages": [
|
||||
"accesskey-ca-editsource",
|
||||
"accesskey-ca-ve-edit",
|
||||
"pipe-separator",
|
||||
"tooltip-ca-createsource",
|
||||
"tooltip-ca-edit",
|
||||
"tooltip-ca-editsource",
|
||||
"tooltip-ca-ve-edit"
|
||||
"accesskey-ca-ve-edit"
|
||||
]
|
||||
},
|
||||
"ext.visualEditor.desktopArticleTarget.noscript": {
|
||||
|
|
|
@ -906,84 +906,13 @@
|
|||
},
|
||||
|
||||
setupMultiTabs: function () {
|
||||
var action = pageExists ? 'edit' : 'create',
|
||||
var
|
||||
isMinerva = mw.config.get( 'skin' ) === 'minerva',
|
||||
pTabsId = isMinerva ? 'page-actions' :
|
||||
$( '#p-views' ).length ? 'p-views' : 'p-cactions',
|
||||
// Minerva puts the '#ca-...' ids on <a> nodes
|
||||
$caSource = $( '#ca-viewsource' ),
|
||||
$caEdit = $( '#ca-edit, li#page-actions-edit' ),
|
||||
$caVeEdit = $( '#ca-ve-edit' ),
|
||||
$caEditLink = $caEdit.find( 'a' ),
|
||||
$caVeEditLink = $caVeEdit.find( 'a' ),
|
||||
caVeEditNextnode =
|
||||
( conf.tabPosition === 'before' ) ?
|
||||
$caEdit.get( 0 ) :
|
||||
$caEdit.next().get( 0 );
|
||||
$caVeEdit = $( '#ca-ve-edit' );
|
||||
|
||||
if ( !$caVeEdit.length ) {
|
||||
// The below duplicates the functionality of VisualEditorHooks::onSkinTemplateNavigation()
|
||||
// in case we're running on a cached page that doesn't have these tabs yet.
|
||||
|
||||
// Alter the edit tab (#ca-edit)
|
||||
if ( $( '#ca-view-foreign' ).length ) {
|
||||
if ( tabMessages[ action + 'localdescriptionsource' ] ) {
|
||||
// The following messages can be used here:
|
||||
// * editlocaldescriptionsource
|
||||
// * createlocaldescriptionsource
|
||||
$caEditLink.text( mw.msg( tabMessages[ action + 'localdescriptionsource' ] ) );
|
||||
}
|
||||
} else {
|
||||
if ( tabMessages[ action + 'source' ] ) {
|
||||
// The following messages can be used here:
|
||||
// * editsource
|
||||
// * createsource
|
||||
$caEditLink.text( mw.msg( tabMessages[ action + 'source' ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no edit tab or a view-source tab,
|
||||
// the user doesn't have permission to edit.
|
||||
if ( $caEdit.length && !$caSource.length ) {
|
||||
// Add the VisualEditor tab (#ca-ve-edit)
|
||||
var caVeEdit = mw.util.addPortletLink(
|
||||
pTabsId,
|
||||
// Use url instead of '#'.
|
||||
// So that 1) one can always open it in a new tab, even when
|
||||
// onEditTabClick is bound.
|
||||
// 2) when onEditTabClick is not bound (!pageCanLoadEditor) it will
|
||||
// just work.
|
||||
veEditUri,
|
||||
getTabMessage( action ),
|
||||
'ca-ve-edit',
|
||||
mw.msg( 'tooltip-ca-ve-edit' ),
|
||||
mw.msg( 'accesskey-ca-ve-edit' ),
|
||||
caVeEditNextnode
|
||||
);
|
||||
|
||||
$caVeEdit = $( caVeEdit );
|
||||
if ( isMinerva ) {
|
||||
$caVeEdit.find( '.mw-ui-icon' ).addClass( 'mw-ui-icon-wikimedia-edit-base20' );
|
||||
}
|
||||
}
|
||||
} else if ( $caEdit.length && $caVeEdit.length ) {
|
||||
// Make the state of the page consistent with the config if needed
|
||||
if ( conf.tabPosition === 'before' ) {
|
||||
if ( $caEdit.next()[ 0 ] === $caVeEdit[ 0 ] ) {
|
||||
$caVeEdit.after( $caEdit );
|
||||
}
|
||||
} else {
|
||||
if ( $caVeEdit.next()[ 0 ] === $caEdit[ 0 ] ) {
|
||||
$caEdit.after( $caVeEdit );
|
||||
}
|
||||
}
|
||||
$caVeEditLink.text( getTabMessage( action ) );
|
||||
}
|
||||
|
||||
// If the edit tab is hidden, remove it.
|
||||
if ( !( init.isVisualAvailable ) ) {
|
||||
$caVeEdit.remove();
|
||||
} else if ( pageCanLoadEditor ) {
|
||||
if ( pageCanLoadEditor ) {
|
||||
// Allow instant switching to edit mode, without refresh
|
||||
$caVeEdit.off( '.ve-target' ).on( 'click.ve-target', init.onEditTabClick.bind( init, 'visual' ) );
|
||||
}
|
||||
|
@ -1033,54 +962,6 @@
|
|||
|
||||
var isMinerva = mw.config.get( 'skin' ) === 'minerva';
|
||||
|
||||
// The "visibility" css construct ensures we always occupy the same space in the layout.
|
||||
// This prevents the heading from changing its wrap when the user toggles editSourceLink.
|
||||
if ( $editsections.find( '.mw-editsection-visualeditor' ).length === 0 ) {
|
||||
// If PHP didn't build the section edit links (because of caching), build them
|
||||
$editsections.each( function () {
|
||||
var $editsection = $( this ),
|
||||
$editSourceLink = $editsection.find( 'a' ).eq( 0 ),
|
||||
$editLink = $editSourceLink.clone(),
|
||||
$divider = $( '<span>' ),
|
||||
dividerText = mw.msg( 'pipe-separator' );
|
||||
|
||||
// The following messages can be used here:
|
||||
// * visualeditor-ca-editsource-section
|
||||
// * config value of tabMessages.editsectionsource
|
||||
$editSourceLink.text( mw.msg( tabMessages.editsectionsource ) );
|
||||
// The following messages can be used here:
|
||||
// * editsection
|
||||
// * config value of tabMessages.editsections
|
||||
$editLink.text( mw.msg( tabMessages.editsection ) );
|
||||
|
||||
$divider
|
||||
.addClass( 'mw-editsection-divider' )
|
||||
.text( dividerText );
|
||||
// Don't mess with section edit links on foreign file description pages (T56259)
|
||||
if ( !$( '#ca-view-foreign' ).length ) {
|
||||
$editLink
|
||||
.attr( 'href', function ( i, href ) {
|
||||
var veUri = new mw.Uri( veEditUri );
|
||||
veUri.query.section = ( new mw.Uri( href ) ).query.section;
|
||||
return veUri.toString();
|
||||
} )
|
||||
.addClass( 'mw-editsection-visualeditor' );
|
||||
|
||||
if ( conf.tabPosition === 'before' ) {
|
||||
$editSourceLink.before( $editLink, $divider );
|
||||
if ( isMinerva ) {
|
||||
$editLink.removeClass( 'mw-ui-icon-flush-right' );
|
||||
}
|
||||
} else {
|
||||
$editSourceLink.after( $divider, $editLink );
|
||||
if ( isMinerva ) {
|
||||
$editSourceLink.removeClass( 'mw-ui-icon-flush-right' );
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
if ( isMinerva ) {
|
||||
// Minerva hides the link text - display tiny icons instead
|
||||
mw.loader.load( [ 'oojs-ui.styles.icons-editing-advanced', 'oojs-ui.styles.icons-accessibility' ] );
|
||||
|
|
Loading…
Reference in a new issue