Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 * @update-token [[File:pathoschild/templatescript.js]]
 */
// <nowiki>
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType: 'script', cache: true }).then(function() {
	/*********
	** Register scripts
	*********/
	pathoschild.TemplateScript.add([
		{ name: 'clean up', script: cleanup, accessKey: 'x', forNamespaces: 'page' }
	]);

	/*********
	** Define scripts
	*********/
	function cleanup(editor) {
		var headerbox = editor.forField('wpHeaderTextbox');
		var footerbox = editor.forField('wpFooterTextbox');
	
		// anything noincluded at the start or end of the edit box should be pushed into the header and footer respectively.
		if (editor.contains(/^<noinclude>/)) {
			var e = editor.get().indexOf('</noinclude>');
	
			// append to header a trimmed version of whatever is inside the leading noinclude
			header.append('\n' + editor.get().substr(11, e - 11).replace(/^\s+|\s+$/g, ''));
	
			// remove leading noinclude from editbox
			editor.set(editor.get().substr(e + 12));
		}
	
		if (editor.contains(/<\/noinclude>$/)) {
			var s = editor.get().lastIndexOf('<noinclude>');
	
			// prepend to footer a trimmed version of whatever is inside the trailing noinclude
			footer.prepend(editor.get().substr(s + 11, editor.get().length - s - 11 - 12).replace(/^\s+|\s+$/g, '') + '\n');
	
			// remove trailing noinclude from editbox
			editor.set(editor.get().substr(0, s));
		}
		
		editor
			// remove trailing spaces at the end of each line
			.replace(/ +\n/g, '\n')
		
			// remove trailing whitespace preceding a hard line break
			.replace(/ +<br *\/?>/g, '<br />')
		
			// remove trailing whitespace at the end of page text
			.replace(/\s+$/g, '')
		
			// remove trailing spaces at the end of refs
			.replace(/ +<\/ref>/g, '</ref>')
		
			// remove trailing spaces at the end of template calls
			.replace(/ +}}/g, '}}')
		
			// convert double-hyphen to mdash (avoiding breaking HTML comment syntax)
			.replace(/([^\!])--([^>])/g, '$1—$2')
		
			// remove spacing around mdash, but only if it has spaces on both sides
			// (we don't want to remove the trailing space from "...as follows:— ",
			// bearing in mind that the space will already be gone if at end of line).
			.replace(/ +— +/g, '—')
		
			// join words that are hyphenated across a line break
			// (but leave "|-" table syntax alone)
			.replace(/([^\|])-\n/g, '$1');
	
		// stuff to do only if the page doesn't contain a <poem> tag:
		if (editor.contains('<poem>')) {
			editor
				// lines that start with " should probably be new lines,
				// if the previous line ends in punctuation,
				// other than a comma or semicolon
				// and let's get rid of trailing space while we're at it
				.replace(/([^\n\w,;])\n\" */g, '$1\n\n"')
		
				// lines that end with " should probably precede a new line,
				// unless preceded by a comma,
				// or unless the new line starts with a lower-case letter;
				// and let's get rid of preceding space while we're at it
				.replace(/([^,])\ *\"\n([^a-z\n])/g, '$1"\n\n$2')
	
				// remove single line breaks; preserve multiple.
				// but not if there's a tag, template or table syntax either side of the line break
				.replace(/([^>}\|\n])\n([^:#\*<{\|\n])/g, '$1 $2')

				// collapse sequences of spaces into a single space
				.replace(/  +/g, ' ');
		}
		
		editor
			// dump spurious hard breaks at the end of paragraphs
			.replace(/<br *\/?>\n\n/g, '\n\n')
		
			// remove unwanted spaces around punctuation marks
			.replace(/ ([;:\?!,])/g, '$1')
		
			// unicodify
			.replace(/&mdash/g, '—')
			.replace(/&ndash/g, '–')
			.replace(/&quot;/g, '"')
		
			// straighten quotes and apostrophes.
			.replace(/[“”]/g, '"')
			.replace(/[‘’`]/g, '\'')
		
			//OCR fixes
			// convert i9 to 19, etc.
			.replace(/[il]([0-9])/g, '1$1')
		
			// "the", "them", "their", etcetera
			.replace(/tlie/g, 'the')
		
			// "U" -> "ll" when preceded by a lowercase letter.
			.replace(/([a-z])U/g, '$1ll')
		
			// replace "float center" with "block center"; original template name was misleading enough be warrant routinely fixing
			.replace(/\{\{float center/g, '{{block center')
			
			.replace(/<center>\s*([.\n]*?)\s*<\/center>/g, '{{center|$1}}');
	
		// temporary fix just for Portrait
		if (mw.config.get('wgTitle').indexOf('A Portrait of the Artist as a Young Man') !== -1)
			editor.replace(/\n\n\n/g, '\n\n');
	}
});
// </nowiki>

// <nowiki>
if(mw.toolbar) {
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/8/8b/Button_m-dash.png",
		"speedTip": "M-dash",
		"tagOpen": '—',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/8/8b/Button_n-dash.png",
		"speedTip": "N-dash",
		"tagOpen": '–',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/5/5e/Button API ɑ.png",
		"speedTip": "ae",
		"tagOpen": 'æ',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/5/5e/Button API ɑ.png",
		"speedTip": "AE",
		"tagOpen": 'Æ',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/1/1e/Button API œ.png",
		"speedTip": "oe",
		"tagOpen": 'œ',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/1/1e/Button API œ.png",
		"speedTip": "OE",
		"tagOpen": 'Œ',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/1/16/Ansi_0163.svg",
		"speedTip": "Pound",
		"tagOpen": '£',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/4/4e/Button_romain.png",
		"speedTip": "Small caps",
		"tagOpen": '{{sc|',
		"tagClose": '}}',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/f/f2/Button-br.png",
		"speedTip": "Break",
		"tagOpen": '<br />',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/c/cd/Button_poem.png",
		"speedTip": "Break & gap",
		"tagOpen": '<br />\n{{gap}}',
		"tagClose": '',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/0/0c/Hyphenated_word_start.svg",
		"speedTip": "hws ",
		"tagOpen": '{{hyphenated word start|',
		"tagClose": '|}}',
		"sampleText": ""
	});
	
	mw.toolbar.addButton({
		"imageFile": "//upload.wikimedia.org/wikipedia/commons/0/07/Hyphenated_word_end.svg",
		"speedTip": "hwe ",
		"tagOpen": '{{hyphenated word end|',
		"tagClose": '|}}',
		"sampleText": ""
	});
}
// </nowiki>