User:Ohconfucius/script/Sources.js: Difference between revisions

Content deleted Content added
bug fix
align to test script
Line 8:
 
importScriptURI('//meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');
importScript("User:Ohconfucius/script/MOSNUM_utils.js"); //needed for "'Accessed' -> 'Retrieved'"
 
importScript("User:Ohconfucius/test/Sources_subscript1.js"); //convert ___domain names into article names
importScript("User:Ohconfucius/test/Sources_subscript2.js"); //Correctly casing titles and apply or rem italicisation
importScript("User:Ohconfucius/test/Sources_subscript3.js"); //link-fixing, dabbing etc
importScript("User:Ohconfucius/script/foreigndates.js"); //link-fixing, dabbing etc
 
function Ohc_add_ref_tags() {
Line 21:
 
}
 
function Ohc_fill_pub_with_domain() {
var txt=document.editform.wpTextbox1;
//test
regex(/\s?(<ref>(?:[^<>]*\|\s*url\s*=|\[?)https?:\/\/((?:\w+\.)*\w+(?:\.(?:com?|org|net|)(?:\.[a-z]{2}|)))\/[^<>{}]+\|publisher=)(?=}}<\/ref>)/gi, "$1$2"); //capture ___domain name to add to publisher
regex(/(\|\s?(?:publisher|website)\s*\=\s*)w{3}\.(\w+\.(?:Project Gutenbergcom?|Proquestorg|Scribdnet|web)(?:\.archive\[a-z]{2}|citation).org)(?=[\s\.]*[|}])/ggi, '$1$2');
regex(/(\|\s?publisher=)\s?\|\s?via\s*\=\s*(\w+)(?=\s*[|}])/gi, '$1$2');
// regex(/\|\s?via\s*\=\s*/gi, '|work=');
regex(/\s?[-–]\s?(?:The |)(\w+\.(?:com?|org|net|)(?:\.[a-z]{2}|))\s?(\|\s?publisher\s*\=\s*)\1(?=}})/gi, '$2$1');
regex(/(\s?:-[ -–]*Google Books[ ]*\s?(\|[^}|]*|)|+)\s?(\|\s?publisher\s*\=\s*Google)(The Books)\1(?=[\s\.]*[|}]})/ggi, '$2$3$1');
regex(/\|\s?first\s*\=[^|]*\|\s?last\s*\=(?:Editor|Group|Staff|Reporter|Writer)\s*(?=\|)/gi, '');
regex(/({{Navbox deaths}})(\n)/gi, '==References==$2{{Reflist}}$2$1$2');
regex(/(==References==\n{{Reflist}}\n)\n?\1/gi, '$1');
 
}
 
 
function Ohc_remove_urls() {
Line 35 ⟶ 51:
 
// removing references to other WP articles and 'external' WP links
regex(/<ref[^<>]*>[^<>]*\|[ ]*url ?=https?:\/\/\w{2}\.wikipedia\.org\/wiki\/w[^<>]*<\/ref>/gi, '{{cn}}<!-- WP:RS needed; removed link to WP-->');
regex(/<ref>\s*https?:\/\/\w{2}\.wikipedia\.org\/wiki\/[^\s\]<]*<\/ref>/gi, '{{cn}}<!-- WP:RS needed; removed link to WP-->');
regex(/<ref>\s*\[https?:\/\/\w{2}\.wikipedia\.org\/wiki\/w[^\s\]]*[ ]+[\w\d][^\]]*\]<\/ref>/gi, '{{cn}}<!-- WP:RS needed; removed link to WP-->');
regex(/<ref(?: name=[^<>]|)>[^<>]*\|\s*url[ ]*=[ ]*https?:\/\/\w{2}\.wikipedia\.org\/wiki\/w[^\s\|\{\}<]*(?=[ ^<>]*[|}])<\/ref>/gi, '{{cn}}<!-- WP:RS needed; removed link to WP-->');
regex(/[ ]\[https?:\/\/\w{2}\.wikipedia\.org\/wiki\/w[^\s\]]*[ ]+([\w][^\]]*)\]/gi, ' [[$1]]');
 
regex(/(<ref[^<>]*>[^<>]*\|[ ]*url ?=https?:\/\/(?:(?:www\.|)(?:facebook|myspace|twitter|mailonline|findagrave)\.com|dailymail\.co\.uk)\/[^<>]*)(<\/ref>)/gi, '$1{{Primary source inline}}$2');
Line 48 ⟶ 64:
regex(/(\|\s?url\s*\=\s*)(https?:[^|{}#\s]+\.html?)\?[^|}]{1,5}(?=[\s\[\]|{}<>])/gi, '$1$2'); //rem link tracking
regex(/(\|\s?url\s*\=\s*|\[)(https?:\/\/books\.google\.[^\/]+\/books\?id=\w{12}&pg=PA\d{1,3})&dq[^\s|}]+(?=\s?[|}])/gi, '$1$2'); //rem browser optimisation
 
 
}
Line 64 ⟶ 81:
regex(/(\|\s?volume\s*\=\s*)vol(?:ume|\.?)[ ]*(\d)/gi, '$1$2');
regex(/(\|\s?pages?\s*\=\s*)(?:pages?|p[gp]?\.?)[ ]*(\d)/gi, '$1$2');
regex(/ [-–] (?:每日明報 daily news|東方日報)/gi, '');
regex(/(\|\s?title\s*\=\s*)Login ?(?=[|}\n])/gi, '$1ACTUAL ARTICLE TITLE BELONGS HERE');
regex(/(\|\s?publisher=)\|\s(?via\s*\:publisher|website|work)=\s*You ?tube(?:\w+.com|)(?=\s*[|}])/gi, '$1$21via=YouTube');
// regex(/(\|\s?via)(?:publisher|website|work)=(Amazon)(?:\s*.com|)(?:\.\w{2}|)(?=\s*[|}])/gi, '|work$1via=$2');
regex(/(\|\s?)(?:publisher|website|work)=(Vimeo)(?:\.com|)(?=\s*[|}])/gi, '$1via=$2');
regex(/(\|\s?publisher=)\|\s?via\s*\=\s*(\w+)(?=\s*[|}])/gi, '$1$2');
regex(/(?:-[ ]*Google Books[ ]*(?:\|[^}]*|)|)\|\s?publisher\s*\=\s*(Google Books)(?=[\s\.]*[|}])/g, '|via=$1');
// regex(/(\|\s?)(?:publisher|website|work)=books\.google(?:\.com?|.co\.uk|)(?=\s*[|}])/gi, '|via=Google Books');
// regex(/\|\s?(?:publisher|website|work)=(British Newspaper Archive|Google Books|Project Gutenberg|Proquest|Scribd|web(?:\.archive\|citation)(?:\.org|))(?=\s*[|}])/gi, '|via=$1');
 
//Remove COinS corrupting templates from CS1 citations
regex(/(\|\s?(?:authors?|first\d?|last\d?|publisher|work)\s*\=\s*(?:[^{}|]*|)){{(?:Sm|Aut|SC|Small[- ]caps|Sm?caps)\|([^{}|]*)}}(?=(?:[^{}|]*|)[|}])/gi, '$1');
Line 126 ⟶ 148:
 
// adjust for possibly incorrectly input title
// regex(/(\|\s?title\s*\=\s*)([^\|\}<>]*)(\s?\|[^}<>]*|)\|\s?(publisher|work)\s*\=\s*(?:\1|\[\[\1\]\])(?=\s*[|}])/g, '$1ACTUAL ARTICLE TITLE BELONGS HERE! |$4=$2$3');
// regex(/(\|\s?title\s*\=\s*)(\w+\.com)(?=\s?[=|{}])/gi, '$1ACTUAL ARTICLE TITLE BELONGS HERE! |publisher=$2');
// rem misplaced punctuation
Line 158 ⟶ 180:
// removing english language parameters
regex(/[ ]?\{\{en[- ]icon\}\}/gi, "");
regex(/\|[ ]*?language[ ]*?=[ ]*?en(?:-\w{2}|glish|)(?=[\s\}|]+)/gi, "");
regex(/(\|[ ]*?language[ ]*?=[ ]*?)\{\{(\w{2})(?:[- ](?:icon|UK|GB|US)|)\}\}/gi, ""); // removing icon template from within "|language=" parameter
 
Line 235 ⟶ 257:
function Ohc_sources_cleanup() {
var txt=document.editform.wpTextbox1;
 
// 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
Line 245 ⟶ 264:
regex(/(\|)((?:The ?|)[A-Z]\w*(?: [A-Z]\w*|))(?: \((?:South Africa)(?:n newspaper|)\))(\]\])/g, '$1$2$3');
 
regex(/(=[ ]*)(Billboard|FastThe Company|People|Q|Slate|Time Out|WiredAdvertiser) \((?:magazineAdelaide)\)(?=\s[ ]*[|}])/g, '$1|___location=$2$3'); //non-standard code
regex(/('')(Billboard|Fast Company|People|Q|Slate|TimeThe Out|WiredAdvertiser) \(magazine(Adelaide)\)(?='')/g, '$1$3 ($2)'); //non-standard code
regex(/(''\[\[|)(The Advertiser)(?:Billboard|Fast Company|People|Q|Slate|Time Out|Wired) \(magazine(Adelaide)\))(?=\]\]'')/g, '$1$2$4|___location=$3'); //non-standard code
regex(/(\|[\[)(Billboard|FastThe Company|People|Q|Slate|Time Out|WiredAdvertiser)(?: \(magazine(Adelaide)\))(?=\]\])/g, '$1$2$3|$2$5|___location=$4');
regex(/(=[ ]*)(Billboard|Campaign|Fast Company|People|Q|Slate|Time(?: Out|)|Wired) \((?:magazine)\)(?=\s*[|}])/g, '$1$2'); //non-standard code
regex(/('')(Billboard|Campaign|Fast Company|People|Q|Slate|Time(?: Out|)|Wired) \(magazine\)(?='')/g, '$1$2'); //non-standard code
regex(/(''\[\[(?:Billboard|Campaign|Fast Company|People|Q|Slate|Time(?: Out|)|Wired) \(magazine\))(?=\]\]'')/g, '$1|'); //non-standard code
regex(/(\|)(Billboard|Campaign|Fast Company|People|Q|Slate|Time(?: Out|)|Wired)(?: \(magazine\))(?=\]\])/g, '$1$2');
regex(/(=[ ]*)(Quartz) \((?:publication)\)(?=\s*[|}])/g, '$1$2'); //non-standard code
regex(/('')(Quartz) \(publication\)(?='')/g, '$1$2'); //non-standard code
Line 364 ⟶ 387:
regex(/\|\s?(?:publisher|website|work)(\s?\=MTV)\|\s?publisher\s*\=\s*(?:MTV Networks|Viacom)/gi, '|publisher$1=');
 
regex(/\|\s?(?:publisher|website|work)\s*\=\s*(?:BBC|BBC News(?: Online|))\s*(\|[^}<>]*|)\|\s?publisher\s*\=\s*(?:BBC|BBC News(?: Online|)|British Broadcasting Corporation)(?=[\s\.]*[|}])/g, '|publisherwork=\'\'BBC News\'\' $1');
regex(/\|\s?(?:publisher|website|work)\s*\=\s*(BBC Sports?)\s*(\|[^}<>]*|)\|\s?publisher\s*\=\s*(?:BBC|BBC News(?: Online|)|British Broadcasting Corporation)(?=[\s\.]*[|}])/g, '|publisherwork=\'\'$1\'\'$2');
regex(/\|\s?publisher\s*\=\s*(BBC (?:Sports|News))\s*(?=\|[^}<>]*|)/g, '|work=\'\'$1\'\'');
regex(/\|\s?(?:publisher|website|work)\s*\=\s*(Metacritic|\[\[Metacritic\]\])\s*(\|[^}<>]*|)\|\s?publisher\s*\=\s*(CBS Interactive|\[\[CBS Interactive\]\])(?=[\s\.]*[|}])/g, '|publisher=$1$2');
 
Line 374 ⟶ 399:
 
//per [[Help:Citation Style 1#Elements not included]]
 
regex(/(?:-[ ]*Google Books[ ]*(\|[^}]*|)|)\|\s?publisher\s*\=\s*Google Books(?=[\s\.]*[|}])/g, '');
// toggling domains within |website= parameter
regex(/\|\s?publisher\s*\=\s*(?:Project Gutenberg|Proquest|Scribd|web(?:\.archive\|citation).org)(?=[\s\.]*[|}])/g, '');
regex(/(\|\s?(?:work|website)\s*\=\s*)(\w+\.(?:com?|org|net|)(?:\.[a-z]{2}|))(?=\s*[|}])/gi, '$1\'\'$2\'\'');
 
// reordering 'work' and 'publisher'; reordering 'work' and 'website'
Line 442 ⟶ 468:
regex(/<[Rr]eferences ?\/>/g, '{{reflist}}'); //default
regex(/({{reflist)\|30em([^}]*}})/g, '$1$2');
regex(/({{reflist)\|[23](}})/g, '$1$2');
 
// disambiguating duplicated ref names
Line 536 ⟶ 563:
 
Ohc_Source_edit_summary();
}
 
function Ohc_noverify() {
var txt=document.editform.wpTextbox1;
 
// removing references to other WP articles and 'external' WP links
regex(/<ref[^<>]*>[^<>]*\|[ ]*url ?=https?:\/\/(?:\w{2}\.wikipedia\.org\/wiki|(?:www\.|)(?:facebook|myspace|twitter|mailonline|findagrave)\.com)\/[^<>]*<\/ref>/gi, '');
regex(/<ref>https?:\/\/(?:en\.wikipedia\.org\/wiki|(?:www\.|)(?:facebook|myspace|twitter|mailonline|findagrave)\.com)\/[^\s\]<]*<\/ref>/gi, '');
regex(/<ref>\[https?:\/\/(?:en\.wikipedia\.org\/wiki|(?:www\.|)(?:facebook|myspace|twitter|mailonline|findagrave)\.com)\/[^\s\]]*[ ]+[\w\d][^\]]*\]<\/ref>/gi, '');
regex(/\|[ ]*url[ ]*=[ ]*https?:\/\/(?:\w{2}\.wikipedia\.org\/wiki|(?:www\.|)(?:facebook|myspace|twitter|mailonline|findagrave)\.com)[^\s\|\{\}<]*(?=[ ]*[|}])/gi, '');
 
 
regex(/[ ]\[https?:\/\/en\.wikipedia\.org\/wiki\/[^\s\]]*[ ]+([\w][^\]]*)\]/gi, ' [[$1]]');
 
}
 
Line 547 ⟶ 588:
ohc_regex(/<ref>((?:[^<>]*\|\s*url\s*=|\[?)https?:\/\/(?:[^|]+\.)*(\w+)\.(?:(?:com?|org|net)(?:\.[a-z]{2}|))[^<>|{}]+@YYYY[\/-]?@Month[\/-]?@Day[^<>]*)(?=<\/ref>)/gi, "<ref name=@YYYY@MM@DD$2>$1"); //urls with embedded dates
 
// disambiguating duplicated ref names
regex(/(<ref name=[^/>"]*)><\/ref>/gi, '$1/>');
regex(/(<ref name=[^/>"]*)>([\s\S]*)\1>([\s\S]*)\1>/gi, '$1A>$2$1B>$3$1C');
regex(/(<ref name=[^/>"]*)>([\s\S]*)\1>/gi, '$1A>$2$1B>');
regex(/(<ref name="[^/>]*)">([\s\S]*)\1>/gi, '$1A>$2$1B">');
}
Line 558 ⟶ 594:
e.preventDefault();
}
 
function addLinks() {
 
var add = mw.util.addPortletLink;
$( add('p-tb', '#', 'Add REFTAGS', 's-reftags', 'Insert missing ref tags', '', '') ).click(prevDef).click(Ohc_add_ref_tags);
$( add('p-tb', '#', 'CITE name', 's-citename', 'gives names to all citations', '', '') ).click(prevDef).click(ohc_ref_names);
$( add('p-tb', '#', 'Fill DOMAIN_NAME', 's-domainname', 'imports ___domain names to publisher field', '', '') ).click(prevDef).click(Ohc_fill_pub_with_domain);
$( add('p-tb', '#', 'Unlink source name', 's-unlink', 'Unlinks source', '', '') ).click(prevDef).click(Ohc_sourceunlink);
$( add('p-tb', '#', 'Fix SOURCES', 's-citefix', 'Run entire new module', '', '') ).click(prevDef).click(Ohc_ref_format_new);