User:KylieTastic/editsummaries.js

/*  * Based on WP Gadget MediaWiki:Gadget-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' ),		rightSummaries = [			'Revert/remove attempt to hot-link external image - images must be uploaded WP:UPIMAGE (copyright allowing)',			'Revert - not a recognised image file - Note images must be uploaded WP:UPIMAGE (copyright allowing)',			'Removed missing (red-linked) image - not a recognised image file - Note images must be uploaded WP:UPIMAGE (copyright allowing)',			'Fixed broken image - editor changing text in file names',			'Fixed broken (red-linked) image',			'Fixed broken (blue-linked) image',			'Remove inline External links',			'Revert asserting National varieties of English (see WP:ENGVAR specifically MOS:RETAIN)',			'No point adding back link to a file that has been deleted (unless re-upload or restored by OTRS first)',			'Removed missing image - File was deleted from Wikimedia Commons - ', 'Removed missing image - File was deleted from English Wikipedia - ', '-thumb (see WP:INFOBOXIMAGE)' ],		articleSummaries = [ 'Expanding article', 'Adding/improving reference(s)', 'Adding/removing wikilink(s)', 'Clean up/copyedit', 'Adding/removing category/ies', 'Adding/removing external link(s)', 'Removing unsourced content', 'Not an article - more user page content see User pages' ],		nonArticleSummaries = [ 'Reply', 'Comment', 'Suggestion' ],		talkPageSummaries = [ 'WikiProject tagging', '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 getSummaryDropdowns { // 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: 'Common edit summaries – click to use'			} ), rightDropdown = new OO.ui.DropdownWidget( {				label: 'Image edit summaries – click to use'			} );

dropdown.menu.on( 'select', onSummarySelect ); rightDropdown.menu.on( 'select', onSummarySelect );

addOptionsToDropdown( rightDropdown, rightSummaries );

if ( namespace === 0 ) { addOptionsToDropdown( dropdown, articleSummaries ); } else { addOptionsToDropdown( dropdown, nonArticleSummaries ); if ( namespace % 2 !== 0 && namespace !== 3 ) { addOptionsToDropdown( dropdown, talkPageSummaries ); }		}		return dropdown.$element.add( rightDropdown.$element ); }	// VisualEditor mw.hook( 've.saveDialog.stateChanged' ).add( function {		var target, $saveOptions, $dropdowns;		// .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; }		$dropdowns = getSummaryDropdowns; $saveOptions.before( $dropdowns ); } );	// WikiEditor	$.when( mw.loader.using( 'oojs-ui-core' ), $.ready ).then( function { var $dropdowns, $editCheckboxes = $( '.editCheckboxes' );

// If we failed to find the editCheckboxes class if ( !$editCheckboxes.length ) { return; }		$dropdowns = getSummaryDropdowns; $dropdowns.css( {			width: '48%',			'padding-bottom': '1em'		} ); $editCheckboxes.before( $dropdowns ); } ); } );