User:Ohconfucius/script/Sources.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Ohconfucius/script/Sources. |
// *********************************************************************************************
//This is a test (non-production) script, and may have untested errors. Please exercise due care should you decide to use it.
// *********************************************************************************************
/*************
*** 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');
//unlinking of piped sources to source and location
regex(/(?:author|agency|publisher)(\s?=\s?\[\[(Evening Standard))\|[\w,]*(\]\])/gi, 'work$1$2$3|location=London');
regex(/((?:journal|newspaper|periodical|work)\s?=\s?\[\[(Daily News) \(New York\)\|)(?:[\w, ]*)(\]\])/gi, '$1$2$3 |location=New York');
regex(/(?:author|agency|publisher)(\s?=\s?\[\[(Daily News) \(New York\)\|)(?:[\w, ]*)(\]\])/gi, 'work$1$2$3 |location=New York');
regex(/((?:journal|newspaper|periodical|work)\s?=\s?\[\[(The Sun|Daily Star) \((United Kingdom)\)\|)(?:[\w, ]*)(\]\])/gi, '$1$2$4 |location=$3');
regex(/(?:author|agency|publisher)(\s?=\s?\[\[(The Sun|Daily Star) \((United Kingdom)\)\|)(?:[\w, ]*)(\]\])/gi, 'work$1$2$4 |location=$3');
regex(/((?:journal|newspaper|periodical|work)\s?=\s?\[\[(The Telegraph) \(Calcutta\)\|)(?:[\w, ]*)(\]\])/gi, '$1$2$4 |location=$3');
regex(/((?:author|agency|publisher)\s*\=\s*\[\[(The Telegraph) \(Calcutta\)\|)(?:[\w, ]*)(\]\])/gi, 'work$1$2$4 |location=$3');
regex(/(=[ ]*\[\[)(?:[BE]SPN ?(?:USA|HD|Network|the ocho|\(United States\))|E.S.P.N.|(?:The |)Entertainment (?:and |)Sports Programming Network)(?:\|[\w, ]*)(\]\])/gi, '$1ESPN$2');
regex(/((?:journal|newspaper|periodical|work)\s?=\s?\[\[(Evening Standard)\|)(?:[\w, ]*)(\]\])/gi, '$1$2$3 |location=London');
regex(/(?:author|agency|publisher)(\s?=\s?\[\[(Evening Standard))\|[\w, ]*(\]\])/gi, 'work$1$2$3|location=London');
// regex(/(?:\|\s?(?:work|publisher)\s*\=\s*)(?:\[\[The Pioneer \(Indian newspaper\)\|(The Pioneer)\]\])(?=[\s\.]*[\|\}])/gi, '|work=$1 |location=India'); //
}
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(/(\[\[|\|)(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(/(\[\[|\|)(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|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', '', '');
}
});