Uiser:Synoman Barris/common.js

Frae Wikipedia, the free beuk o knawledge

Tak tent: Efter hainin, ye micht hae tae bypass yer brouser's cache for tae see the chynges. Mozilla / Firefox / Safari: haud doun Shift while dabbin on Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: haud doun Ctrl while dabbin on Refresh, or press Ctrl-F5; Konqueror: juist dab on the Reload button, or press F5; Opera users micht hae tae haillie dicht thair cache in Tools→Preferences.

// Mark-Reverted, to know which revisions are already reverted!
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Suffusion_of_Yellow/mark-reverted.js&action=raw&ctype=text/javascript" );
// Lists new user names to wikiproject, for Vandal fighting
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:The Voidwalker/newUserPatrol.js&action=raw&ctype=text/javascript" );
// Lists article creations for set of users, useful in CU
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:The Voidwalker/createdArticles.js&action=raw&ctype=text/javascript" ); 

//UserInfo on all Userpages

mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:SMcCandlish/userinfo.js&action=raw&ctype=text/javascript');
//Remove Wikidata
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:DannyS712/RemoveWikiData.js&action=raw&ctype=text/javascript');
//AutoUndoGlobal
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:WhitePhosphorus/js/AutoUndoGlobal.js&action=raw&ctype=text/javascript');
//Accounts Created
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:DannyS712/AccountsCreated.js&action=raw&ctype=text/javascript');
// Section Remover
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:DannyS712/SectionRemover.js&action=raw&ctype=text/javascript" );
// Citation Identifier
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:SuperHamster/CiteUnseen.js&action=raw&ctype=text/javascript" );
// Recently Added Text
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Þjarkur/Highlight recently added text.js&action=raw&ctype=text/javascript" );
window.highlightRecentlyAddedTextSettings = {
  color: 'rgb(255, 165, 255)', // Slight Pink
  useInMainspace: true,
}

// [[File:Krinkle_Countervandalism.js]]
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Krinkle/Scripts/Countervandalism.js&action=raw&ctype=text/javascript');
$(document).ready( function () {
$('#firstHeading').after( $('.patrollink') );
} );
// rollback sum
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Nageh/rollbackSum.js&action=raw&ctype=text/javascript" );
//<nowiki>
/* Cat-a-lot - changes category of multiple files */
mw.loader.using(['jquery.ui', 'mediawiki.util'], function(){
	mw.loader.load('//commons.wikimedia.org/w/load.php?modules=ext.gadget.Cat-a-lot');
});
////////// Cat-a-lot user preferences //////////
window.catALotPrefs = {"watchlist":"preferences","minor":true,"editpages":true,"docleanup":false,"subcatcount":10};
////////////////////////////////////catALotEnd//
//</nowiki>
//MYContribs
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Mvolz/displayContributions.js&action=raw&ctype=text/javascript" );
//Edit war Checker
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Evad37/EditWarChecker.js&action=raw&ctype=text/javascript");
// install [[Wikipedia:User:PleaseStand/Comment highlighter]] tool
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:PleaseStand/highlight-comments.js&action=raw&ctype=text/javascript' );
// Six tab button
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:js/6tabs-vector.js&action=raw&ctype=text/javascript");
//Adds more menus such as tools and analytical options
mw.loader.load('https://meta.wikimedia.org/w/index.php?action=raw&ctype=text/javascript&title=MediaWiki:MoreMenu.import.js');
// My Subpages
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:PrimeHunter/My_subpages.js&action=raw&ctype=text/javascript" );
// by [[m:user:Hoo man]] <http://meta.wikimedia.org/wiki/User:Hoo_man/Scripts/Active_sysops>
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/active_sysops.js&action=raw&ctype=text/javascript');
if(typeof(activeSysopsConfig) == 'undefined') activeSysopsConfig = {};
activeSysopsConfig.markWikisActiveSysops = true;
activeSysopsConfig.markWikisActiveSysopsLessThan = 1;
//diff-permalink
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Enterprisey/diff-permalink.js&action=raw&ctype=text/javascript');
// Provides several useful functions for rollback (custom edit summary, mark as bot edits and mass revert)
// by [[m:user:Hoo man]] <http://meta.wikimedia.org/wiki/User:Hoo_man/Scripts/Smart_rollback>
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/smart_rollback.js&action=raw&ctype=text/javascript');
if(typeof(smartRollbackConfig) === 'undefined') smartRollbackConfig = {};
smartRollbackConfig.editSummaries = {};
smartRollbackConfig.editSummaries[0] = 'Revert; Vandalism';
smartRollbackConfig.editSummaries[1] = 'Test edits/Assume Good Faith';
smartRollbackConfig.editSummaries[2] = 'UNexplained addition/Removal of huge text';
smartRollbackConfig.editSummaries[3] = 'Link Spamming/Promotional Links/Self Published Links';
smartRollbackConfig.editSummaries[4] = 'Mass changes to the content without consensus/sources/references';

// Next page in selected category
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Danski454/cat-next.js&action=raw&ctype=text/javascript" );
// Article Quality
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:EpochFail/ArticleQuality.js&action=raw&ctype=text/javascript");
//Number of tags in Article
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Ugog Nizdast/displayNumberOfTags.js&action=raw&ctype=text/javascript");
//Last Editor Info
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Eizzen/LastEditor.js&action=raw&ctype=text/javascript");
//InspectChange
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Writ Keeper/Scripts/commonHistory.js&action=raw&ctype=text/javascript");
//Page Info
mw.loader.load('//www.mediawiki.org/w/index.php?title=XTools/ArticleInfo.js&action=raw&ctype=text/javascript');
//Deletion Finder
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Writ_Keeper/Scripts/deletionFinder.js&action=raw&ctype=text/javascript");
//FancyDIFF
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Enterprisey/fancy-diffs.js&action=raw&ctype=text/javascript");
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Xiplus/TwinkleGlobal.js&action=raw&ctype=text/javascript');
// Unreliable sources detector
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Headbomb/unreliable.js&action=raw&ctype=text/javascript");

//QuickNote

mw.loader.load("https://en.wikipedia.org/wiki/User:Awesome Aasim/quicknote.js?action=raw&ctype=text/javascript");
$.when(mw.loader.using(['mediawiki.util'], $.ready)).done( function() {
	mw.util.addPortletLink("p-tb", mw.config.get('wgArticlePath').replace('$1', "Project:AutoWikiBrowser/Script"), "JS Wiki Browser", "tb-awbscript", "Run Javascript Wiki Browser");
});

if (mw.config.get('wgCanonicalNamespace')+':'+mw.config.get('wgTitle') === 'Project:AutoWikiBrowser/Script' && mw.config.get('wgAction') == 'view')
	mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript');
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function() {

var config = mw.config.get([
	'debug',
	'wgAction',
	'wgArticleId',
	'wgCategories',
	'wgMonthNames',

	'wgNamespaceNumber',
	'wgPageName',
	'wgRelevantUserName'
]);

$( document ).ready( function () {
	if ( ( $( '#ca-addsection' ).length > 0 ||
		$.inArray( 'Non-talk pages that are automatically signed', config.wgCategories )  >= 0 ) &&
		config.wgAction === 'view' &&
		$.inArray( 'Pages that should not be manually archived', config.wgCategories ) === -1 ) {
		var OCAstate = mw.user.options.get( 'userjs-OCA-enabled', 'true' );
		var pageid = config.wgArticleId;
		var errorLog = { errorCount: 0 };
		new mw.Api().get( {
			action: 'query',
			prop: [ 'revisions', 'info' ],
			rvsection: 0,
			rvprop: 'content',
			pageids: pageid,
			indexpageids: 1,
			rawcontinue: ''
		} ).done( function ( response0 ) {
			var thisMonthNum, thisMonthFullName, monthNamesShort, thisMonthShortName, thisYear, archiveNum;
			
			var content0 = response0.query.pages[ pageid ].revisions[ 0 ][ '*' ];
 
			/* archiveme */// Find out if there is already an {{Archive me}} request, and if it is between 1-2 months old
			if ( config.wgNamespaceNumber === 3 ) {
				thisMonthNum = new Date().getMonth();
				thisMonthFullName = config.wgMonthNames[ thisMonthNum + 1 ];
				monthNamesShort = [ "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
				thisMonthShortName = monthNamesShort[ thisMonthNum + 1 ];
				thisYear = new Date().getFullYear();
				var nowOcto = parseInt( ( ( thisYear * 12 ) + thisMonthNum + 1 ), 10 );
				var archiveme = content0.match( /\{\{Archive ?me(\| *date *= *(January|February|March|April|May|June|July|August|September|October|November|December) ([\d]{4}))?\}\}/i );
				if ( archiveme === null || archiveme === undefined ) {
					errorLog.errorCount++;
					errorLog.archiveme = '{{Archiveme}} not found.';
				} else {
					/* Archive me found - how old is it? */
					var archivemeMonth = archiveme[ 2 ];
					var archivemeMonthNum = 0;
					if ( typeof archivemeMonth === 'number' ) {
						archivemeMonthNum = parseInt( archivemeMonth, 10 );
					} else {
						for ( var i in config.wgMonthNames ) {
							if ( archivemeMonth === config.wgMonthNames[ i ] ) {
								archivemeMonthNum = parseInt( i, 10 );
							} else if ( archivemeMonth === monthNamesShort[ i ] ) {
								archivemeMonthNum = parseInt( i, 10 );
							}
						}
					}
					var archivemeYear = parseInt( archiveme[ 3 ], 10 );
					var archivemeOcto = parseInt( ( ( archivemeYear * 12 ) + archivemeMonthNum ), 10 );
					var archivemeSafe = parseInt( ( nowOcto - 2 ), 10 );
					archiveme = archiveme[ 0 ];
				}
			}
 
			/* counter */// Get the counter value
			var counterRegEx = new RegExp( '\\| *counter *= *(\\d+)' );
			var counter = counterRegEx.exec( content0 );
			if ( counter === null || counter === undefined ) {
				counter = 1;
				errorLog.errorCount++;
				errorLog.counter = counter;
			} else {
				counter = counter[ 1 ];
				archiveNum = counter;
			}
 
			/* archiveName */// Get the archiveName value
			var archiveNameRegEx = /\| *archive *= *(.*\%\(counter\)d.*) *(-->)?/;
			var archiveName = archiveNameRegEx.exec( content0 );
			var rootBase = config.wgPageName
					.replace( /\/.*/g, '' )// Chop off the subpages
					.replace( /_/g, ' ' );// Replace underscores with spaces
			if ( archiveName === null || archiveName === undefined ) {
				archiveName = rootBase + '/Archive ' + counter;
				errorLog.errorCount++;
				errorLog.archiveName = archiveName;
			} else { 
				archiveName = archiveName[ 1 ]
					.replace( /\| *archive *= */, '' )
					.replace( /\%\(year\)d/g, thisYear )
					.replace( /\%\(month\)d/g, thisMonthNum )
					.replace( /\%\(monthname\)s/g, thisMonthFullName )
					.replace( /\%\(monthnameshort\)s/g, thisMonthShortName )
					.replace( /\%\(counter\)d/g, archiveNum );
				var archiveBase = archiveName
					.replace( /\/.*/, '' )// Chop off the subpages
					.replace( /_/g, ' ' );// Replace underscores with spaces
				var archiveSub = archiveName
					.replace( /_/g, ' ' )// Replace underscores with spaces
					.replace( archiveBase, '' );// Chop off the base pagename
				if ( archiveBase != rootBase ) {
					errorLog.errorCount++;
					errorLog.archiveName = 'Archive name mismatch:<br /><br />Found: ' + archiveName;
					errorLog.archiveName += '<br />Expected: ' + rootBase.replace( '_', ' ' ) + archiveSub + '<br /><br />';
				}
			}
 
			/* archivepagesize */// Get the size of the destination archive from the API
			new mw.Api().get( {
				action: 'query',
				prop: 'revisions',rvlimit: 1,
				rvprop: [ 'size', 'content' ],
				titles: archiveName,
				list: 'usercontribs',
				uclimit: 1,
				ucprop: 'timestamp',
				ucuser: ( ( config.wgRelevantUserName ) ?
					config.wgRelevantUserName : 'Example' ),
				rawcontinue: '',
			} ).done( function ( archivePageData ) {
				var archivePageSize = 0;
				if ( archivePageData.query.pages[ -1 ] === undefined ) {
					for ( var a in archivePageData.query.pages ) {
						archivePageSize = parseInt( archivePageData.query.pages[ a ].revisions[ 0 ].size, 10 );
						archiveName = archivePageData.query.pages[ a ].title;
					}
				} else {
					archivePageSize = -1;
					archiveName = archivePageData.query.pages[ archivePageSize ].title;
					errorLog.errorCount++;
					errorLog.archivePageSize = -1;
					errorLog.archiveName = '<a class="new" href="' +
						mw.util.getUrl( archiveName, { action: 'edit', redlink: '1' } ) +
						'" title="' + archiveName + '">' + archiveName + '</a>';
				}
 
				/* maxarchivesize */// Get the defined max archive size from template
				var maxArchiveSizeRegEx = new RegExp( '\\| *maxarchivesize *= *(\\d+K?)' );
				var maxArchiveSize = maxArchiveSizeRegEx.exec( content0 );
				if ( maxArchiveSize === null || maxArchiveSize[ 1 ] === undefined ) {
					maxArchiveSize = parseInt( 153600, 10 );
					errorLog.errorCount++;
					errorLog.maxArchiveSize = maxArchiveSize;
				} else if ( maxArchiveSize[ 1 ].slice( -1 ) === "K" && $.isNumeric( maxArchiveSize[ 1 ].slice( 0, maxArchiveSize[ 1 ].length-1 ) ) ) {
					maxArchiveSize = parseInt( maxArchiveSize[ 1 ].slice( 0, maxArchiveSize[ 1 ].length - 1 ), 10 ) * 1024;
				} else if ( $.isNumeric( maxArchiveSize[ 1 ].slice() ) ) {
					maxArchiveSize = parseInt( maxArchiveSize[ 1 ].slice(), 10 );
				}
 
				/* pslimit */// If maxArchiveSize is defined, and archivePageSize >= maxArchiveSize increment counter and redfine page name.
				if ( !errorLog.maxArchiveSize && archivePageSize >= maxArchiveSize ) {
					counter++;
					archiveName = archiveNameRegEx.exec( content0 );
					archiveName = archiveName[ 1 ]
						.replace( /\| *archive *= */, '' )
						.replace( /\%\(year\)d/g, thisYear )
						.replace( /\%\(month\)d/g, thisMonthNum )
						.replace( /\%\(monthname\)s/g, thisMonthFullName )
						.replace( /\%\(monthnameshort\)s/g, thisMonthShortName )
						.replace( /\%\(counter\)d/g, counter );
					var oldCounter = counterRegEx.exec( content0 );
					var newCounter = '|counter=1';
					if ( oldCounter !== null && oldCounter !== undefined ) {
						newCounter = oldCounter[ 0 ].replace( oldCounter[ 1 ], counter );
						oldCounter = oldCounter[ 0 ];
					} else {
						errorLog.errorCount++;
						errorLog.newCounter = newCounter;
					}
				}
 
				/* archiveheader */// Get the defined archive header to place on archive page if it doesn't exist
				var archiveHeaderRegEx = new RegExp( '\\| *archiveheader *= *(\{\{[^\r\n]*\}\})' );
				var archiveHeader = archiveHeaderRegEx.exec( content0 );
				if ( archiveHeader === null || archiveHeader === undefined ) {
					archiveHeader = "{{Aan}}";
					errorLog.errorCount++;
					errorLog.archiveHeader = archiveHeader;
				} else {
					archiveHeader = archiveHeader[ 1 ];
				}
 
				/* headerlevel */// Get the headerlevel value or default to '2'
				var headerLevelRegEx = new RegExp( '\\| *headerlevel *= *(\\d+)' );
				var headerLevel = headerLevelRegEx.exec( content0 );
				if ( headerLevel === null || headerLevel === undefined ) {
					headerLevel = 2;
					errorLog.errorCount++;
					errorLog.headerLevel = headerLevel;
				} else {
					headerLevel = parseInt( headerLevel[ 1 ] );
				}
 
				/* debug */// Table to report the values found.
				if ( config.debug === true ) {
					var OCAreport = '<table style="width: 100%;" border="1"><tr><th style="font-variant: small-caps; font-size: 20px;">config</th><th style="font-variant: small-caps; font-size: 20px;">value</th></tr>';
					OCAreport += '<tr><td>Counter</td><td style="text-align: center;';
					if ( errorLog.counter ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.counter; }
						else { OCAreport += '">' + counter; }
					OCAreport += '</td></tr><tr><td colspan="2" style="text-align: center;">Archive name</td></tr><tr><td colspan="2" style="text-align: center;';
					if ( errorLog.archiveName ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.archiveName; }
						else { OCAreport += '">' + archiveName; }
					OCAreport += '</td></tr><tr><td>Header Level</td><td style="text-align: center;';
					if ( errorLog.headerLevel ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.headerLevel; }
						else { OCAreport += '">' + headerLevel; }
					OCAreport +=  '</td></tr><tr><td>Archive header</td><td style="text-align: center;';
					if ( errorLog.archiveHeader ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.archiveHeader; }
						else { OCAreport += '">' + archiveHeader; }
					OCAreport +=  '</td></tr><tr><td>Max<br />archive size</td><td style="text-align: center;';
					if ( errorLog.maxArchiveSize ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.maxArchiveSize; }
						else { OCAreport += '">' + maxArchiveSize; }
					OCAreport +=  '</td></tr><tr><td>Current<br />archive size</td><td style="text-align: center;';
					if ( errorLog.archivePageSize ) { OCAreport += ' background-color: #FFEEEE;">' + archivePageSize; }
						else if ( archivePageSize >= maxArchiveSize ) { OCAreport += ' background-color: #FFEEEE;">' + archivePageSize; }
						else { OCAreport += '">' + archivePageSize; }
					if ( !errorLog.archiveme && archiveme !== undefined ) {
						OCAreport +=  '</td></tr><tr><td colspan="2" style="text-align: center;';
						if ( ( nowOcto - archivemeOcto ) <= 1 ) { OCAreport += '">Asked to archive '; }
						if ( ( nowOcto - archivemeOcto ) === 0 ) { OCAreport += 'this month'; }
						else if ( ( nowOcto - archivemeOcto ) === 1 ) { OCAreport += 'last month'; }
						else { OCAreport += ' background-color: #FFEEEE;">Asked to archive ' + ( nowOcto - archivemeOcto ) + ' months ago'; }
					}
					if ( errorLog.archiveme || archiveme !== undefined ) { OCAreport +=  '</td></tr><tr><td colspan="2" style="text-align: center;'; }
						if ( errorLog.archiveme ) { OCAreport +=  ' background-color: #FFEEEE;">' + errorLog.archiveme; }
						else if ( archiveme !== undefined ) { OCAreport += '">' + archiveme; }
					OCAreport +=  '</td></tr><tr><td colspan="2" style="font-size: larger; text-align: center;"><a href="/wiki/User:Technical_13/Scripts/OneClickArchiver" title="User:Technical 13/Scripts/OneClickArchiver">Documentation</a></td></tr></table>';
					mw.notify( $( OCAreport ), { title: 'OneClickArchiver report!', tag: 'OCA', autoHide: false } );
				}
 
				var OCAerror = '<p>The following errors detected:<br />';
				if ( errorLog.counter ) { OCAerror += '<b style="font-size: larger; color: #FF0000;">&bull;</b>&nbsp;Unable to find <b>|counter=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>1</b><br />'; }
				if ( errorLog.archiveName && errorLog.archiveName.search( 'defaulted to' ) !== -1 ) { OCAerror += '<b style="font-size: larger; color: #FF0000;">&bull;</b>&nbsp;Unable to find <b>|archive=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>' + archiveName + '</b><br />'; }
				if ( errorLog.archiveName && errorLog.archiveName.search( 'mismatch' ) !== -1 ) { OCAerror += '<b style="font-size: larger; color: #FF0000;">&bull;</b>&nbsp;Archive name mismatch detected.<br />'; }
				if ( errorLog.headerLevel ) { OCAerror += '&nbsp; Unable to find <b>|headerlevel=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>2</b><br />'; }
				if ( errorLog.archiveHeader ) { OCAerror += '&nbsp; Unable to find <b>|archiveheader=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>"{{Aan}}"</b><br />'; }
				if ( errorLog.maxArchiveSize ) { OCAerror += '&nbsp; Unable to find <b>|maxarchivesize=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>153600</b><br />'; }
				if ( errorLog.counter || errorLog.archiveName ) { OCAerror += '<br /><b style="font-size: larger; color: #FF0000;">&bull;</b>&nbsp;Causing the script to abort.<br />'; }
				OCAerror += '<br /><span style="font-size: larger;">Please, see <a href="/wiki/User:Technical_13/Scripts/OneClickArchiver" title="User:Technical 13/Scripts/OneClickArchiver">the documentation</a> for details.</span></p>';
				var archiverReport = mw.util.addPortletLink(
					'p-cactions',
					'#archiverNoLink',
					'|Archive',
					'pt-OCA-report',
					'Report for why there are no |Archive links on this page',
					null,
					null
				);
				$( archiverReport ).click( function ( e ) {
					e.preventDefault();
					mw.notify( $( OCAerror ), { title: 'OneClickArchiver errors!', tag: 'OCAerr', autoHide: false } );
				} );
 
				if ( config.wgNamespaceNumber === 3 && ( errorLog.counter || errorLog.archiveName ) &&
				config.debug === true && errorLog.archiveme )  {
					if ( confirm( 'Click [OK] to post {{Archiveme|{{SUBST:DATE}}}} to the top of the page and abort or\n\t[Cancel] to attempt running with default values.' ) === true ) {
						new mw.Api().postWithToken( 'edit', {
							action: 'edit',
							section: 0,
							pageid: pageid,
							text: '{{Archiveme|{{SUBST:DATE}}}}\n' + content0,
							summary: '{{[[Template:Archiveme|Archiveme]]}} posted with [[User:Evad37/OneClickArchiver|OneClickArchiver]].'
						} ).done( function () {
							alert( 'Request for user to set up archiving posted.' );
							location.reload();
						} );
					}
				} else if ( config.wgNamespaceNumber === 3 && archivemeOcto >= archivemeSafe ) {
 
					/* Archive me request was made, give the user a chance to comply */
 
				} else if ( config.wgNamespaceNumber === 3 && ( errorLog.counter || errorLog.archiveName ) && config.debug === true && confirm( '{{Archiveme}} found on the top of the page:\n\n\t Click [OK] abort or\n\t[Cancel] to attempt running with default values.' ) === true ) {
 
					/* User aborted script */
 
				} else {
					$( 'h' + headerLevel + ' span.mw-headline' ).each( function() {
						var sectionName = $( this ).text();
						var editSectionUrl = $( this ).parent().find('.mw-editsection a').not('.mw-editsection-visualeditor').first().attr( 'href' );
						var sectionReg = /&section=(.*)/;
						var sectionRaw = sectionReg.exec( editSectionUrl );
						if ( sectionRaw != null && sectionRaw[ 1 ].indexOf( 'T' ) < 0 ) {
							var sectionNumber = parseInt( sectionRaw[ 1 ] );
							if ( $( this ).parent().prop( 'tagName' ) === 'H' + headerLevel ) {
 
								$( this ).parent( 'h' + headerLevel ).append(
									' <div style="font-size: 0.6em; font-weight: bold; float: right;"> | <a id="' + sectionNumber +
									'" href="#archiverLink" class="archiverLink">' + 'Archive' + '</a></div>'
								);
								$(this).parent('h' + headerLevel).find('a.archiverLink').attr('title', 'Archive to: "'+archiveName+'"');
								$( this ).parent( 'h' + headerLevel ).find( 'a.archiverLink' ).click( function() {
 
									var mHeaders = '<span style="color: #444444;">Retrieving headers...</span>';
									var mSection = 'retrieving section content...';
									var mPosting = '<span style="color: #004400">Content retrieved,</span> performing edits...';
									var mPosted = '<span style="color: #008800">Archive appended...</span>';
									var mCleared = '<span style="color: #008800">Section cleared...</span>';
									var mReloading = '<span style="color: #000088">All done! </span><a href="#archiverLink" onClick="javascript:location.reload();" title="Reload page">Reloading</a>...';
 
									$( 'body' ).append( '<div class="overlay" style="background-color: #000000; opacity: 0.4; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 500;"></div>' );					
 
									$( 'body' ).prepend( '<div class="arcProg" style="font-weight: bold; box-shadow: 7px 7px 5px #000000; font-size: 0.9em; line-height: 1.5em; z-index: 501; opacity: 1; position: fixed; width: 50%; left: 25%; top: 30%; background: #F7F7F7; border: #222222 ridge 1px; padding: 20px;"></div>' );
 
									$( '.arcProg' ).append( '<div>' + mHeaders + '</div>' );
 
									$( '.arcProg' ).append( '<div>' + 'Archive name <span style="font-weight: normal; color: #003366;">' + archiveName + '</span> <span style="color: darkgreen;">found</span>, ' + mSection + ' (' + archivePageSize + 'b)</div>' );
									new mw.Api().get( {
										action: 'query',
										pageids: pageid,
										rvsection: sectionNumber,
										prop: [ 'revisions', 'info' ],
										rvprop: 'content',
										indexpageids: 1,
										rawcontinue: ''
									} ).done( function ( responseSection ) {
										var sectionContent = responseSection.query.pages[ pageid ].revisions[ 0 ][ '*' ];
										$( '.arcProg' ).append( '<div>' + mPosting + '</div>' );
 
										var dnau = sectionContent.match( /<!-- \[\[User:DoNotArchiveUntil\]\] ([\d]{2}):([\d]{2}), ([\d]{1,2}) (January|February|March|April|May|June|July|August|September|October|November|December) ([\d]{4}) \(UTC\) -->/ );
										var dnauDate;
										if ( dnau === null || dnau === undefined ) {
											dnauDate = Date.now();
											dnau = null;
										} else {
											dnau = dnau[ 1 ] + ':' + dnau[ 2 ] + ' ' + dnau[ 3 ] + ' ' + dnau[ 4 ] + ' ' + dnau[ 5 ];
											dnauDate = new Date( dnau );
											dnauDate = dnauDate.valueOf();
										}
 
										if ( dnauDate > Date.now() ) {
											$( '.arcProg' ).remove();
											$( '.overlay' ).remove();
											var dnauAbortMsg = '<p>This section has been marked \"Do Not Archive Until\" ' + dnau + ', so archiving was aborted.<br /><br /><span style="font-size: larger;">Please, see <a href="/wiki/User:Technical_13/Scripts/OneClickArchiver" title="User:Technical 13/Scripts/OneClickArchiver">the documentation</a> for details.</span></p>';
											mw.notify( $( dnauAbortMsg ), { title: 'OneClickArchiver aborted!', tag: 'OCAdnau', autoHide: false } );
										} else {
											var archiveAction = 'adding section';
											if ( archivePageSize <= 0 || ( archivePageSize >= maxArchiveSize && !errorLog.maxArchiveSize ) ) {
												sectionContent = archiveHeader + '\n\n' + sectionContent;
												archiveAction = 'creating';
												mPosted = '<span style="color: #008800">Archive created...</span>';
											} else {
												sectionContent = '\n\n{{Clear}}\n' + sectionContent;
											}
 
											if ( dnau != null ) {
												sectionContent = sectionContent.replace( /<!-- \[\[User:DoNotArchiveUntil\]\] ([\d]{2}):([\d]{2}), ([\d]{1,2}) (January|February|March|April|May|June|July|August|September|October|November|December) ([\d]{4}) \(UTC\) -->/g, '' );
											}
 
											new mw.Api().postWithToken( 'edit', {
												action: 'edit',
												title: archiveName,
												appendtext: sectionContent,
												summary: '/* '+sectionName+' */ archived using [[User:Evad37/OneClickArchiver|OneClickArchiver]])'
											} ).done( function () {
												$( '.arcProg' ).append( '<div class="archiverPosted">' + mPosted + '</div>' );
												new mw.Api().postWithToken( 'edit', {
													action: 'edit',
													section: sectionNumber,
													pageid: pageid,
													text: '',
													summary: '[[User:Evad37/OneClickArchiver|OneClickArchived]] "' + sectionName + '" to [[' + archiveName + ']]'
												} ).done( function () {
													$( '.arcProg' ).append( '<div class="archiverCleared">' + mCleared + '</div>' );
													if ( archivePageSize >= maxArchiveSize && !errorLog.maxArchiveSize ) {
														var mUpdated = '<span style="color: #008800">Counter updated...</span>';
														new mw.Api().postWithToken( 'edit', {
															action: 'edit',
															section: 0,
															pageid: pageid,
															text: content0.replace( oldCounter, newCounter ),
															summary: '[[User:Evad37/OneClickArchiver|OneClickArchiver]] updating counter.'
														} ).done( function () {
															$( '.arcProg' ).append( '<div class="archiverPosted">' + mUpdated + '</div>' );
															$( '.arcProg' ).append( '<div>' + mReloading + '</div>' );
															location.reload();
														} );
													} else {
														$( '.arcProg' ).append( '<div>' + mReloading + '</div>' );
														location.reload();
													}
												} );
											} );
										}
									} );
								} );
							}
						}
					} );
				}
			} );
		} );
		var linkTextD = '1CA is on', linkDescD = 'Disable OneClickArchiver';
		var linkTextE = '1CA is off', linkDescE = 'Enable OneClickArchiver';
		var linkText = linkTextD, linkDesc = linkDescD;
		if ( OCAstate === 'false' ) {
			linkText = linkTextE; linkDesc = linkDescE;
			$( 'div.archiverDiv, li#pt-OCA-report' ).css( 'display', 'none' );
		}
		var archiverToggle = mw.util.addPortletLink(
			'p-cactions',
			'#archiverLink',
			linkText,
			'pt-OCA',
			linkDesc,
			'o',
			null
		);
		$( archiverToggle ).click( function ( e ) {
			e.preventDefault();
			/* Toggle the archiveLinks */
			$( 'div.archiverDiv' ).css( 'display', function ( _i, val ) {
				return val === 'none' ? '' : 'none';
			});
			/* Toggle the toggle link */
			$( 'li#pt-OCA a' ).html( function ( _i, val ) {
				return val === linkTextD ? linkTextE : linkTextD;
			});
			/* Toggle the toggle description */
			$( 'li#pt-OCA a' ).attr( 'title', function ( _i, val ) {
				return val === linkDescD ? linkDescE : linkDescD;
			});
			/* Toggle the error report link */
			if ( ( errorLog.counter || errorLog.archiveName ) ) {
				$( 'li#pt-OCA-report' ).css( 'display', function ( _i, val ) {
					return val === 'none' ? '' : 'none';
				});
			}
			/* Toggle default state */
			new mw.Api().postWithToken( 'options', {
				action: 'options',
				optionname: 'userjs-OCA-enabled',
				optionvalue: OCAstate === 'true' ? 'false' : 'true'
			} ).done( function() {
				var resultMsg = 'OneClickArchiver is now ' + ( OCAstate === 'true' ? 'disabled' : 'enabled' ) + ' by default.';
				mw.notify(resultMsg);
				OCAstate = OCAstate === 'true' ? 'false' : 'true';
			} );
		} );
	}
} );

});
// </nowiki>
/*** Reference Expander ***/

// Expands references that are a link to a expanded reference using {{cite ..}}
// [[User:BrandonXLF/ReferenceExpander]]
// By [[User:BrandonXLF]]

$(mw.util.addPortletLink('p-tb', '#', 'Expand references')).click(function(e){
	e.preventDefault();
	var progress = new OO.ui.ProgressBarWidget({
		progress: false
	});
	var doing = $('<div style="margin:0.5em 0;font-weight:bold;">Initalizing...</div>');
	var logElement = $('<div style="font-family:monospace monospace;"></div>');
	function log (msg, color) {
		logElement.append($('<div>').text('> ' + msg).css({color: color || 'grey'}));
	}
	function ProcessDialog( config ) {
		ProcessDialog.super.call( this, config );
	}
	OO.inheritClass( ProcessDialog, OO.ui.ProcessDialog );
	ProcessDialog.static.name = 'citoidExpandRefs';
	ProcessDialog.static.title = 'Reference Expanders';
	ProcessDialog.static.actions = [{
		action: 'close',
		label: 'Close',
		flags: [ 'safe', 'close' ]
	}];
	ProcessDialog.prototype.initialize = function () {
		ProcessDialog.super.prototype.initialize.apply( this, arguments );
		this.content = new OO.ui.PanelLayout({
			padded: true,
			expanded: false
		});
		processDialog.content.$element.append(progress.$element, doing, logElement);
		this.$body.append( this.content.$element );
	};
	ProcessDialog.prototype.getActionProcess = function ( action ) {
		var dialog = this;
		return new OO.ui.Process( function () {
			dialog.close();
		});
	};
	ProcessDialog.prototype.getBodyHeight = function () {
		return this.content.$element.outerHeight( true );
	};
	var windowManager = new OO.ui.WindowManager();
	$( document.body ).append( windowManager.$element );
	var processDialog = new ProcessDialog({
		size: 'large'
	});
	windowManager.addWindows( [ processDialog ] );
	windowManager.openWindow( processDialog );
	log('Loading page content and scripts...');
	mw.loader.getScript('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/Citoid.js&action=raw&ctype=text/javascript').then(function(){
		new mw.Api().edit(mw.config.get('wgPageName'),function(rev){
			var def = $.Deferred();
			var refs = rev.content.match(/<ref.*?>.*?<\/ref>/g);
			var done = 0;
			progress.setProgress(0);
			doing.text('Expanding references...');
			function afterRef (msg, color) {
				done++;
				log(msg,color);
				progress.setProgress(done/refs.length*100);
				processDialog.updateSize();
				if (done >= refs.length) {
					progress.setProgress(false);
					doing.text('Saving...');
					log('Saving changes to ' + mw.config.get('wgPageName') + '...');
					processDialog.updateSize();
					var pos = 0;
					def.resolve({
						text: rev.content.replace(/<ref.*?>.*?<\/ref>/g, function(){
							return refs[pos++];
						}),
						summary: 'Expanding bare references using [[User:BrandonXLF/ReferenceExpander|ReferenceExpander]]'
					});
				}
			}
			function doRef (i) {
				if (refs[i].match(/<ref.*?> *{{/)) {
					afterRef('Skipping already expanded reference.');
					return;
				}
				var parts = refs[i].match(/(<ref.*?>)(.*?)(<\/ref>)/);
				parts[2] = parts[2].match(/\[?([^ \]]*)*\]?/)[1];
				getCitoidRef(parts[2]).then(function(ref){
					refs[i] = parts[1] + ref + parts[3];
					afterRef('Expanded reference to "' + parts[2].trim() + '".', 'green');
				},function(err){
					afterRef('Error expanding reference to "' + parts[2].trim() + '".', 'red');
				});
			}
			if (refs) {
				for (var i = 0; i < refs.length; i++) doRef(i);
			} else {
				log('No references found on the page.');
				def.resolve({
					text: rev.content
				});
			}
			return def.promise();
		}).then(function(){
			progress.setProgress(100);
			doing.text('Edit saved!');
			log('Edit saved. Reloading...');
			window.location.reload();
		});
	});
});
/*** Autoref ***/

// Insert auto-filled references in the 2010 Wikitext editor like you can in VE
// Documentation at [[User:BrandonXLF/Autoref]]
// By [[User:BrandonXLF]]

$.when( mw.loader.using('ext.wikiEditor'), mw.loader.getScript('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/Citoid.js&action=raw&ctype=text/javascript'), $.ready).then(function(){
	$('#wikiEditor-section-main [rel="reference"] > a').unbind().click(function(){
		var pos = {
			start: $( '#wpTextbox1' ).textSelection( 'getCaretPosition' ),
			end: $( '#wpTextbox1' ).textSelection( 'getCaretPosition' ) + $( '#wpTextbox1' ).textSelection( 'getSelection' ).length
		};
		OO.ui.prompt($('<span>Enter a <abbr title="URL, DOI, ISBN, PMID, PMCID, or QID">source</abbr>:</span>'), {
			textInput: {
				placeholder: 'Leave blank for none'
			}
		}).done(function(source){
			$( '#wpTextbox1' ).textSelection( 'setSelection', pos );
			if (source === null) {
				return;
			}
			if (source === '') {
				$( '#wpTextbox1' ).textSelection( 'encapsulateSelection', { pre: '<ref>', post: '</ref>' } );
				return;
			}
			getCitoidRef(source).then(function(ref){
				$( '#wpTextbox1' ).textSelection( 'replaceSelection', '<ref>' + ref + '</ref>');
			},function(err){
				mw.notify(err, {type: 'error'});
			});
		});
	});
});
/**
 * 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]]
 */
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js');

function Ohc_format_Sundry() {
 var    txt=document.editform.wpTextbox1;

//html, superscripted ordinals 
	regex(/\[\[[\w]*_\d{4}#\d{4}_[\w]*_\d\d?\|(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))( \d\d?)\]\]/g, '$1$2');
//	regex(/<br>/gi, '<br/>');
	regex(/(\d)(<sup>)(m)(\d<\/sup>)/gi, '$1$3$2$4'); //misplaced unit (squared)il

//rem linking within section headings
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[([^\|\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[[^\|\]]+?\|([^\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\](?:([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]|)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3$4$5$6$7');
//	regex(/(==[ ]?)\d{1,2}px([^\|\]]+?)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3'); //rem artefact after removing file from title

//rem refs within section headings
	regex(/(==[ ]?(?:[^<>\n]*))(?:<ref(?:>[^<>]*<\/ref| name=[^\/>]+\/)>)([^<>\n]*)(?=[ ]?==)/gi, '$1$2');

//rem empty parameters
//	regex(/\|[\n]*[ ]*[a-zA-Z][a-z0-9_ ]*=[ ]*[\n]?[ ]*(?=[\|\}])/g, "");

//rem deprecated parameters 
//	regex(/\|\s*influence[sd]\s*=[^\|\{\}]*(?=[\|\}])/g, ""); //rfc infobox person July 2013;	code fails if there are piped links
	regex(/({{(?:end|start)[-–]date)\|df=y(?:es|)/gi, "$1"); //rem deprecated parameter
	regex(/({{(?:end|start)[-–]date(?:[^\{\}]*))\|df=y(?:es|)(}})/gi, "$1$2"); //rem deprecated parameter

//add correct hyphenation
	regex(/\b([2-9]|\d{2,3}|half|quarter|two|three|four|five|six|seven|eight|nine|ten) (second|minute|hour|day|week|month|year|decade|fold|liter|litre|degree|pound|inch|foot|yard|mile|(?:kilo|)met(?:re|er)|man|page|point|word|dollar|cent|floor|store?y|(?:bed|)room)\b/g, "$1-$2");
	regex(/\b([2-9]|\d{2,3}|two|three|four|five|six|seven|eight|nine|ten)-(second[- ]class)\b/g, "$1 $2"); //palliative to reverse incorrectly inserted hyphen "n-second-class"
	regex(/\b(two|three|four|five|six|seven|eight|nine|ten) (halves|thirds|quarters|(?:four|fif|six|seven|eigh|nin|ten)ths)\b/gi, "$1-$2");
	regex(/\b((?:[2-9]|\d{2,3})-(?:month|year)) (old)\b/gi, "$1-$2");
	regex(/(\bnon) ([A-Z]?[a-z]+)/g, "$1-$2");
	regex(/(\bnon)-(grata)/g, "$1 $2"); //reinstate for "persona non grata"
	regex(/(qua non)-([A-Z])/gi, "$1 $2"); //reinstate for "sine qua non"
	regex(/([Bb]etween \d{4})\s?[‐‒–—―]\s?(\d{4})/g, "$1 and $2"); //ungrammatical constructs involving year ranges"
	regex(/([Bb]etween (\d{2})\d{2})\s?[‐‒–—―]\s?(\d{2})/g, "$1 and $2$3"); //ungrammatical constructs involving year ranges"
	regex(/([Ff]rom \d{4})\s?[‐‒–—―]\s?(\d{4})/g, "$1 to $2"); //ungrammatical constructs involving year ranges"
	regex(/([Ff]rom (\d{2})\d{2})\s?[‐‒–—―]\s?(\d{2})/g, "$1 to $2$3"); //ungrammatical constructs involving year ranges"

	regex(/(?:\| ?date= ?)(Cric\w{4,})(?=[|}])/gi, "|publisher=$1");
//	regex(/{{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}/gi, "$1$2");
//	regex(/{{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}/gi, "$1");
//	regex(/(\|\s*(?:\w+_|)colou?rs\s*=\s*[^{]*){{color ?sample\s?\|#?\w+}}([^{|]*)(?=\n?[|{}])/gi, "$1$2");

}
 
function Ohc_format_MOSCAPS(){
//WP:AMPERSAND
	regex(/(==[ ]*[^=&\n]* )&( [^=&\n]*)(?=[ ]*=)/g, '$1and$2');
	
//improper capitalisation within section headings
	regex(/(==[ ]*External )(Links)(?=[ ]*=)/g, '$1links');
	regex(/(==[ ]*See )(Also)(?=[ ]*=)/g, '$1also');
	regex(/(==[ ]*)Notable Alumnae/g, '$1Alumni');
	regex(/(==[ ]*)Notable ([A-Z]\w*?)/g, '$1$2');
	regex(/(==[ ]*Box )O(ffice)(?=[ ]*=)/g, '$1o$2');
	regex(/(==[ ]*[\w]+? and )A(wards?|chievements?)(?=[ ]*=)/g, '$1a$2');
	regex(/(==[ ]*[\w\s]+? )A(lbums?)(?=[ ]*=)/g, '$1a$2');
	regex(/(==[ ]*[\w\s]+? )C(areer|haracters|hart|ompetitions?|ompositions|redits)(?=[ ]*=)/g, '$1c$2');
	regex(/(==[ ]*[\w\s]+? )(Capped [Pp]layers)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*[A-Z]\w+ )((?:[A-Z]\w+ |and |)Destinations?)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*[\w\s]+? )E(ducation)(?=[ ]*=)/g, '$1e$2');
	regex(/(==[ ]*[\w\s]+? )F(acilities|ilms?)(?=[ ]*=)/g, '$1f$2');
//	regex(/(==[ ]*[\w\s]+? )G(roups?)(?=[ ]*=)/g, '$1g$2');
	regex(/(==[ ]*[\w\s]+? )L(evels?|ife|istings?)(?=[ ]*=)/g, '$1l$2');
	regex(/(==[ ]*[\w\s]+? )M(ember(?:ship|s?))(?=[ ]*=)/g, '$1m$2');
	regex(/(==[ ]*[\w\s]+? )P(oll(?:ing|s?))(?=[ ]*=)/g, '$1p$2');
	regex(/(==[ ]*[\w\s]+? )R(ankings?|eading|esults?|ecords?|eception|ecognition)(?=[ ]*=)/g, '$1r$2');
	regex(/(==[^=\n]+) +S((?:chedule|creenings?|ummary) ?==)/gi, '$1 s$2');
	regex(/(==[ ]*[\w\s]+? )T(ables?|ournaments|ransport(?:ations?|))(?=[ ]*=)/gi, '$1t$2');
	regex(/(==[ ]*[\w\s]+? )W(inners)(?=[ ]*=)/g, '$1w$2');
	regex(/(==[ ]*[\w\s]+? )Y(ears)(?=[ ]*=)/g, '$1y$2');
 
	regex(/(==[ ]*Performance )(By \w+)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Extra )(Preliminary Round)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Extended )(Playing Squad)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Wider )(Training [Gg]roup)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Regular )(Season [Ss]chedule)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Right )([Oo]f Reply)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Twin )(Towns(?: [Aa]nd [Ss]ister [Cc]ities|))(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*Heraldic )(Items)(?=[ ]*=)/g, '$1items');
	regex(/(==[ ]*Campaign )C(redits)(?=[ ]*=)/g, '$1c$2');
	regex(/(==[ ]*Combat )C(hronicle)(?=[ ]*=)/g, '$1c$2');
	regex(/(==[ ]*[\w\s]+? )(International Trips)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	
	regex(/(\|\s*(?:\w+_|)colou?rs\s*=\s*[A-Z])([\w ,&]+)(?=[\n|}])/gi, '$1{{' + 'subst:' + 'lc:$2}}'); //downcase colours in infobox
 
	regex(/(==\w+) M(atch(?:es|))\b/gi, '$1 m$2');
	regex(/(==\w+)[-–\s]B(acks?)\b/gi, '$1-b$2');
	regex(/(==\w+)[-–\s]E(ight)/gi, '$1-e$2');
	regex(/(==(?:Top|Bottom))[-–\s]H(alf)\b/gi, '$1 h$2');
	regex(/(==(?:Scrum|Fly))[-–\s]H(alf|alves)\b/gi, '$1-h$2');
	regex(/(==\w+)[-–\s]Q(uarters?)\b/gi, '$1-q$2');

// within links and pipes
	regex(/((?:'''|\|)(?:[Hh]alf|[Ff]ull))[-–\s]B(acks?(?:'''|\]\]))/gi, '$1 b$2');
	regex(/((?:'''|\|)\w+)[-–\s]F(orwards?(?:'''|\]\]))/gi, '$1 f$2');
	regex(/((?:'''|\|)(?:[Oo]ne|[Tt]hree|[Ff]our||[Ff]ive))[-–\s]E(ights?(?:'''|\]\]))/gi, '$1-e$2');
	regex(/((?:'''|\|)\w+)[-–\s]H((?:alf|alves)(?:'''|\]\]))/gi, '$1-h$2');
	regex(/((?:'''|\|)(?:[Oo]ne|[Tt]hree|[Ff]our))[-–\s]Q(uarters?(?:'''|\]\]))/gi, '$1-q$2');
	regex(/((?:'''|\|) ?Player )(One|Two|Three|Four)/gi, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/((?:'''|\|)Population)[\s]D(ensity(?:'''|\s?\|))/gi, '$1 d$2');
	regex(/((?:'''|\|)Population)[\s]P(rojection(?: \w+|)(?:'''|\s?\|))/gi, '$1 p$2');

	regex(/([^\n]*\[\[)(One Country, Two Systems)(?=[|\]])/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/((?:[^\n]*|[^\.]\s)\[\[)(Exclusive Economic Zone)(?=[|\]])/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(\[\[(?:\d{3,4} |)(?:[A-Z][a-z]+ )(?:[A-Z][a-z]+ )*)(Conspiracy|Controversy|(?:Race |)Riot|Massacre|Murder|Protest|Uprising)(?=s?(?: of \d{3,4}|)\]| \(\d{3,4}\))/g, '$1{{' + 'subst:' + 'lc:$2}}'); //per Frietjes: you cannot use subst: inside of references

//improper capitalisation within infobox strings
	regex(/(, |\band )A(cademic|ctor|ctress|ctivist|nimator|rranger|rtist|rt critic|strologer|thlete|uthor)(?= ?[\n,<|])/g, '$1a$2');
	regex(/(, |\band )B(allet|iography|roadcaster|usiness(?:wo|)man)(?= ?[\n,<|])/g, '$1b$2');
	regex(/(, |\band )C(hef|olumnist|o-\w+|omedian|omposer|onsultant|ritic|urator)(?= ?[\n,<|])/g, '$1c$2');
	regex(/(, |\band )D(entist|esigner|j|irector|is[ck] jockey|ocumentary maker|ramatist)(?= ?[\n,<|])/g, '$1d$2');
	regex(/(, |\band )E(ditor|ditor[ -]in[ -]chief|ducator|ngineer|ntertainer|ntrepreneur|nvironmentalist|ssayist|xecutive producer|xplorer)(?= ?[\n,<|])/g, '$1e$2');
	regex(/(, |\band )F(ashion (?:designer|model)|iction|ilm(?: critic|director|[- ]?maker|producer))(?= ?[\n,<|])/g, '$1f$2');
	regex(/(, |\band )G(raphic designer)(?= ?[\n,<|])/g, '$1g$2');
	regex(/(, |\band )H(acker|istorian|istorical fiction)(?= ?[\n,<|])/g, '$1h$2');
	regex(/(, |\band )J(ournalist)(?= ?[\n,<|])/g, '$1j$2');
	regex(/(, |\band )L(awyer|eader|ecturer|ibrarian|iterary editor|yricist)(?= ?[\n,<|])/g, '$1l$2');
	regex(/(, |\band )M(ayor|athematician|odel|usician|ulti-instrumentalist)(?= ?[\n,<|])/g, '$1m$2');
	regex(/(, |\band )M(usic (?:arranger|composer|critic|director|producer))(?= ?[\n,<|])/g, '$1m$2');
	regex(/(, |\band )N(arrator|ovelist)(?= ?[\n,<|])/g, '$1n$2');
	regex(/(, |\band )O(rator)(?= ?[\n,<|])/g, '$1o$2');
	regex(/(, |\band )P(erformance artist|erformer|hilosopher|hilosophy|hotographer|laywright|oet|oetry|olitical activist|olitician|laywright|riest|resenter|roducer|rofessor|olitical commentator|ublic speaker|ublicist|ublisher|undit)(?= ?[\n,<|])/g, '$1p$2');
	regex(/(, |\band )R(ecord producer|eporter)(?= ?[\n,<|])/g, '$1r$2');
	regex(/(, |\band )S(ailor|cholar|cientist|creenwriter|culptor|oldier|olicitor|inger.songwriter|ong-?writer|peaker|tockbroker)(?= ?[\n,<|])/g, '$1s$2');
	regex(/(, |\band )S(tand[- ]?up) C(omed(?:ian|))(?= ?[\n,<|])/g, '$1s$2 c$3');
	regex(/(, |\band )T(eacher|elevision|heatr(?:e|ical) (?:critic|director|producer)|ranslator)(?= ?[\n,<|])/g, '$1t$2');
	regex(/(, |\band )V(oice actor)(?= ?[\n,<|])/g, '$1v$2');
	regex(/(, |\band )W(riter)(?= ?[\n,<|])/g, '$1w$2');

//rem inappropriate
	regex(/((?:occupation|profession)[ ]*=[^\n]*)(?:, (?:activ|philanthrop)ist|Member of Parliament)(?=[^\n]*\n[ ]*\|)/gi, '$1');
//	regex(/((?:occupation|profession)[ ]*=[ ]*)(?:\[\[Dewan Rakyat\|Member of Parliament\]\])(?=[^\n]*\n[ ]*\|)/gi, '$1Politican');
	regex(/((?:occupation|profession)[ ]*=[ ]*)(?:(?:\[\[[^|\]]+\||)Member of Parliament\]\])(?=[^\n]*\n[ ]*\|)/gi, '$1Politican');
	regex(/((?:instrument|occupation|products|profession)[ ]*=[ ]*[A-Z]+)([a-z]+[^=|}]+)(?=\n[ ]*\|)/gi, '$1{{' + 'subst:' + 'lc:$2}}'); //to genericise downcasing of occupations and musical instruments

//other improper capitalisation -sports
	regex(/((?:==?|\||\()[ ]*[\w\s]+? )H(eld|istory|onou?rs)(?=[ ]*=)/g, '$1h$2');
	regex(/((?:==?|\||\()[ ]*(?:1st|2nd|3rd|\dth) )M(atch)/g, '$1m$2');
	regex(/((?:==?|\||\()[ ]*(?:1st|2nd|3rd|\dth) )F(inal)/g, '$1f$2');
	regex(/((?:==?|\||\()[ ]*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )Q(uarter)/g, '$1q$2');
	regex(/((?:==?|\||\()[ ]*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )R(ound)/g, '$1r$2');
    regex(/(\W[a-z]+ )[Qq](uarter)[\- ]F(inal)/g, '$1q$2-f$3');
    regex(/((?:==?|\||\()[ ]*[Qq]uarter|[Ss]emi)[\- ]?F(inal)/gi, '$1-f$2');
    regex(/(\W[a-z]+ )[Ss](emi)[\- ]F(inal)/g, '$1s$2-f$3');
	regex(/(==[ ]*Overall )(Team [Rr]ecords?)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*(?:CFL|N[BFH]L) )C(oaching )[Rr](ecords?)(?=[ ]*=)/g, '$1c$2r$3');
	regex(/(==[ ]*[-\w\s]+? )C(areer )S(tatistics)(?=[ ]*=)/g, '$1{{' + 'subst:' + 'lc:$2}}');
	regex(/(==[ ]*[\w\s]+? (?:and |& |))S(eason|quad|tyle|taff|tage|tatistics)(?=[ ]*=)/g, '$1s$2');
    regex(/\b(Bowling |Batting )S(tyle)\b/g, '$1s$2');
	regex(/\b([Rr]ight|[Lr]eft)-([Hh]anded(?: (?:Opening|Top [Oo]rder) Batsman|))\b/gi, '$1-{{' + 'subst:' + 'lc:$2}}');
    regex(/\b([Aa]ll)[- ]R(ounder)\b/gi, '$1-r$2');
    regex(/\b(Wicket)[- ]K(eeper)\b/gi, '$1-k$2');
    regex(/([Rr]ight|[Lr]eft)[- ]([Aa]rm (?:\[\[(?:[^|\[\]]+\||))(?:[Oo]rthodox|(?:[Ll]eg|[Oo]ff)[- ][Ss]pin|[Mm]edium(?: [Ff]ast|)|[Ff]ast(?: [Mm]edium|))\]\])/g, '$1-{{' + 'subst:' + 'lc:$2}}');
    regex(/((?:\[\[[^|\[\]]+\|)(?:[Rr]ight|[Lr]eft))[- ]([Aa]rm (?:[Oo]rthodox|(?:[Ll]eg|[Oo]ff)[- ][Ss]pin|[Mm]edium(?: [Ff]ast|)|[Ff]ast(?: [Mm]edium|))\]\])/g, '$1-{{' + 'subst:' + 'lc:$2}}');
    regex(/\b(Fast)[-– ]([Mm]edium [Bb]owler)\b/g, '$1–{{' + 'subst:' + 'lc:$2}}');
    regex(/\b([Ff]ast |[Mm]edium )B(owler)\b/g, '$1b$2');
    regex(/\b([Ff]ast|[Ss]low)[-– ]((?:lef|righ)t-[Aa]rm [Bb]owler)\b/g, '$1 {{' + 'subst:' + 'lc:$2}}');
    regex(/\b(fast)[- ]B(owler)\b/g, '$1-b$2');
    regex(/\b([Ll]eg|[Oo]ff)[- ]([Ss](?:pin )(?:Bowler|))\b/g, '$1-{{' + 'subst:' + 'lc:$2}}');
    
	regex(/(== ?\w )(League Table)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Contract) +(Detail|Length)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/((?:\||==)\s*Current) +(Club|Line-?up|Roster|Team)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Points|Pts) +(Ag(?:ain|)st|Diff(?:erence|)|For)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(== ?Top) +(scorers(?: in Order of League Goals|))/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(== ?Touring )P(arty)/g, '$1p$2');
	regex(/((?:==|[|!])\s*(?:\d+ Season |Current |Former ))P(layers)/g, '$1p$2');
	regex(/(== ?\d+ Gains & )L(osses)/g, '$1l$2');
	regex(/(== ?\d+ Signings & )T(ransfers)/g, '$1t$2');
	regex(/(== ?\w+) +(Results & Fixtures)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(== ?\w+) +(and Capacity)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(== ?Accidents[^=]+)I(ncidents)/g, '$1i$2');
	regex(/(Airport) +(Name|Code)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Bonus )P(oints|ts)/g, '$1p$2');
	regex(/(Broadcast )D(ates?)/g, '$1d$2');
	regex(/(Busiest) +((?:International |Domestic |) *(?:Flight|Routes(?: Out [Oo]f|)))/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(City ) ?S(erved)/g, '$1s$2');
	regex(/(br(?: ?\/|)>|Aircraft |Passenger |[Ff]reight )M(ovement)/gi, '$1m$2');
	regex(/(br(?: ?\/|)>|Total |Domestic |International )P(assenger)/g, '$1p$2');
	regex(/(Date (?:and|&) )T(ime)/gi, '$1t$2');
	regex(/(\|\s*(?:Date|Years?)) ((?:[Oo]f |)[A-Z]\w+)/g, '$1 {{' + 'subst:' + 'lc:$2}}'); //piping added to exclude false positive: "10 Years Younger"
	regex(/(\|+\s*)Hall \d[\.,] ?/g, '$1'); //rem over-specific location of match
	regex(/(Did) +([Nn]ot (?:[Ee]nter|[Pp]articipate|[Qq]ualify))/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(: Estimated [Vv]otes by) +EU P(arty)/gi, '{{' + 'subst:' + 'lc:$1}}EU party');
	regex(/(First|Second|Third|(?:Four|Fif|Six|Seven|Eigh|Nin|Ten|\d)th) +(Places?(?: Match|))/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Group )S(tage)/gi, '$1s$2');
	regex(/(Seasonal )C(harter)/g, '$1c$2');
	regex(/(Term )((?:[Oo]f |)[A-Z]\w+)/g, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Top )C(arrier)/g, '$1c$2');
	regex(/(Winter |Summer ) ?S(easonal)/g, '$1s$2');
	regex(/(Until the )E(nd of)/gi, '$1e$2');
	regex(/(Former |Last |New |Previous )C(lub)/gi, '$1c$2');
	regex(/(Years |When )S(igned)/gi, '$1s$2');
	regex(/(Match )I(nformation)/gi, '$1i$2');
	regex(/(\|\s*\w+ )S(taff\b)(?=\s?\w)/gi, '$1s$2'); //bug fix
	regex(/N(ational Distribution of Seats)/gi, 'N{{' + 'subst:' + 'lc:$1}}');
	regex(/([-–]\s?Won (?:Gold|Silver|Bronze) Medal)/gi, '{{' + 'subst:' + 'lc:$1}}');

	regex(/(Tour|Test|International) +M(atch)/gi, '$1 m$2');
	regex(/(Oppo)(?:sing [Tt]eam)/g, '$1nent');
	regex(/(by )O(pponent)/g, '$1o$2');
	regex(/(Tournaments(?:<br>| ))(Met)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(W&ndash;L(?:<br>| ))(Record)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Largest(?:<br>| ))(Victory|Defeat)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');
	regex(/(Current(?:<br>| ))(Streak)/gi, '$1 {{' + 'subst:' + 'lc:$2}}');

	regex(/\b(st|nd|rd|th) G(rade)\b/g, '$1 g$2');
//	regex(/(Official )S(ite)/g, '$1s$2');
//	regex(/([A-Z][a-z]+ )O(fficial )W(ebsite\])/g, '$1o$2w$3');
	regex(/(\'Further )R(eading)(?=\')/g, '$1r$2');

        regex(/([a-z] )A(nd|t) A(n? \w)/g, '$1a$2 a$3');
        regex(/([a-z] )A(nd|t) (My \w)/g, '$1a$2 $3');
        regex(/([a-z] )A(nd|t) T(he \w)/g, '$1a$2 t$3');
        regex(/([a-z] )By A(n? \w)/g, '$1by a$2');
        regex(/([a-z] )By (My \w)/g, '$1by $2');
        regex(/([a-z] )By T(he \w)/g, '$1by t$2');
        regex(/([a-z] )For A(n? \w)/g, '$1for a$2');
        regex(/([a-z] )For (My \w)/g, '$1for $2');
        regex(/([a-z] )For T(he \w)/g, '$1for t$2');
        regex(/([a-z] )In A(n? \w)/g, '$1in a$2');
        regex(/([a-z] )In (My \w)/g, '$1in $2');
        regex(/([a-z] )In T((?:he|o) \w)/g, '$1in t$2');
        regex(/([a-z] )I(nto \w)/g, '$1i$2');
        regex(/([a-z] )O(f|n|r) A(n? \w)/g, '$1o$2 a$3');
        regex(/([a-z] )O(f|n|r) (My \w)/g, '$1o$2 $3');
        regex(/([a-z] )O(f|n|r) T(he \w)/g, '$1o$2 t$3');
        regex(/([a-z] )To A(n? \w)/g, '$1to a$2');
        regex(/([a-z] )To (My \w)/g, '$1to m$2');
        regex(/([a-z] )To T(he \w)/g, '$1to t$2');
        regex(/([a-z] )With A(n? \w)/g, '$1with a$2');
        regex(/([a-z] )With M(y \w)/g, '$1with M$2');
        regex(/([a-z] )With T(he \w)/g, '$1with t$2');

        regex(/([a-z] )A(t \w)/g, '$1a$2');
        regex(/([a-z] )I(n \w)/g, '$1i$2');

        regex(/([Rr]unners?)[\- ]U(p\b)/g, '$1-u$2');
        regex(/([Rr]unner)[\- ][Uu](?:ps)\b/g, '$1s-up');
        regex(/([Pp]lay)[\- ][Oo](ffs?)/g, '$1-o$2');

        regex(/(\b\d{4})-P(resent\b)/gi, '$1–p$2');
        regex(/(\b\d{4}) - P(resent\b)/gi, '$1 – p$2');
        regex(/(\b\d{4}(?:–| – ))P(resent\b)/g, '$1p$2');
 
        regex(/(Bring |Turn )[Ii]t o(n)/g, '$1It O$2');   //reverting proper name - title of song or work
        regex(/(Carry )o(n [A-Z]\w*|n film)/g, '$1O$2');   //reverting proper name - 'Carry On' film series
        regex(/(\bMa )o(n Shan\b)/g, '$1O$2');   //reverting proper name - 'Ma On Shan'
        regex(/(NZ |New Zealand )o(n Air|n Screen)/g, '$1O$2');   //reverting proper name - 'NZ On Air'
        regex(/(\w (?:\[\[|))O(ff-Broadway\b)/g, '$1O$2');   //not a proper noundowncase 
        regex(/in t(he [Aa]ir [Tt]onight)/g, 'In t$1');   //reverting per "In the Air Tonight"
        regex(/in t(he Flesh [Tt]our)/g, 'In t$1');   //reverting per "In the Flesh tour"
        regex(/(\W)o(n This Day)/g, '$1O$2');   //reverting per "on This Day"
        regex(/({NYT )o(n this day)/g, '$1O$2');   //reverting per "on This Day"
        regex(/(\bWing )o(n\s\D)/g, '$1O$2');   //reverting "Wing on"
        regex(/(Star Trek )into( Darkness)/g, '$1Into$2');   //reverting proper name - title of work
        regex(/((?:Sonata|Symphony|Concerto|Prelude)(?: No\. \d\d?|)) in a((?:-flat|) [Mm](?:inor|ajor))/g, '$1 in A$2');   //reverting musical term

}
 
function Ohc_format_MOSFLAG(){
    //remove flagicons from country, birth and death
	regex(/((?:birth|death|place|captain|chairman|club|coach|manager|headquarters|citizenship|nationality|occupation|origin|party|region_served|stadium)\s*=\s*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\} ?|\[\[(?:File|Image):Flag of [^\]]\]\] ?)/gi, '$1');    
	regex(/((?:birth|death)(?:_?place|)\s*=\s*)\{\{flag(?:country|u|)\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
	regex(/((?:(?:birth|death)(?:_?place|)|citizenship|residence|nationality)\s*=\s*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\} ?|\[\[(?:File|Image):Flag of [^\]]+\]\] ?)/gi, '$1$2');
    regex(/((?:city|location|residence|venue)\s*=\s*)\{\{flag(?:country|)\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
//    regex(/((?:city|location|residence|venue)\s*=\s*[^{}|]*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\}|\[\[(?:File|Image):Flag of [^\]]+\]\]) ?/gi, '$1');
    regex(/((?:city|location|residence|venue)\s*=\s*(\[\[[^|\]]+\|[^|\]]+\]\]|)[^{}|]*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\}|\[\[(?:File|Image):Flag of [^\]]+\]\]) ?/gi, '$1');
    regex(/((?:country|location|nationality|residence)\s*=\s*)\{\{flagu?\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
    regex(/((?:champs|name|leader|scorer)\s*=\s*)\{\{leagueicon?\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1');

//strip bare facilities icons
    regex(/\[\[(File|image):Feature (accessible|elevators|parking|suburban buses)\.svg\|\d\d?px(?:\|[^\]]+)?\]\]\s*/gi, ''); 


//remove scroll bar for reflists 
	regex(/(References ?={1,4}[\n\r])[\r\n\s]*<div class=[^>]*>([\S\s]*?)<\/div>/gi, '$1$2');
//	regex(/((?:Notes ?|References ?)={2,4}\s?[\n\r])[\r\n\s]*(?:\{\{[Rr]eflist\}\}|<[Rr]eferences ?\/>)/gi, '$1{{reflist|colwidth=30em}}');  

}
 
function Ohc_format_MOSPUNCT(){
//rem redundant spaces underlining and punctuation
//	regex(/([\s>()])[“„«](\[?\w+)/gi, '$1\"$2');
//	regex(/(\w+\]?\.?)[”»](\W)/gi, '$1\"$2');
	regex(/(.)[“„”«»](.)/gi, '$1\"$2');
//	regex(/([\s>()])[‘`´’′](\[?\w+)/gi, '$1\'$2');
	regex(/(\w)[‘’′](s|t)\b/gi, '$1\'$2');		// in-word replacement of various single quotes and prime symbol with straight apostrophe
//	regex(/(.)[‘`´’](.)/gi, '$1\'$2');		// straight apostrophe (won't touch prime symbol here)
	regex(/([\w;,\]\)>] ) +([\[(]|[a-z\d])/gi, '$1$2');	//rem multiple spaces except when preceded by full stop; tweaked to not remove dbl spaces where preceded by new sentence (caps)
	regex(/(^\.U\.)[ ]+((?:S|K)\.)/gi, '$1$2');  //U. S. and U. K. to U.S. and U.K.
	regex(/(<\/?ref(?: name=[^<>\/]*?|)>)[ ,\.]*(<ref)/gi, '$1$2');	// remove punctuation between ref tags
	regex(/[ ]{1,3}(<\/?ref(?:>| >| n))/gi, '$1');		// remove spaces and line feeds preceding ref tags and templates 
//	regex(/[ ]{1,3}(:\s)/gi, '$1');		// remove spaces preceding colons //disabled following complaint (Peter Coxhead Sept 2017)
//	regex(/(<\/ref ?>|<ref name=[^>\/]+\/>)([^\s<])/gi, '$1 $2');		// add spaces after ref tags
//	regex(/[ ]+(\n|\r)/gi, '$1');	//removes multiple spaces preceding line break
	regex(/(\d),&nbsp;([12]\d{3}\b)+/gi, '$1, $2');	//removes nbsp preceding year
	regex(/(\d)(?:&nbsp;| )%/gi, '$1%');	//removes nbsp preceding '%'
	regex(/(&nbsp;)[ ](–|&ndash;)/gi, '$1$2');	//Palliative for dashes script insertion of space after nbsp
	regex(/(&nbsp;| )(?:—|&mdash;)(&nbsp;| )/gi, '$1–$2');	//Palliative for dashes script insertion of space after nbsp

	regex(/\b(US|UK|A(?:US|)|C(?:AN|)|NZ|HK) ([$£¥€])(\d)/g, '$1$2$3');
	regex(/([$£¥€]) (\d)/gi, '$1$2');
	regex(/(\{\{(?:INR|Indian Rupee)\}\}|Rs\.?)(\d+)/g, '$1 $2');
	regex(/\{\{AUD\}\} ?(\d+)/g, 'A$$1');

//rem 'external' wiktionary links
	regex(/\[https?:\/\/en\.wiktionary\.org\/wiki\/[\w]*[ ](\w[^\]]*)\]/gi, '$1');

//rem linked copyright symbol 
	regex(/(\[\[copyright\|©\]\] |©)/gi, '');

//rem leading and lagging spaces within wikilinks
	regex(/(\[\[)[ ]+([^\[\]\|]*?)[ ]*(\]\])/gi, '$1$2$3');
	regex(/(\[\[)[ ]*([^\[\]\|]*?)[ ]+(\]\])/gi, '$1$2$3');
	regex(/(\[\[[^\[\]\|]*?[ ])[ ]+([^\[\]]*?\]\])/gi, '$1$2');
	regex(/(\[\[[^\[\]\|]*?)[ ]+\|[ ]*([^\[\]]+\]\])/gi, '$1|$2');
//	regex(/(\[\[[^\[\]\|]*?)[ ]*\|[ ]+([^\[\]]+\]\])/gi, '$1|$2'); //can't remember why we need the second (repeated) line
 
	regex(/\[\[([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*(?:album|film|magazine|newspaper|song)\))(\]\])/gi, '[[$1$2|$1$3'); //adding piping to album|film|magazine dabbed by parentheticals

//symbol for 'times' and dashes
//	regex(/&times;/gi, '×');
//	regex(/([ \.][\d]+)x([\d]+(?:\.[\d]+|)\s)/gi, '$1&nbsp;×&nbsp;$2'); //disabling - never ending false positives
	regex(/(\d) x (\d )/gi, '$1&nbsp;×&nbsp;$2');
	regex(/\s(A[cglmrstu]|B[ahikrad]?|C[adeflmno]|D[bsyrsu]|E[rsu]|F[elmr]?|G[adef]|H[fgos]|I[nr]?|Kr?|L[aruv]|M[dgnot]|N[abdeiop]?|Os?|P[abdmortu]?|R[abefghnu]|S[bcegimnr]?|T[abcehilm]?|U[ub][neopst]|V|W|Xe|Yb?|Z[nr])-(Br|Cl?|F|H|I|N|O|P|Se?)\s/g, ' $1–$2 '); //signifying chemical bonds abbrev
//	regex(/([^<][^!] *)--( *[^>])/gi, '$1–$2'); //disabling - causes false positives with urls and some images
	regex(/&mdash;/gi, '—');
	regex(/([\w\d]) — (?=[\w\d])/gi, '$1 – ');		// tweak to avoid replacing emdashes in strings that are in non-roman unicode characters
	regex(/(\D7\d7)–(\d(?:00|)\D)/gi, '$1-$2');  //airplane model numbers taking hyphen

//inserting a white space between wikilinks to avoid errors upon unlinking
	regex(/(\]\][\.,]?)(\[\[)(?!file|image)/gi, '$1 $2');

//full stop and nbsp fixes
	//protection for strings within wikilinks
	regex(/(\[(?:[^\|\]]*)\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})([ ]*(?:[cgkm])[^\|\]]*?[\|\]])/gi, '$1♭$2');
	regex(/(\[(?:[^\|\]]*)(?:\d?\d[:\.]\d?\d| \d?\d))([ ]*(?:[ap]\.m\.|[ap]m)[^\|\]]*?[\|\]])/gi, '$1♭$2');

	//degrees and titles
	regex(/(Ph)(?:\.\s?|\s)(D)\.?/g, '$1$2');
	regex(/\b(B|M)(?:\.\s?|\s)(Arch|Comm|Ed|Eng|Sc|Tech)\.?(?=\W)/g, '$1$2');
//	regex(/(\|[A-Z])\.\s?([A-Z])\.\s?([A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2$3$4]]');
//	regex(/(\|[A-Z])\.\s?([A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2$3]]');
//	regex(/(\|[A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2]]');

	//times of day, time ranges
//	regex(/((?:\d?\d[:\.]\d?\d| \d?\d)&nbsp;[ap])(?:\.m\.)(?=[^\w\-])/gi, '$1m');

//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?=[^\w\-])/gi, '$1&nbsp;am&nbsp;– $2&nbsp;pm');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?=[^\w\-])/gi, '$1&nbsp;pm&nbsp;– $2&nbsp;am');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?=[^\w\-])/gi, '$1&nbsp;am&nbsp;– $2&nbsp;am');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?=[^\w\-])/gi, '$1&nbsp;pm&nbsp;– $2&nbsp;pm');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:a\.m\.|am)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(noon|midnight)(?=[^\w\-])/gi, '$1&nbsp;am&nbsp;– $2');
//	regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:p\.m\.|pm)(?:[ ]*|&nbsp;)[-–—](?:[ ]*|&nbsp;)(noon|midnight)(?=[^\w\-])/gi, '$1&nbsp;pm&nbsp;– $2');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:am|AM)(?=[^\w\-])/g, '$1&nbsp;am');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:pm|PM)(?=[^\w\-])/g, '$1&nbsp;pm');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Aa]\.[Mm]\.)(?=\S[^\w\-])/g, '$1&nbsp;am');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Pp]\.[Mm]\.)(?=\S[^\w\-])/g, '$1&nbsp;pm');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Aa]\.[Mm])(?=\.[\s\W][A-Z])/g, '$1&nbsp;am');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Pp]\.[Mm])(?=\.[\s\W][A-Z])/g, '$1&nbsp;pm');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Aa]\.[Mm])(?=\.<)/g, '$1&nbsp;am');
	regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*|&nbsp;)(?:[Pp]\.[Mm])(?=\.<)/g, '$1&nbsp;pm');

	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kw)\b/gi, '$1&nbsp;kW');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:khz)\b/gi, '$1&nbsp;kHz');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:mhz)\b/gi, '$1&nbsp;MHz');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:ghz)\b/gi, '$1&nbsp;GHz');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kph|kphr|kmh|kmhr|kmph|kmphr|km\/hr)\b/gi, '$1&nbsp;km/h');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:m\.p\.h\.)\b/gi, '$1&nbsp;mph');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(gm|kg|km)s?\b/g, '$1&nbsp;$2');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*KMs?\b/gi, '$1&nbsp;km');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*KGs?\b/gi, '$1&nbsp;kg');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:K(g|m))s?\b/gi, '$1&nbsp;k$2');
	regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*cms?/gi, '$1&nbsp;cm');
	regex(/([^\|\[=]\d{1,3})\s(m|b|tr)illion(\b[^}])/g, '$1&nbsp;$2illion$3');

        regex(/(\d)(?:&nbsp;|\s)?C(entimet(?:er|re))/g, '$1&nbsp;c$2');
        regex(/(\d)(?:&nbsp;|\s)?K(ilomet(?:er|re))/g, '$1&nbsp;k$2');
        regex(/(\d)(?:&nbsp;|\s)?KM\b/g, '$1&nbsp;km');

//turn letter 'x' into symbol '×'
	regex(/(\d)\sx\s(\d{1,3})\sin\s\(/gi, '$1 × $2 in (');
	regex(/(\d)\sx\s(\d{1,3})\sinch\s/gi, '$1 × $2 inch ');

// Convert degree symbols into ° symbol, ensure preceding space
	regex(/&deg;/g, '°');
//	regex(/º/g, '°');

// Celsius spelling errors
	regex(/(?:celsius|celcius|centigrade)/gi, 'Celsius');

//Fix common naming error (be careful with this one)
//	regex(/centigrade/gi, 'Celsius');
//Celsius or Fahrenheit
	regex(/(\d)&nbsp;(?:[°º]|deg|degree|degrees)&nbsp;([CF]\W)/g, '$1&nbsp;°$2');
	regex(/(\d)(?:[°º]|deg|degree|degrees)&nbsp;([CF]\W)/g, '$1&nbsp;°$2');
	regex(/(\d)&nbsp;(?:[°º]|deg|degree|degrees)([CF]\W)/g, '$1&nbsp;°$2');
	regex(/(\d)(?:\s|)(?:[°º]|deg|degree|degrees)(?:\s|)([CF]\W)/g, '$1&nbsp;°$2');
	regex(/(\d)(?:\s|&nbsp;)?(?=\[\[Celsius\|[°º]C\]\])/gi, '$1&nbsp;$2');
	regex(/(\d)(?:\s|&nbsp;)?(?=\[\[Fahrenheit\|[°º]F\]\])/gi, '$1&nbsp;$2');
	regex(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-|&nbsp;|)[°º]F([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1{{convert|$2|°F|°C|abbr=on}}$3');
	regex(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-|&nbsp;|)(?:deg|degree|degrees)(?:\s|-|&nbsp;|)Fahrenheit([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1{{convert|$2|°F|°C}}$3');

// Convert &sup to superscript
//	regex(/(m)(?:&sup2;|²);/gi, '$1<sup>2</sup>');
//	regex(/(m)(?:&sup3;|³);/gi, '$1<sup>3</sup>');

//remove commas from numerical values in convert template
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
	regex(/(\{convert\|\d+),(\d)/gi, '$1$2');

//inappropriate unit pairs for convert template
	regex(/(\{\{convert\s*\|\d+(?:\.\d|)\|acre\|)m2(?=[|}])/gi, '$1ha');

//remove leading zeros from convert template
	regex(/(\{\{convert\s*\|)\s*0+(?=[1-9])/gi, '$1$2');

///e-acute accent in spelling
	regex(/\b(caf|clich)e\b/g, '$1é');

}
 
function Ohc_format_COMMONALITY(){
///per WP:COMMONALITY
	regex(/([Ff])reshman (year)/g, '$1irst $2');
	regex(/([Ss])ophomore (album|year)/g, '$1econd $2');

//remove Crores and Lakhs in templates converting to USD 
	regex(/\{\{INR Convert[ ]*\|[ ]*/gi, '{{INRConvert|'); //removing spaces (redirects to shortcut)
 
	regex(/(\{INRConvert\|-?\d{2,})8\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$19$2');
	regex(/(\{INRConvert\|-?\d{2,})7\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$18$2');
	regex(/(\{INRConvert\|-?\d{2,})6\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$17$2');
	regex(/(\{INRConvert\|-?\d{2,})5\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$16$2');
	regex(/(\{INRConvert\|-?\d{2,})4\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$15$2');
	regex(/(\{INRConvert\|-?\d{2,})3\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$14$2');
	regex(/(\{INRConvert\|-?\d{2,})2\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$13$2');
	regex(/(\{INRConvert\|-?\d{2,})1\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$12$2');
	regex(/(\{INRConvert\|-?\d{2,})0\.[5-9]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$11$2');
	regex(/(\{INRConvert\|-?\d{3,})\.[0-4]\d*[ ]*(\|c(?:\|-?\d|)\}\})/gi, '$1$2');
 
	regex(/(\{INRConvert\|)(-?\d+)0000[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2|b$3$4');
	regex(/(\{INRConvert\|)(-?\d+)0[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2|m$3$4');
	regex(/(\{INRConvert\|)(-?\d+)(\d)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2.$3|m$4$5');
	regex(/(\{INRConvert\|)(-?\d+)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$200000$3$4');
	regex(/(\{INRConvert\|)(-?\d+)\.(\d)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2$30000$4$5');
	regex(/(\{INRConvert\|)(-?\d+)\.(\d)(\d)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2$3$4000$5$6');
//	regex(/(\{INRConvert\|)(-?\d+)(\d)[ ]*\|l(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2.$3|m$4$5');
	regex(/(\{INRConvert\|)(-?\d+)\.(\d)[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2$3|m$4$5');
	regex(/(\{INRConvert\|)(-?\d+)\.(\d)(\d+)[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2$3.$4|m$5$6');
	regex(/(\{INRConvert\|)(-?\d+)00[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2|b$3$4');
	regex(/(\{INRConvert\|)(-?\d+)(\d)0[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2.$3|b$4$5');
	regex(/(\{INRConvert\|)(-?\d+)(\d\d)[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$2.$3|b$4$5');
	regex(/(\{INRConvert\|)(-?\d+)[ ]*\|c(\|-?\d|)(?:\|nolink=yes|)((?:\|year=\d{4}|)\}\})/gi, '$1$20|m$3$4');
 
	regex(/(\{INRConvert\|-?\d{2,})8\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$19$2');
	regex(/(\{INRConvert\|-?\d{2,})7\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$18$2');
	regex(/(\{INRConvert\|-?\d{2,})6\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$17$2');
	regex(/(\{INRConvert\|-?\d{2,})5\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$16$2');
	regex(/(\{INRConvert\|-?\d{2,})4\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$15$2');
	regex(/(\{INRConvert\|-?\d{2,})3\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$14$2');
	regex(/(\{INRConvert\|-?\d{2,})2\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$13$2');
	regex(/(\{INRConvert\|-?\d{2,})1\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$12$2');
	regex(/(\{INRConvert\|-?\d{2,})0\.[5-9]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$11$2');
	regex(/(\{INRConvert\|-?\d{3,})\.[0-4]\d*[ ]*(\|[bm](?:\|-?\d|)\}\})/gi, '$1$2');
 
	//Currency notation placements  [$£₤¥€]
	regex(/\s(\$(?:\d+\.\d\d?|\d{1,3}|\d{1,3},\d{3}))((?:\s|&nbsp;)(?:m|b|tr)illion|)[ ]*(?:US(?:[D$]|\s?dollars?))\b/gi, ' US$1$2');

//Remove surprise or 'Easter egg' diversions linking unit name to orders of magnitude articles
	regex(/\[\[1\s?_?E\s?[\-\+]?\d{1,2}\s?..?\|([^\]]{1,50})\]\]/gi, '$1');
	regex(/\[\[Orders\sof\smagnitude\s\([^\)]+\)\|([^\]]{1,50})\]\]/gi, '$1');

	regex(/(\d)♭(\w| )/g, '$1$2');

//remove useless comments
	regex(/<!-- Metadata: see \[\[Wikipedia:Persondata\]\]\. -->/gi, '');

//Deleted image cleanup
	regex(/<!-- Deleted image removed:[^>]*? -->\n*/gi, '');

//	setoptions(minor='true');		//removed ",watch='false'" in response to user notification 13 Nov. 2010
//	setreason('remove bold formatting', 'append');
}

/** ------------------------------------------------------------------------ **/
/// PROTECTION BY STRING SUBSTITUTION
 
var linkmap=[];
function ohc_downcase_CEO()
{
    // protects categories, templates, link pipings, quotes, etc
    // the sensitive part is stored and replaced with a unique identifier,
    // which is later replaced with the stored part.
 
    var protect_function = function(s, begin, replace, end) {
        linkmap.push(replace);
        return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
    };
    regex(/(<(?:imagemap)>)([\s\S]*)(<\/(?:imagemap)>)/gi, protect_function);
    regex(/(\{(?:Coord|See ?also|Main|Wikisource))(\|[^{}]*)(\})/gi, protect_function);
    regex(/(\{\{cit(?:ation|e))([^<>}]*)(\}\})/gi, protect_function);
    regex(/((?:Category|File|Image):)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/((?:image\d?|image_skyline|image[ _]location\d?|image[ _]name|image[ _]file|img|pic)\s*=)([^|}]*)([|}])/gi, protect_function);
    regex(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function);
    regex(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function);
    regex(/(\|\s*edition\s*=)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/(\|\s*\w*\s*=\s*)(\d(?:st|nd|rd|th)[^|\]]*)([\|\]])/gi, protect_function);
    regex(/(\D)(\d(?:st|nd|rd|th)(?: (?:to |and )(?:the |)\d{1,2}(?:st|nd|rd|th)|) (?:centur|ed[i\. ]|grade|millenni[au]|parallel|round))(.)/gi, protect_function); //protecting lower case terms only; code does not expand where ordinal num is followed by a block cap
    regex(/((?:cover|file(?:name|)|image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic|map|title|quote)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
    regex(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
    regex(/(\[\[\w*)([^\|\]]*)(\|)/gi, protect_function);
    regex(/(\{\{\w*)([^\|=\[\]]*)(\}\})/gi, protect_function);
    regex(/(<ref(?: name="[^\"]*?" ?|)>)([\s\S]*?)(<\/ref>)/gi, protect_function);
    regex(/(<ref(?: name=\w+)>)([\s\S]*?)(<\/ref>)/gi, protect_function);
    regex(/(\{Infobox)( non Test)( cricket)/gi, protect_function);
    regex(/(.)((?:Chairman's|President'?s) (?:XI|Cup))(.)/g, protect_function);
    regex(/(.)(100\scrore club)(.)/gi, protect_function);
    regex(/(.)(Conference of Presidents)(.)/g, protect_function);
    regex(/(.)(Pussy Riot)(.)/g, protect_function);
    regex(/(\[\[)((?:The |)Texas Chain ?Saw Massacre[^\]|]*)([\]|])/gi, protect_function);
 
        regex(/(Chief (Executive|Financial|Operating|Information|Marketing) Officer)/g, '{{' + 'subst:' + 'lc:$1}}');
//		regex(/C(hief Executive)(?=\W)/g, 'C{{' + 'subst:' + 'lc:$1}}'); 
        regex(/M(anaging )D(irector)(?=\W)/g, 'm$1d$2');
        regex(/G(eneral )M(anager\b)(?!of|[ ]*=)/g, 'g$1m$2');
        regex(/(Chairman of the Board(?: of Directors|))/g, '{{' + 'subst:' + 'lc:$1}}');
        regex(/([Bb]oard of Directors)(?=\W)/g, '{{' + 'subst:' + 'lc:$1}}');
        regex(/(Board Members?)(?=\W)/g, '{{' + 'subst:' + 'lc:$1}}');
        regex(/(Committee Members?)(?=\W)/g, 'c{{' + 'subst:' + 'lc:$1}}');
        regex(/(Independent (?:(?:Non[\s\-]|)Executive |)Directors)(?=\W)/gi, '{{' + 'subst:' + 'lc:$1}}');
        regex(/(Non[\s\-]Executive Directors?)(?=\W)/g, '{{' + 'subst:' + 'lc:$1}}');
        regex(/I(ndependent )S(chool)(?=\W)/g, 'i$1s$2'); //false positive with Independent Schools Inspectorate
        regex(/N(on[\s\-])P(rofit)(?=\W)/g, 'n$1p$2');
        regex(/(\w\s)V(ice)[\s\-]C(hair(?:man|)\W)(?!of)/g, '$1v$2-c$3');
        regex(/(\w\s)C(hairman\W)(?!of)/g, '$1c$2');
        regex(/C(ompany )S(ecretary\W)(?!of)/g, 'c$1s$2');
        regex(/G(eneral )S(ecretary\W)(?!of)/g, 'g$1s$2');
//        regex(/(\b[^A-Z]\w*[^neS]\.?\s)V(ice)[\s\-]P(resident\W|rincipal)(?!of)/g, '$1v$2-p$3');
        regex(/(\w\s+)P(residents)/g, '$1p$2');
//        regex(/(\b[^A-Z]\w*[^neS]\.?\s)P(resident\W)(?!of)/g, '$1p$2');
//        regex(/(\w\s)D(eputy) P(rime)[\s\-]M(inister\W)(?!of)/g, '$1d$2 p$3 m$4');
        regex(/([Aa]\s)M(ember of )P(arliament\W)/g, '$1m$2p$3');
        regex(/(\w\s)M(embers of )P(arliament\W)/g, '$1m$2p$3');

// Euros - replace space as separator
	regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4,$5,$6');
	regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4,$5');
	regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4');
	regex(/(€|Euros?) ?(\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3');
	regex(/(\d+)[\. ](\d{3})[\. ](\d{3}) ?(€|Euros?|\[\[(?:€|Euros?\||)(?:€|Euros?)\]\])(?=\W)/g, '$4$1,$2,$3');
	regex(/(\d+)[\. ](\d{3}) ?(€|Euros?|\[\[(?:€|Euros?\||)(?:€|Euros?)\]\])(?=\W)/g, '$3$1,$2');

// replace full stop as thousands separator
	regex(/(\|[\s\']+)(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3,$4,$5');
	regex(/(\|[\s\']+)(\d+)[\. ](\d{3})[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3,$4');
//	regex(/(\|[\s\']+)(\d+)[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3'); //disabled 2 april 2017 due to false positives with 3dp

// replace comma as decimal separator
	regex(/(\|[\s\']+)(\d+),(\d\d?)(?=[ ']*[|\n<])/g, '$1$2.$3'); //add obligatory space or single quote mark,- false positives within convert templates
	regex(/(\(\d+),(\d\d?%\))/g, '$1.$2');	//percentages in parentheses
	regex(/(\{\{(?:de|in)crease\}\}\s*)(\d+),(\d\d?)(?=[ ]*[|\n<])/g, '$1$2.$3');

	regex(/([€])[ ]*(\d+)(?=\W)/g, '$1$2');
	regex(/([€])(\d+),(\d\d?)(?=\W)/g, '$1$2.$3');
	regex(/(\W)(\d+),(\d\d?)[ ]*(?=[€%]|Euro?)/g, '$1$2.$3');
	regex(/(\|\s*attendance\s*=\s*\d{1,3})[\.]?(\d{3}\D)/gi, '$1,$2');

// layout - rem horizontal lines per WP:LAYOUT
//	regex(/(\n)----\n/g, '$1'); // html element - may sometimes be appropriate – disabled per discussion at WT:LAYOUT July 2014

//remove Crores and Lakhs not in templates
	regex(/(\d+)[ ]?(?:lakh|\[\[lakh\]\])[\- ](?:crores?|\[\[crores?\]\])/g, '$1&nbsp;trillion ([[Long and short scales|short scale]])');

    regex(/(?:(\d+),|)(\d+)0,000(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2&nbsp;billion');
	regex(/(?:(\d+),|)(\d+)\.(\d)(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2$30,000');
	regex(/(?:(\d+),|)(\d+)\.(\d)(\d)(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2$3$4,000');
	regex(/(?:(\d+),|)(\d+)0(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2&nbsp;million');
	regex(/(?:(\d+),|)(\d+)(\d+)(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$2.$3&nbsp;million');
	regex(/(?:(\d+),|)(\d+)(?:&nbsp;|\s)?(?:[Ll]acs?|[Ll]akhs?|\[\[[Ll]akhs?(?:\|[Ll]|\|[Ll]acs?|\|[Ll]akhs?|)\]\]s?)(?=[^\-\w])/g, '$1$200,000');
	regex(/(?:(\d+),|)(\d+)\.(\d)(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$2$3&nbsp;million');
	regex(/(?:(\d+),|)(\d+)\.(\d)(\d+)(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$2$3.$4&nbsp;million');
	regex(/(?:(\d+),|)(\d+)00(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$2&nbsp;billion');
	regex(/(?:(\d+),|)(\d+)(\d\d)(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$2.$3&nbsp;billion');
	regex(/(?:(\d+),|)(\d+)(?:&nbsp;|\s)?(?:[Cc]rs?|[Cc]rores?|\[\[[Cc]rores?(?:\|[Cc]rs?|\|[Cc]rores?|)\]\]s?)(?=[^\-\w])/g, '$1$20&nbsp;million');

// Indian commas
	regex(/(\W)(\d{1,3}),(\d\d),(\d\d),(\d\d),(\d\d),(\d\d\d)(?=[\s\.,–]\D)/g, '$1{{formatnum:$2$3$4$5$6$7}}');
	regex(/(\W)(\d{1,3}),(\d\d),(\d\d),(\d\d),(\d\d\d)(?=[\s\.,–]\D)/g, '$1{{formatnum:$2$3$4$5$6}}');
	regex(/(\W)(\d{1,3}),(\d\d),(\d\d),(\d\d\d)(?=[\s\.,–]\D)/g, '$1{{formatnum:$2$3$4$5}}');
	regex(/(\W)(\d{1,3}),(\d\d),(\d\d\d)(?=[\s\.,–]\D)/g, '$1{{formatnum:$2$3$4}}');

	regex(/(\{INR)\}\}[ ]*\{\{formatnum:(\d+\}\})/g, '$1Convert|$2');
//	regex(/(\{\{(?:INR|Indian Rupee)\}\}|Rs\.?) (\d+)/g, '$1$2');

    //removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
    regex(/⍌([0-9]+)⍍/g, function(x, n) {
        var res = linkmap[n];
        res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
            var res = linkmap[n];
            res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                var res = linkmap[n];
                res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                    return linkmap[n];
                });
                return res;
            });
            return res;
        });
        return res;
    });
}
 
/** ------------------------------------------------------------------------ **/
/// LINKSPAM removal with protection for Reference tags and External links

var linkmap=[];
function ohc_linkspam()
{
    // protects everything within reference tags 
    // the sensitive part is stored and replaced with a unique identifier,
    // which is later replaced with the stored part.
 
    var protect_function = function(s, begin, replace, end) {
        linkmap.push(replace);
        return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
    };

    regex(/(== ?(?:Bibliography|Further reading|References|Sources|Works) ?==+)(\n[\S\s]*?)(\n)(?===)/gi, protect_function);
    regex(/(== ?(?:Attribution|External links) ?==+)(\n[\S\s]*?)(\[\[Category:[^\]]+\]\])/gi, protect_function);
    regex(/({{(?:refn|sfnp)\|)([^}]*?)(}})/gi, protect_function);
    regex(/(<ref name="[^\"]*?" ?>)([\s\S]*?)(<\/ref>)/gi, protect_function);
    regex(/(<ref[^/>]*?>)([\s\S]*?)(<\/ref>)/gi, protect_function);
    regex(/(\|\s?(?:image|model|references?|video)\d\s?=\s?[\'\"]?\[https?:)([^\]]*)(\])/gi, protect_function);
    regex(/([=\*][ ]?\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);


 
	regex(/([^>\*][ ]?)\[https?:\/\/[^\s\[\]]*[ ]+([\'\"\w][^\[\]]*)\](?![ ]*[\n\-]+)/gi, '$1$2');



    //removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
    regex(/⍌([0-9]+)⍍/g, function(x, n) {
        var res = linkmap[n];
        res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
            var res = linkmap[n];
            res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                var res = linkmap[n];
                res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                    return linkmap[n];
                });
                return res;
            });
            return res;
        });
        return res;
    });
}

function ohc_change_type(){

//update syntax of 'File'
//	regex(/\[\[(file|[Ii]mage):/g, '[[File:');
//add {{url}} template to infobox parameter
	regex(/({{) ?(url) ?(?=\|)/gi, '$1$2');
	regex(/({{url\|)[ ]*(?:https?:\/\/|)((?:www\.|)[^\}]+}})[ ]*(?=[\n\r])/gi, '$1$2');
	regex(/({{url\|)(?:https?:\/\/|)((?:www\.|)[^\}]+)\|(?:\2|Official (?:web|)site)}}(?=[\s])/gi, '$1$2}}');
	regex(/(\| ?homepage[ ]*=)[ ]*https?:\/\/(?:www\.|)([^\s\[\]]+)(?=[\s])/gi, '$1{{url|$2}}'); //rem 'website='
	regex(/(\| ?(?:homepage|website)[ ]*=)[ ]*\[https?:\/\/(www\.|)([^\s\[\]]+) \2\3\](?=[\s])/gi, '$1{{url|$3}}');
	regex(/(\| ?(?:homepage|website)[ ]*=)[ ]*\[https?:\/\/(?:www\.|)([^\s\[\]]+) official (?:web|)site\](?=[\s])/gi, '$1{{url|$2}}');

//remove icons from headers (needs to occur before protection)
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:File|image):[^\]]+?\]\]([^\[=\n]*)([ ]?==)/gi, '$1$2$3');


}

function Ohc_final_cleanup(){

//adjust piping - remove redundant, adding piping for parentheticals
         regex(/\[\[A([^\]\|]*)\|(a)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[B([^\]\|]*)\|(b)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[C([^\]\|]*)\|(c)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[D([^\]\|]*)\|(d)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[E([^\]\|]*)\|(e)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[F([^\]\|]*)\|(f)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[G([^\]\|]*)\|(g)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[H([^\]\|]*)\|(h)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[I([^\]\|]*)\|(i)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[J([^\]\|]*)\|(j)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[K([^\]\|]*)\|(k)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[L([^\]\|]*)\|(l)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[M([^\]\|]*)\|(m)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[N([^\]\|]*)\|(n)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[O([^\]\|]*)\|(o)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[P([^\]\|]*)\|(p)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[Q([^\]\|]*)\|(q)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[R([^\]\|]*)\|(r)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[S([^\]\|]*)\|(s)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[T([^\]\|]*)\|(t)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[W([^\]\|]*)\|(w)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[X([^\]\|]*)\|(x)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[Y([^\]\|]*)\|(y)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[Z([^\]\|]*)\|(z)\1([^-\] ]*|)(\]\])/g, '[[$2$1$4$3');
         regex(/\[\[([^\]\|]*)\|\1([^-\] ]*|)(\]\])/gi, '[[$1$3$2'); //per WP:PIPE and WP:REDIRECT
         regex(/\[\[([^\[\]\(\)\|:]*)( \((?:\d{4} |)film\))(\]\])/gi, '\'\'[[$1$2|$1$3\'\'');
         regex(/\[\[([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*(?:album|film|magazine|newspaper|song|\bEP)\))(\]\])/g, '[[$1$2|$1$3'); //adding piping to album|film|magazine dabbed by parentheticals
//         regex(/([^"]\[\[)([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*\))(\]\])(?![\s\n])/gi, '$1$2$3|$2$4'); //ensure songs titles not piped by default, but disabled due to false removal from visible disambiguators

// deprecated parameters in citation templates
	regex(/(\|\s*)coauthors(\s*=\s*)/g, '$1author2$2');

}


function Ohc_downcase_headings(){
//cleanup of headings per MOSHEAD before complete downcasing (most code is copied from other parts of the script)
// remove file 
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:File|image):[^\]]+?\]\]([^\[=\n]*)([ ]?==)/gi, '$1$2$3');

//rem linking within section headings
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[([^\|\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[[^\|\]]+?\|([^\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
	regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\](?:([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]|)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3$4$5$6$7');

//original code
	regex(/(==+[ ]?[A-Z])([^\[=|]*)(?===+ ?\n)/g, '$1{{' + 'subst:' + 'lc:$2}}');

}
 
function Ohc_castlist(){
    //remove flagicons from country, birth and death
	regex(/(\* )(\[\[[-\w' ]*\]\]) as ([^,\.]*)([,.])([^\n<]*)([\n<])/gi, '$1\'\'\'$3\'\'\' ($2)$4$5$6');

}
 
/** ------------------------------------------------------------------------ **/
/// PROTECTION BY STRING SUBSTITUTION
 
var linkmap=[];
function ohc_protect_fmt()
{
    // protects categories, templates, link pipings, quotes, etc
    // the sensitive part is stored and replaced with a unique identifier,
    // which is later replaced with the stored part.
 
    var protect_function = function(s, begin, replace, end) {
        linkmap.push(replace);
        return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
    };
    regex(/(\{Wikisource\|)([\}]*)(\})/gi, protect_function);
    regex(/((?:Category|File|Image):)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/((?:[a-z]{2,3}):)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/(\{(?:See ?also|Main))(\|[^{}]*)(\})/gi, protect_function);
    regex(/((?:cover|file(?:name|)|image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic|map)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
    regex(/(\[\[\w*)([^\|\]]*)(\|)/gi, protect_function);
    regex(/(\{\{\w*)([^\|=\[\]]*)(\}\})/gi, protect_function);
    regex(/(<ref name=)([^<>]*)(>)/gi, protect_function);
    regex(/(Convoy(?:&nbsp;|\s))(\w{2,3}(?:&nbsp;|\s)\d\d(?:&nbsp;|\s)?\w{2,3})(.)/gi, protect_function);
    regex(/(\{Infobox)( non Test)( cricket)/gi, protect_function);
    regex(/(\d[]*)(Cr App R)(.)/g, protect_function);
    regex(/(.)(On a Friday)(.)/g, protect_function);
    regex(/(.)(Not On Our Watch Project)(.)/g, protect_function);
    regex(/(.)(Octopussy and the living daylights)(.)/gi, protect_function);
    regex(/(.)(\'?Carry On [A-Z][a-z]*)(.)/g, protect_function);
    regex(/(.)(10 metre (?:air|running) \w*)(.)/g, protect_function);
    regex(/(.)(\d day (?:schools) \w*)(.)/g, protect_function);
 
}


function ohc_unprotect_fmt()
{
    //removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
    regex(/⍌([0-9]+)⍍/g, function(x, n) {
        var res = linkmap[n];
        res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
            var res = linkmap[n];
            res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                var res = linkmap[n];
                res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
                    return linkmap[n];
                });
                return res;
            });
            return res;
        });
        return res;
    });
}

/** ------------------------------------------------------------------------ **/
 
function Ohc_formats(){
//driver

	Ohc_format_Sundry();
	Ohc_format_MOSCAPS();
	Ohc_format_MOSFLAG();
	Ohc_format_MOSPUNCT();
	Ohc_format_COMMONALITY();
}

function Ohc_formatgeneral() {
	ohc_change_type();
	ohc_protect_fmt();
	Ohc_formats();
	ohc_unprotect_fmt();
	ohc_downcase_CEO();
	ohc_linkspam();
	Ohc_final_cleanup();
	
}

function Ohc_run_formatgeneral() {
	Ohc_formatgeneral();
	Ohc_formatgen_edit_summary();

}

function Ohc_formatgen_edit_summary(){
	//Add a tag to the summary box
	setoptions(minor='true'); 		
	setreason('General [[WP:MOS|formatting]] by [[User:Ohconfucius/script|script]]', 'append');
	doaction('diff');
}
$(function () {
 if(document.forms.editform) {
 	mw.loader.using( ['mediawiki.util'], function() {
  	  mw.util.addPortletLink('p-tb', 'javascript:Ohc_run_formatgeneral()', 'General formatting', 't-addmetric', 'Fixes some unit formatting', '', '');
 	});
  }
});