// *********************************************************************************************
// PLEASE EXERCISE DUE CARE!!
// this script has been recently re-imagined and although it has been tested on a hundred (or more) articles, it may still contain bugs.
//
// You are advised to read and understand the script documentation at User:Ohconfucius/script/Sources (link above) prior to using.
// Please leave any questions on my talk page. Note that there is a separate page for bug reports.
// *********************************************************************************************
/*************
*** Regex menu framework
*** by [[m:user:Pathoschild]] <http://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Regex_menu_framework>
*** - adds a sidebar menu of user-defined scripts.
*************/
importScriptURI('http://meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');
importScript("User:Ohconfucius/test/Sources_subscript1.js");
importScript("User:Ohconfucius/test/Sources_subscript2.js");
importScript("User:Ohconfucius/test/Sources_subscript3.js");
function Ohc_linkspam() {
var txt=document.editform.wpTextbox1;
txt.value=txt.value.replace(/([^>\*][ ]?)\[https?:\/\/[^\s\]]*[ ]([\w\d][^\]]*)\](?![ ]*[\n\-]+)/gi, '$1$2');
}
function Ohc_sources_prep() {
var txt=document.editform.wpTextbox1;
// removing references to other WP articles
txt.value=txt.value.replace(/<ref>https?:\/\/en\.wikipedia\.org\/wiki\/[^\s\]<]*<\/ref>/gi, '');
txt.value=txt.value.replace(/<ref>\[https?:\/\/en\.wikipedia\.org\/wiki\/[^\s\]]*[ ][\w\d][^\]]*\]<\/ref>/gi, '');
// removing external links within publisher/journal/work fields
txt.value=txt.value.replace(/(\|\s?(?:newspaper|work|journal|publisher)\s*\=\s*)\[https?:\/\/[^\s\]]*\s([\w\d][^\]]*)\]/gi, '$1$2');
txt.value=txt.value.replace(/(\|\s?author(?:link\d?|)\s*\=\s*)\[https?:\/\/[^\s\]]*\s([\w\d][^\]]*)\]/gi, '$1$2');
txt.value=txt.value.replace(/(\|\s?(?:newspaper|work|journal|publisher|author)\s*\=\s*)www\.([\w\d][^\|\}]*)(?=[\|\}])/gi, '$1$2');
txt.value=txt.value.replace(/(\|\s?author(?:link\d?|)\s*\=\s*)www\.([\w\d][^\|\}]*)(?=[\|\}])/gi, '$1$2');
txt.value=txt.value.replace(/(\|\s?author\s*\=\s*)(?:wire staff|staff reporters?|)[ ]*(?=[\|\}])/gi, '');
txt.value=txt.value.replace(/(\|\s?author\s*\=\s*)([A-Z][a-z]*(?: [A-Z][a-z]*)*) (?:wire staff|(?:staff |)reporters?)[ ]*(?=[\|\}])/gi, '$1$2');
// txt.value=txt.value.replace(/\{\{[ ]*cite /g, '{{Cite ');
txt.value=txt.value.replace(/\{\{wikinews(|2|cat|has|portal|table|-inline)(\|[^\}]+|)\}\}\s*/gi, '');
txt.value=txt.value.replace(/\*[ ]*\{\{Find a Grave\|\d{4}(\|[^\}]+|)\}\}\s*/gi, '');
//citation template fixes
// rem copyright assertion
txt.value=txt.value.replace(/(\|\s?publisher\s*\=\s*)(?:\[\[copyright(?:\|©|)\]\])\s?/gi, '$1');
txt.value=txt.value.replace(/(\|\s?publisher\s*\=\s*)(?:©|copyright)\s?/gi, '$1');
txt.value=txt.value.replace(/(?:\|\s?publisher(\s*\=\s*)\'\'\[\[([^\]]{1,40})\]\]\'\')/gi, '|work$1[[$2]]');
txt.value=txt.value.replace(/(?:\|\s?publisher(\s*\=\s*)\'\'([^\|\}]{1,40})\'\')(?=\s*[\}\|])/gi, '|work$1$2');
txt.value=txt.value.replace(/(?:\|\s?(?:newspaper|work)(\s*\=\s*)\'\'\[\[([^\]]{1,40})\]\]\'\')/gi, '|publisher$1[[$2]]');
txt.value=txt.value.replace(/(?:\|\s?(?:newspaper|work)(\s*\=\s*)\'\'([^\|\}]{1,40})\'\')/gi, '|publisher$1$2');
// rem corporate designation
txt.value=txt.value.replace(/(\|\s?publisher\s*\=\s*[^\[\|\}]{1,40}), (?:Inc|LL[CP]|Ltd|PLC|SA)\.?(?=[ ]*\|\})/gi, '$1');
txt.value=txt.value.replace(/(\|\s?publisher\s*\=\s*[^\[\|\}]{1,40}) (?:Inc|LL[CP]|Ltd|PLC|SA)\.?(?=[ ]*\|\})/gi, '$1');
// rem unnecessary quote marks
txt.value=txt.value.replace(/(\|\s?title\s*\=\s*)["“]([^\|]+)["”](?=\s?[\|\}])/gi, '$1$2');
txt.value=txt.value.replace(/(\|\s?title\s*\=\s*)['‘]([^\|]+)['’](?=\s?[\|\}])/gi, '$1$2');
// repl double 'in-title' quote marks with single quotes
txt.value=txt.value.replace(/(\|\s?title\s*\=\s*[\w ]* )["“]((?:\w[\w]* )+(?:\w[\w]*))["”]([^\|]+|)(?=\s?[\|\}])/gi, '$1\'$2\'$3');
// removing blank parameters
regex(/(?:\|[ ]*(?:first\d?|agency|(?:co|)authors?\d?|archive(?:url|date)|journal|publisher|newspaper|work|(?:access|)date|doi|month|year|___location|format|language|last\d?|publisher|authorlink\d?|volume|issue|pages?|firstn|lastn|authorn-link|editor|editorn|editorn-last|editorn-first|editor-link|editorn-link|others|nopp|chapter|trans_chapter|chapterurl|quote|ref|laysummary|laydate|separator|postscript|lastauthoramp|issn|oclc|pmid|pmd|bibcode|id)[ ]*=[\s]*)(?=[\}\|])/gi, '');
//rem underlining within certain fields
txt.value=txt.value.replace(/(\|\s?(?:journal|newspaper|periodical|publisher|work)\s*\=\s*)<u>([^\|\}]*)<\/u>/gi, '$1');
//rem linking within locations field
regex(/(\|[ ]*?___location=[ ]*?)\[\[([^\|\]]+?)\]\](?:(,? )\[\[([^\|\]]+?)\]\]|)([ ]{0,1})/gi, '$1$2$3$4$5');
regex(/(\|[ ]*?___location=[ ]*?)\[\[(?:[^\|\]]+?\|)([\w\s\,]+?)\]\](?:(,? )\[\[([^\|\]]+?)\]\]|)([ ]{0,1})/gi, '$1$2$3$4$5');
regex(/\[\[(New York)\]\]/gi, '$1');
// eliminating time of day
ohc_regex(/(\|[ ]*author[ ]*=[ ]*)(?:posted|published)(?: by| on|)[\s:](?=\w)/gi, "$1");
regex(/(\|[ ]*(?:date|archivedate|accessdate|author)[ ]*=[ ]*)[0-2]?\d:[0-5]\d(?:[ ]| )(?:[ap]m |[ap]\.m\. |)([A-Z]{1,2}T|UTC)[\.,]?[ ]?/gi, "$1");
// eliminating days of the week
regex(/(\|[ ]*(?:date|archivedate|accessdate|author)[ ]*=[ ]*)(?:(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day,?)\s/gi, "$1");
regex(/(\|[ ]*(?:date|archivedate|accessdate|author)[ ]*=[ ]*)(?:(?:Mon|Tues?|Wed|Thur?|Fri|Sat|Sun)[\.,]?)\s/gi, "$1");
}
function Ohc_dab_news_sources() {
var txt=document.editform.wpTextbox1;
//pre-dab of piped sources
// regex(/(\[\[)(?:foo|bar)(\|)/gi, '$1foo bar \(dab\)$2');
regex(/(\[\[)(?:(?:British|English|London) Sun|Sun on Sunday|The Scottish Sun|(?:The |)Sun (?:\((?:British |)newspaper\)|\(tabloid\)|\(UK newspaper\)|\(UK\)|Newspaper|on Sunday|Online)|Thesun\.co\.uk)(\|)/gi, '$1The Sun \(United Kingdom\)$2');
regex(/(\[\[)Daily Star \((?:British|UK)\)(\|)/gi, '$1Daily Star \(United Kingdom\)$2');
regex(/(\[\[)(?:Calcutta Telegraph|The Telegraph \((?:kolkatt?a|India)\)|(?:The |)Telegraph India|Telegraphindia\.com)(\|)/gi, '$1The Telegraph \(Calcutta\)$2');
regex(/(\[\[)Dawn(?:, Karachi| newspaper|\.com| \((?:Newspaper|Pakistan)\))(\|)/gi, '$1Dawn \(newspaper\)$2');
regex(/(\[\[The Pioneer)(?:, Karachi| newspaper| \((?:indian newspaper)\))(\|)/gi, '$1 \(Indian newspaper\)$2');
regex(/(\[\[)dailypioneer.com(\|)/gi, '$1The Pioneer \(Indian newspaper\)$2');
regex(/(=[ ]*\[\[)(?:[BE]SPN ?(?:USA|HD|Network|the ocho|\(United States\))|E.S.P.N.|(?:The |)Entertainment (?:and |)Sports Programming Network)(?:\|[\w, ]*)(\]\])/gi, '$1ESPN$2');
}
function Ohc_publishers() {
var txt=document.editform.wpTextbox1;
//linked publishing houses
txt.value=txt.value.replace(/(?:\|\s?(newspaper|work|publisher)\s*\=\s*\[?\[?Hachette Filipacchi Médias\|(Hachette Filipacchi) \(UK\) Ltd\]?\]?)(?=[\s\.]*[\|\}])/gi, '');
txt.value=txt.value.replace(/(?:\|\s?(newspaper|work|publisher)\s*\=\s*\[?\[?(John Fairfax (and Sons Ltd\.?|Holdings)|Fairfax(?: Media( Limited)| Digital| newspapers))\]?\]?)(?=[\s\.]*[\|\}])/gi, '');
txt.value=txt.value.replace(/(?:\|\s?publisher\s*\=\s*(\[\[|)(Associated Newspapers|Condé Nast Publications|Fairfax Media|Gannett Company|(Guardian|Telegraph) Media Group|(?:Guardian|Independent) News (?:and|&) Media|Imdb Inc\.?|IDG|IPC Media|MTV Networks|(The |)(?:Washington Post|(?:New York|Seattle) Times) Company|News (?:Corporation|International|Limited)|Prometheus Global Media|Tribune Company|Trinity Mirror|Times Newspapers (?:Limited|Ltd.?)|Nielsen (?: Media Research|Business Media(, Inc\.?|))|Rovi Corporation|Viacom|Time (?:Warner ?|)Inc\.?)(\]\]|))(?=[\s\.]*[\|\}])/gi, '');
}
function Ohc_sources_cleanup() {
var txt=document.editform.wpTextbox1;
// relocating '___location' parameter outside citation templates
//sources without dab but with inserted locator
regex(/(''Daily News) \|___location=(New York)('')/gi, '$1$3 \($2\)');
regex(/(''\[\[Daily News\]\]) \|___location=(New York)('')/gi, '$1$3 \($2\)');
regex(/(=\s*\[\[|\|)(Daily News)( \|___location=New York)(\]\])/gi, '$1$2$4$3');
regex(/(\[\[|\|)(Daily News) \|___location=(New York)(\]\])/gi, '$1$2$4 $3');
regex(/(''Evening Standard) \|___location=(London)('')/gi, '$1$3 \($2\)');
regex(/(''\[\[Evening Standard\]\]) \|___location=(London) ?('')/gi, '$1$3 \($2\)');
regex(/(=\s*\[\[|\|)(Evening Standard)( \|___location=London)(\]\])/gi, '$1$2$4$3');
regex(/(\[\[|\|)(Evening Standard)( \|___location=London)(\]\])/gi, '$1$2$4 $3');
// displacing ___location-dab (in parentheses)
regex(/( \|___location=(?:New York|UK))(\]\])/gi, '$2$1');
// The following regexes for dab-links are in sets of four. If changing, please ensure all sets are changed
regex(/(=[ ]*(?:The ?|)[A-Z]\w*(?: [A-Z]\w*|)) \((South Africa)(?:n newspaper|)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''(?:The ?|)[A-Z]\w*(?: [A-Z]\w*|)) \((South Africa)(?:n newspaper|)\)(''[\.,;])/g, '$1$3$2');
regex(/(\[\[((?:The ?|)[A-Z]\w*(?: [A-Z]\w*|)))( \(South Africa(?:n newspaper|)\))(\]\][\.,;]?)/g, '$1$3|$2$4');
regex(/(\|)((?:The ?|)[A-Z]\w*(?: [A-Z]\w*|))(?: \((South Africa)(?:n newspaper|)\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*Daily Record) \((Scotland)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''Daily Record) \((Scotland)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(Daily Record)( \(Scotland\))(\]\][\.,;]?)/g, '$1$2$3|$2$4');
regex(/(\|)(Daily Record)(?: \(Scotland\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*Dawn) \((newspaper)\)([ ]*[\|\}])/g, '$1|___location=Pakistan$3');
regex(/(''Dawn) \((newspaper)\)('')/g, '$1$3 \(Pakistan\)');
regex(/(\[\[)(Dawn)( \(newspaper\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(Dawn)(?: \(newspaper\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*(?:Daily Star)) \((United Kingdom)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''(?:Daily Star)) \((United Kingdom)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(Daily Star)( \(United Kingdom\))(\]\][\.,;]?)/g, '$1$2$3|$2$4');
regex(/(\|)(Daily Star)(?: \(United Kingdom\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*El Mundo) \((Columbia|Spain)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''El Mundo) \((Columbia|Spain)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(El Mundo)( \(Columbia|Spain\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(El Mundo)(?: \((?:Columbia|Spain)\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*The Daily Star) \((Lebanon)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''The Daily Star) \((Lebanon)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(The Daily Star)( \(Lebanon\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(The Daily Star)(?: \(Lebanon\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*The Gazette) \((Montreal)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''The Gazette) \((Montreal)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(The Gazette)( \(Montreal\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(The Gazette)(?: \(Montreal\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*The Herald) \((Glasgow)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''The Herald) \((Glasgow)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(The Herald)( \(Glasgow\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(The Herald)(?: \(Glasgow\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*The Nation) \((Malawi|Nigeria|Thailand)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''The Nation) \((Malawi|Nigeria|Pakistan|Thailand)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(The Nation)( \((?:Malawi|Nigeria|Pakistan|Thailand)\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(The Nation)(?: \((?:Malawi|Nigeria|Pakistan|Thailand)\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*La Presse) \((Canadian newspaper)\)([ ]*[\|\}])/g, '$1|___location=Canada$3');
regex(/(''La Presse) \((Canadian newspaper)\)('')/g, '$1$3 \(Canada\)');
regex(/(\[\[)(La Presse)( \(Canadian newspaper\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(La Presse)(?: \(Canadian newspaper\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*Les Échos) \((France)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''Les Échos) \((France)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(Les Échos)( \(France\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(Les Échos)(?: \(France\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*Panorama) \((Gibraltar)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''Panorama) \((Gibraltar)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(Panorama)( \(Gibraltar\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(Panorama)(?: \(Gibraltar\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*The Pioneer) \((Indian newspaper)\)([ ]*[\|\}])/g, '$1|___location=India$3');
regex(/(''The Pioneer) \((Indian newspaper)\)('')/g, '$1$3 \(India\)');
regex(/(\[\[)(The Pioneer)( \(Indian newspaper\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(The Pioneer)(?: \(Indian newspaper\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*The Sun) \((Hong Kong|Malaysia|Nigeria|United Kingdom)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
regex(/(''The Sun) \((Hong Kong|Malaysia|Nigeria|United Kingdom)\)('')/g, '$1$3 \($2\)');
regex(/(\[\[)(The Sun)( \((?:Hong Kong|Malaysia|Nigeria|United Kingdom)\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(The Sun)(?: \((?:Hong Kong|Malaysia|Nigeria|United Kingdom)\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*The Telegraph) \((Calcutta)\)([ ]*[\|\}])/g, '$1|___location=Calcutta$3');
regex(/(''The Telegraph) \((Calcutta)\)('')/g, '$1$3 \(Calcutta\)');
regex(/(\[\[)(The Telegraph)( \(Calcutta\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(The Telegraph)(?: \(Calcutta\))(\]\])/g, '$1$2$3');
regex(/(=[ ]*Vogue) \((British magazine)\)([ ]*[\|\}])/g, '$1|___location=UK$3');
regex(/(''Vogue) \((British magazine)\)('')/g, '$1$3 \(UK\)');
regex(/(\[\[)(Vogue)( \(British magazine\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(Vogue)(?: \(British magazine\))(\]\])/g, '$1$2$3');
regex(/(=(?:ABC|Sport)) \((newspaper)\)([ ]*[\|\}])/g, '$1|___location=Spain$3');
regex(/(''(?:ABC|Sport)) \((newspaper)\)('')/g, '$1$3 \(Spain\)');
regex(/(\[\[)(ABC|Sport)( \(newspaper\))(\]\])/g, '$1$2$3|$2$4');
regex(/(\|)(ABC|Sport)(?: \(newspaper\))(\]\])/g, '$1$2$3');
// regex(/(=(?:Business Day|City Press|Daily News|Daily Voice|Independent Online|New Age|Post|Table Talk|The Citizen|The Mercury|The New Age|The Star|The Sunday Independent|The Sunday Times|The Times|The Witness|The World)) \((South Africa)(?:n newspaper|)\)([ ]*[\|\}])/g, '$1|___location=$2$3');
// regex(/(''(?:Business Day|City Press|Daily News|Daily Voice|Independent Online|New Age|Post|Table Talk|The Citizen|The Mercury|The New Age|The Star|The Sunday Independent|The Sunday Times|The Times|The Witness|The World)) \((South Africa)(?:n newspaper|)\)('')/g, '$1$3 \($2\)');
// regex(/(\[\[)(Business Day|City Press|Daily News|Daily Voice|Independent Online|New Age|Post|Table Talk|The Citizen|The Mercury|The New Age|The Star|The Sunday Independent|The Sunday Times|The Times|The Witness|The World)( \(South Africa(?:n newspaper|)\))(\]\])/g, '$1$2$3|$2$4');
// regex(/(\|)(Business Day|City Press|Daily News|Daily Voice|Independent Online|New Age|Post|Table Talk|The Citizen|The Mercury|The New Age|The Star|The Sunday Independent|The Sunday Times|The Times|The Witness|The World)(?: \(South Africa(?:n newspaper|)\))(\]\])/g, '$1$2$3');
regex(/(''\[\[)(Nature|Science)(\]\]'')/g, '$1$2 \(journal\)|$2$3');
regex(/(''\[\[)(Salon)(\]\]'')/g, '$1$2 \(website\)|$2$3');
// removing redundancies
regex(/\|[ ]?language[ ]?\=[ ]?English[ ]*?(?=[\|\}])/gi, ''); //note: adjusted for false positive in infoboxes books
regex(/- [\w]*\.com[ ]*\|/gi, '|');
regex(/(.) – Google [^ \]]*(\][\.,;]) Books\.google\.\w{2,3}(\.| )/gi, '$1$2Google Books$3');
regex(/(.) at Discogs(\][\.,;]) Discogs\.com(\.| )/gi, '$1$2Discogs$3');
regex(/\|\s?author\s?\=(?:posted|publishe[dr]|written)\s?(?:by|on)\s/gi, '|author=');
regex(/\|\s?(?:work|publisher)(\s?\=MTV)\|\s?publisher\s*\=\s*(?:MTV Networks|Viacom)/gi, '|publisher$1=');
regex(/\|\s?(?:publisher|work)\s*\=\s*(?:BBC|BBC News(?: Online|))\s*(\|[^}<>]*|)\|\s?publisher\s*\=\s*(?:BBC|BBC News(?: Online|)|British Broadcasting Corporation)(?=[\s\.]*[\|\}])/g, '|publisher=BBC News $1');
regex(/\|\s?(?:publisher|work)\s*\=\s*(BBC Sports?)\s*(\|[^}<>]*|)\|\s?publisher\s*\=\s*(?:BBC|BBC News(?: Online|)|British Broadcasting Corporation)(?=[\s\.]*[\|\}])/g, '|publisher=$1$2');
// removing publishers less well-known than their titles
regex(/(\|\s?work\s*\=\s*(?:Time|People)\s*(?:\|[^}<>]*|))\|\s?publisher\s*\=\s*Time (?:Warner ?|)Inc.?(?=[\s\.]*[\|\}])/g, '$1');
regex(/(\|\s?work\s*\=\s*(?:\[\[|)The New York Times(?:\]\]|)\s*)(\|[^}<>]*|)\|\s?publisher\s*\=\s*The New York Times Company(?=[\s\.]*[\|\}])/g, '$1');
regex(/(\|\s?work\s*\=\s*(?:\[\[|)The (?:Daily Telegraph|Guardian)(?:\]\]|)\s*(?:\|[^}<>]*|))\|\s?publisher\s*\=\s*(?:\[\[|)(?:Telegraph|Guardian) Media Group(?:\]\]|)(?=[\s\.]*[\|\}])/g, '$1');
regex(/(\|\s?publisher\s?\=MTV\|\s?)publisher\s*\=\s*(?:MTV Networks|Viacom)/gi, '$1=');
regex(/(?:\|publisher=Turner Sports Interactive, Inc)\.? ?\|publisher=(NBA)(?= ?\|)/gi, '$1');
regex(/(\|publisher=NBA) ?\|publisher=(?:Turner Sports Interactive, Inc)\.?(?= ?\|)/gi, '$1');
//per [[Help:Citation Style 1#Elements not included]]
regex(/(?:-[ ]*Google Books[ ]*(\|[^}]*|)|)\|\s?publisher\s*\=\s*Google Books(?=[\s\.]*[\|\}])/g, '');
regex(/\|\s?publisher\s*\=\s*(?:Project Gutenberg|Scribd)(?=[\s\.]*[\|\}])/g, '');
// removing identical/similar entries in 'work' and 'publisher'
regex(/\|\s?work\s*\=\s*([^\|\}<>]*)(\s?\|[^}<>]*|)\|\s?(?:publisher|work)\s*\=\s*\1(?:\.com|)(?=[\s\.]*[\|\}])/g, '|work=$1$2');
regex(/\|\s?work\s*\=\s*([^\|\}<>]*)(?:\.com|)(\s?\|[^}<>]*|)\|\s?(?:publisher|work)\s*\=\s*\1(?=[\s\.]*[\|\}])/g, '|work=$1$2');
regex(/\|\s?work\s*\=\s*\[\[([^\|\}<>]*)\]\](\s?\|[^}<>]*|)\|\s?(?:publisher|work)\s*\=\s*\1(?:\.com|)(?=[\s\.]*[\|\}])/g, '|work=[[$1]]$2');
regex(/\|\s?work\s*\=\s*([^\|\}<>]*)(?:\.com|)(\s?\|[^}<>]*|)\|\s?(?:publisher|work)\s*\=\s*\[\[\1\]\](?=[\s\.]*[\|\}])/g, '|work=$1$2');
regex(/\|\s?publisher\s*\=\s*([^\|\}<>]*)(\s?\|[^}<>]*|)\|\s?(?:publisher|work)\s*\=\s*\1(?:\.com|)(?=[\s\.]*[\|\}])/g, '|publisher=$1$2');
regex(/\|\s?publisher\s*\=\s*([^\|\}<>]*)(?:\.com|)(\s?\|[^}<>]*|)\|\s?(?:publisher|work)\s*\=\s*\1(?=[\s\.]*[\|\}])/g, '|publisher=$1$2');
regex(/\|\s?publisher\s*\=\s*\[\[([^\|\}<>]*)\]\](\s?\|[^}<>]*|)\|\s?(?:publisher|work)\s*\=\s*\1(?:\.com|)(?=[\s\.]*[\|\}])/g, '|publisher=[[$1]]$2');
regex(/\|\s?publisher\s*\=\s*([^\|\}<>]*)(?:\.com|)(\s?\|[^}<>]*|)\|\s?(?:publisher|work)\s*\=\s*\[\[\1\]\](?=[\s\.]*[\|\}])/g, '|publisher=$1$2');
regex(/\|\s?___location\s*\=\s*New York(?: City|)\s*(\|[^}<>]*|)\|\s?___location\s*\=\s*(New York(?: City|)|USA)(?=[\s\.]*[\|\}])/g, '|___location=New York $1');
regex(/(?:\|[ ]*?___location=[^\[\]\|]*)(\|[ ]*?___location=[^\[\]\|\}]*)(?=[\|\}])+/gi, '$1');
regex(/(\|[ ]*?publisher=[^\[\]\|]*)(?:\|[ ]*?publisher=[^\[\]\|\}]*)(?=[\|\}])+/gi, '$1');
regex(/(\|[ ]*?work=[^\[\]\|]*)(?:\|[ ]*?work=[^\[\]\|\}]*)(?=[\|\}])+/gi, '$1');
regex(/(\|[ ]*?author=)(?:(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day,? ?)(?=[^\]\|\}]*\|)/gi, '$1');
regex(/( | [\w, ]*?)(?=[ ]|)/gi, '');
// regex(/( \| [^=\|\{\}\]]*?)(?=[ ]\|)/gi, ''); //disabled 3 October 2012 - false positive removal of elements in wikitable
regex(/( | News)(?=[ ]?[&\|])/gi, '');
regex(/( | (?:Football|Latest)(?: News|))(?=[ ]?[&\|])/gi, '');
regex(/\|\s?title\s*\=\s*BBC (?:News|Sport)\s?(?:–|| )\s?/gi, '|title=');
regex(/(DOC|PDF)\) \./gi, '$1).');
// removing artefacts (outside of citation templates)
regex(/([\w]+\'\')\.(?:co(?:m|m?\.\w{2})|\.\w{2})[ ]/gi, '$1. ');
//dynamic columns for reflists; remove scroll bar
regex(/(={2,4}[\n\r])[\r\n\s]*(?:<div class="\w*" [^>]*)>([\S\s]*)<\/div>/g, '$1$2');
regex(/(?:\{\{[Rr]eflist\}\}|<[Rr]eferences ?\/>)/g, '{{reflist|colwidth=30em}}');
}
function Ohc_sourceunlink() {
var txt=document.editform.wpTextbox1;
//removal of all links from sources
//rem linking within citation template parameters
regex(/(\|[ ]*?(?:author|agency|publisher|journal|newspaper|periodical|work)=[ ]*?)\[\[([^\|\]]+?)\]\](?:(,? )\[\[([^\|\]]+?)\]\]|)([ ]{0,1})/gi, '$1$2$3$4$5');
regex(/(\|[ ]*?(?:author|agency|publisher|journal|newspaper|periodical|work)=[ ]*?)\[\[(?:[^\|\]]+?\|)([\w\s\,]+?)\]\](?:(,? )\[\[([^\|\]]+?)\]\]|)([ ]{0,1})/gi, '$1$2$3$4$5');
//rem other linking within refs tags
regex(/(<ref[^>]*>[^<]+?[\]\.,;]\s+)\[\[(?:[^\|\]<]*\||)([^\|\]<]*)(?: online|)\]\]([^<]*?<\/ref>)\) \./gi, '$1$2$3).');
regex(/(<ref[^>]*>[^<]+?[\]\.,;]\s+\'\')\[\[(?:[^\|\]<]*\||)([^\|\]<]*)(?: online|)\]\](\'\'[^<]*?<\/ref>)\) \./gi, '$1$2$3).');
}
/** ------------------------------------------------------------------------ **/
/// PROTECTION BY STRING SUBSTITUTION
var linkmap=[];
function ohc_protect_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(/(<ref[^>]*?>)(.*?)(<\/ref>)/gi, protect_function);
regex(/(\*[ ]?\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
}
function ohc_unprotect_linkspam()
{
//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;
});
}
var linkmap=[];
function ohc_protect_urls()
{
// protects only urls
// 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(/(https?:|ftp:)([^\]\|]*)([\]\|])/gi, protect_function);
regex(/(\{\{cite ?book\s?\|)([^\}]+)(\})/gi, protect_function);
}
function ohc_unprotect_urls()
{
//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_Source_edit_summary(){
//Add a tag to the summary box
setoptions(minor='true');
setreason('per [[Help:Citation Style 1]] by [[User:Ohconfucius/script/Sources|script]]', 'append');
doaction('diff');
}
function Ohc_linkspam_driver() {
var txt=document.editform.wpTextbox1;
ohc_protect_linkspam();
Ohc_linkspam();
ohc_unprotect_linkspam();
setreason('rem [[WP:Linkspam|linkspam]]', 'append');
}
function Ohc_ref_format_new() {
var txt=document.editform.wpTextbox1;
ohc_protect_urls();
Ohc_sources_prep();
Ohc_unpipe();
Ohc_dab_news_sources();
Ohc_sourcename();
Ohc_sourcework();
Ohc_sourcepub();
Ohc_sourceagency();
Ohc_redo_pipe();
Ohc_sources_cleanup();
ohc_unprotect_urls();
Ohc_Source_edit_summary();
}
function Ohc_ref_format_driver() {
var txt=document.editform.wpTextbox1;
Ohc_ref_format();
Ohc_Source_edit_summary();
}
addOnloadHook(function () {
if(document.forms.editform) {
// addPortletLink('p-tb', 'javascript:function_name()', 'Button name', 't-dmy', 'Hover text', '', '');
addPortletLink('p-tb', 'javascript:Ohc_linkspam_driver()', 'Linkspam', 'rm-linkspam', 'removes linkspam in running text', '', '');
addPortletLink('p-tb', 'javascript:Ohc_ref_format_driver()', 'Fix news sources', 't-citefix', 'format citations', '', '');
addPortletLink('p-tb', 'javascript:Ohc_publishers()', 'Rem publishers', 't-citefix', 'Removing certain publishers fields', '', '');
// addPortletLink('p-tb', 'javascript:Ohc_sourcename()', 'Align source name', 't-citefix', 'Corrects source name – subscript1', '', '');
// addPortletLink('p-tb', 'javascript:Ohc_sourcework()', 'Cleanup WORK', 't-citefix', 'Cleanup and reclassifies as WORK – subscript2', '', '');
// addPortletLink('p-tb', 'javascript:Ohc_sourcepub()', 'Cleanup publisher', 't-citefix', 'Cleanup and reclassifies as PUBLISHER – subscript2', '', '');
// addPortletLink('p-tb', 'javascript:Ohc_sources_cleanup()', 'Final cleanup', 't-citefix', 'Cleanup after script actions', '', '');
addPortletLink('p-tb', 'javascript:Ohc_sourceunlink()', 'Unlink source name', 't-citefix', 'Unlinks source', '', '');
addPortletLink('p-tb', 'javascript:Ohc_ref_format_new()', 'Fix sources', 't-citefix', 'Run entire new module', '', '');
}
});