MediaWiki:Gadget-customreasons.js

/** * Allows users to define custom reason pages for deletes, file deletes, and blocks * * Pages: *    Deletes: User:ExampleUser/Filedelete-reason-dropdown *    File deletes: User:ExampleUser/Deletereason-dropdown *    Blocks: User:ExampleUser/Ipbreason-dropdown * * @author grunny */ /*globals jQuery, mediaWiki, window */ ( function ( $, mw, window ) {	'use strict';

var CustomReasons = {

init: function { if ( mw.config.get( 'wgAction' ) === 'delete' && $( '#wpDeleteReasonList' ).length ) { if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) { CustomReasons.getReasonList( 'User:' + mw.config.get( 'wgUserName' ) + '/Filedelete-reason-dropdown', '#wpDeleteReasonList' ); } else { CustomReasons.getReasonList( 'User:' + mw.config.get( 'wgUserName' ) + '/Deletereason-dropdown', '#wpDeleteReasonList' ); }			} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Block' && $( '#mw-input-wpReason' ).length ) { CustomReasons.getReasonList( 'User:' + mw.config.get( 'wgUserName' ) + '/Ipbreason-dropdown', '#mw-input-wpReason' ); }		},

getReasonList: function ( pageName, container ) { $.get( mw.config.get( 'wgScript' ), { title: pageName, action: 'raw', ctype: 'text/plain' } ).done( function ( data ) {				var	summaryOptionsHtml = ' Other reason ',					i,					lines = data.split( '\n' ),					value,					optgroup = false;				if ( data ===  ) {					// Page has no content					return false;				}				for ( i in lines ) {					if ( lines.hasOwnProperty( i ) ) {						value = $.trim( lines[i] );						if ( value ===  ) {							continue;						} else if ( value.substr( 0, 1 ) === '*' && value.substr( 1, 1 ) !== '*' ) {							// A new group is starting ...							value = $.trim( value.substr( 1 ) );							if ( optgroup ) {								summaryOptionsHtml += ' ';							}							summaryOptionsHtml += '';							optgroup = true;						} else if ( value.substr( 0, 2 ) === '**' ) {							// groupmember							value = $.trim( value.substr( 2 ) );							summaryOptionsHtml += '' + value + ' '; } else { // groupless reason list if ( optgroup ) { summaryOptionsHtml += ' '; }							summaryOptionsHtml += '' + value + ' '; optgroup = false; }					}				}				if ( optgroup ) { summaryOptionsHtml += ' '; }				$( container ).html( summaryOptionsHtml ); } ).fail( function { // Page doesn't exist or other error return false; } );;		}	};	$( CustomReasons.init ); }( jQuery, mediaWiki, window ) );