User:MB/edit summary.js
Appearance
< User:MB
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:MB/edit summary. |
/* _____________________________________________________________________________
* | |
* | === WARNING: GLOBAL GADGET FILE === |
* | Changes to this page affect many users. |
* | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
* |_____________________________________________________________________________|
*
* Imported as of 09/06/2011 from [[User:ErrantX/defaultsummaries.js]]
* Edited version from [[User:MC10/defaultsummaries.js]]
* Implements default edit summary dropdown boxes
*/
/* global mw, ve */
/* eslint-disable no-jquery/no-global-selector */
( function () { // Wrap with anonymous function
var $summaryBox = $( '#wpSummary' ),
minorSummaries = [
'Spelling/grammar/punctuation correction',
'Remove redlinked hatnote per [[WP:REDHAT]]',
'Remove link in "See also" section that is alreadly linked in article',
'Remove icon per [[MOS:INFOBOXFLAG]], [[MOS:ICONDECORATION]]',
'Update biographical short description per [[WP:SDDATES]]',
'Fixing style/layout errors',
'[[Help:Reverting|Reverting]] [[Wikipedia:Vandalism|vandalism]] or test edit',
'[[Help:Reverting|Reverting]] unexplained content removal',
'Copyedit (minor)'
],
articleSummaries = [
'Fixing infobox maintenance errors',
'Fixing minor reference errors',
'Adding or fixing coordinates',
'Adding/removing external link(s)',
'Adding/removing wikilink(s) ([[WP:SEAOFBLUE]])',
'Removing unsourced content',
'Removing ELs in text ([[WP:SPAM|linkspam]]) per [[WP:EL]]',
'Move image(s) to prevent "sandwiched" text per [[MOS:SANDWICH]]',
'Infobox cleanup',
'Rmv undefined, unsupported, deprecated infobox parameters'
],
nonArticleSummaries = [
'Reply',
'Comment',
'Suggestion'
],
talkPageSummaries = [
'[[Wikipedia:WikiProject|WikiProject]] tagging',
'[[Wikipedia:WikiProject|WikiProject]] assessment'
];
function addOptionsToDropdown( dropdown, optionTexts ) {
dropdown.menu.addItems( optionTexts.map( function ( optionText ) {
return new OO.ui.MenuOptionWidget( { label: optionText } );
} ) );
}
function onSummarySelect( option ) {
// Save the original value of the edit summary field
var editsummOriginalSummary = $summaryBox.val(),
canned = option.getLabel(),
newSummary = editsummOriginalSummary;
// Append old edit summary with space, if exists,
// and last character != space
if ( newSummary.length !== 0 && newSummary.charAt( newSummary.length - 1 ) !== ' ' ) {
newSummary += ' ';
}
newSummary += canned;
$summaryBox.val( newSummary ).trigger( 'change' );
}
function insertSummaryOptions( $insertBeforeThis, dropdownWidth ) {
// For convenience, add a dropdown box with some canned edit
// summaries to the form.
var namespace = mw.config.get( 'wgNamespaceNumber' ),
dropdown = new OO.ui.DropdownWidget( {
label: 'MB custom edit summaries – click to use'
} ),
minorDropdown = new OO.ui.DropdownWidget( {
label: 'MB custom minor edit summaries – click to use'
} );
dropdown.$element.css( 'width', dropdownWidth );
dropdown.menu.on( 'select', onSummarySelect );
minorDropdown.$element.css( 'width', dropdownWidth );
minorDropdown.menu.on( 'select', onSummarySelect );
addOptionsToDropdown( minorDropdown, minorSummaries );
if ( namespace === 0 ) {
addOptionsToDropdown( dropdown, articleSummaries );
} else {
addOptionsToDropdown( dropdown, nonArticleSummaries );
if ( namespace % 2 !== 0 && namespace !== 3 ) {
addOptionsToDropdown( dropdown, talkPageSummaries );
}
}
$insertBeforeThis.before( dropdown.$element );
$insertBeforeThis.before( minorDropdown.$element );
}
// VisualEditor
mw.hook( 've.saveDialog.stateChanged' ).add( function () {
var target, $saveOptions;
// .ve-init-mw-viewPageTarget-saveDialog-checkboxes
if ( $( 'body' ).data( 'wppresent' ) ) {
return;
}
$( 'body' ).data( 'wppresent', 'true' );
target = ve.init.target;
$saveOptions = target.saveDialog.$saveOptions;
$summaryBox = target.saveDialog.editSummaryInput.$input;
if ( !$saveOptions.length ) {
return;
}
insertSummaryOptions( $saveOptions );
} );
// WikiEditor
$.when( mw.loader.using( 'oojs-ui-core' ), $.ready ).then( function () {
var $editCheckboxes = $( '.editCheckboxes' );
// If we failed to find the editCheckboxes class
if ( !$editCheckboxes.length ) {
return;
}
insertSummaryOptions( $editCheckboxes, '48%' );
} );
}() );