Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
//define  custom buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdButton = {};
wikEdButton[100] = ['wikEdBraces', 'wikEdButton', 'Enclose the selection with Braces', 'http://upload.wikimedia.org/wikipedia/commons/6/67/WikEd_logo.png', '16', '16', 'Braces', 'javascript:WikEdEditButton(this, this.id, null, BracesHandler);' ];
wikEdButton[101] = ['wikEdBrackets', 'wikEdButton', 'Enclose the selection with Brackets', 'http://upload.wikimedia.org/wikipedia/commons/0/07/WikEd_disabled.png', '16', '16', 'Brackets', 'javascript:WikEdEditButton(this, this.id, null, BracketsHandler);' ];
wikEdButton[102] = ['wikEdRefSect', 'wikEdButton', 'Insert the reference section', 'http://upload.wikimedia.org/wikipedia/commons/0/07/WikEd_disabled.png', '16', '16', 'RefSect', 'javascript:WikEdEditButton(this, this.id, null, RefSectionHandler);' ];

//define custom button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
var wikEdButtonBar = {};
wikEdButtonBar['custom1'] = ['wikEdButtonBarCustom1', 'wikEdButtonBarCustom1', 'wikEdButtonsCustom1', 'wikEdButtonsCustom1', 44, 'My custom buttons1', [100, 101, 102] ];


//==========================================================
//This function adds or removes Brackets around the selected text
//==========================================================
function BracketsHandler(obj) {

WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
  obj.changed = obj.selection;
}
else {
  obj.changed = obj.cursor;
}

if ( /\((.*?)\)/i.test(obj.changed.plain) ) {
  obj.changed.plain = obj.changed.plain.replace(/\((.*?)\)/gi, '$1');
}
// add the text formatting
else {
  obj.changed.plain = '(' + obj.changed.plain + ')';
  obj.changed.plain = obj.changed.plain.replace(/(\()( *)(.*?)( *)(\))/, '$2$1$3$5$4');
}
// keep the changed text selected
obj.changed.keepSel = true;
return;
}

//==========================================================
//This function adds or removes braces around the selected text
//==========================================================
function BracesHandler(obj) {

WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
  obj.changed = obj.selection;
}
else {
  obj.changed = obj.cursor;
}
if ( /{{(.*?)}}/i.test(obj.changed.plain) ) {
  obj.changed.plain = obj.changed.plain.replace(/{{(.*?)}}/gi, '$1');
}
// add the text formatting
else {
  obj.changed.plain = '{{' + obj.changed.plain + '}}';
  obj.changed.plain = obj.changed.plain.replace(/({{)( *)(.*?)( *)(}})/, '$2$1$3$5$4');
}
// keep the changed text selected
obj.changed.keepSel = true;
return;
}



//==========================================================
//This function adds or removes ref section
//==========================================================
function RefSectionHandler(obj) {
//select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
//focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line

WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}

// make your changes to the plain target text in obj.changed.plain

// add the text formatting
obj.changed.plain = '==References==\n {{reflist}}' + obj.changed.plain + '';
//  obj.changed.plain = obj.changed.plain.replace(/(&lt;div&gt;)( *)(.*?)( *)(&lt;\/div&gt;)/, '$2$1$3$5$4');

// keep the changed text selected
obj.changed.keepSel = true;

// return to WikEdEditButton() to apply changes
return;
}


//===============================
// End of Custom features
//===============================


// addPurge
$(function () {
var hist; var url;
if (!(hist = document.getElementById('ca-history') )) return;
if (!(url = hist.getElementsByTagName('a')[0] )) return;
if (!(url = url.href )) return;
mw.util.addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
'purge', 'ca-purge', 'Purge server cache for this page', '0');
});
//</nowiki>