Jump to content

User:Ohconfucius/test/Sources subscript3.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function Ohc_redo_pipe(){

// repiping ambiguous links created - magazines
	var table = [
		'(Ability|Above|Above&Beyond|Absolute Magnitude|Acoustic|Acoustic Guitar|Ad Astra|Adventure|Adventure Gaming|Aerial|Aerie|African Film|After Dark|Afterimage|Aggregation|Aircraft Recognition|Airliners|Al Bayan|Al Fatat|Al Yamamah|Al-Arabi|Alarm|Alaska|Album|Alcheringa|Algol|Al-Hilal|Alive|Al-Khansaa|Alligator Juniper|Allure|Al-Manar|Alpinist|Alter Ego|Alula|Amandla|Amateur Gardening|Ambit|America|American Digger|American Health|American Heritage|American Renaissance|American Way|Amerika|Amina|Amusement|Anarchy|Ancient Egypt|Ancient Warfare|Animation|Answer Me!|Antaeus|Antic|Antiques|Äntligen Hemma|Aperture|Apollo|Araragi|Arcadia|Archaeology|Architecture|Archive|Arena|Argia|Argo Navis|Argosy|Arkangel|Armadillo|Armor|Army Man|Art of the West|Artes|Arthur|Artrocker|Ascent|Aspen|Astronomy|Atalanta|Atlanta|Atlántica|Atlántida|Atlas|Atomic|Attitude|Audience|Audio|AudioFile|Audrey|Audubon|Australian Aviation|Automobile|Automotive Industries|Avant Garde|Avenue|AVN|Azari|Azure)',
		'(Backbone|Bent|Billboard|Blender|Boards|Bomb|Border Crossings|Boxoffice|Brainstorm|Brick|British Birds|Broadcast|BRW|Building|Business Matters|Business Plus|Byte)',
		'(Campaign|Cashbox|CFO|Chapman|Chief Executive|Civil Lines|Clash|Clear|Close Up|Closer|Clutch|CODA|Colors|Computer|Contagious|Contemporary|Continuum|Control Engineering|Converting|Cosmopolitan|Cracked|Creative Nonfiction|Creativity|Cricket|Curve)',
		'(Dazed & Confused|Descant|Destiny|Develop|Diesel Power|DineroDazed & Confused|Descant|Destiny|Develop|Diesel Power|Dinero)',
		'(Entrepreneur|Ebony|Elle|Emergency Nurse|Empire|Engineering|Esquire|Essence|Ethos|Exame|Expert)',
		'(Facta|Fairplay|Fanfare|Fantastic Man|Fast Car|Field Artillery|Filmmaker|Fire Chief|Flaunt|Flying|Food Technology|Format|Fortune|frieze|Frontline|Futures|FX)',
		'(Game Developer|Gangway|Geist|Gemini|Glamour|Global Finance|Goldenseal|Good Morning|Grain|Gramophone|Grooves|Gyro)',
		'(Habitat|Hazards|Hello|Hotels|I\\.D\\.|Imagination|In the Family|Inc\\.|Industrial Minerals|Innovation|Inside Golf|Inspire|Intelligent Enterprise|Interview|Investigate|Investment Advisor)',
		'(Jazz At Ronnie Scott\'s|Jet|Jp)',
		'(Kawanku|Klan|Kmt|Kurmanci)',
		'(Latino Money|Liberty|Life|Life & Style|Light Metal Age|Limelight|Links|Lobster|Logistics Management)',
		'(Marg|Marketing|Marmalade|Maxim|Mix|Mojo|Money|Ms\\.|Muse|Musician)',
		'(National Geographic|National Lampoon|Naval Review|Nerve|Nest|Newsline|New Moon|New South|Nightshift|No Compromise|New York|Nuts)',
		'(Opera|Optimize|Opus|Outlook|Overload)',
		'(Pageant|Parabola|Parade|Parent(?:ing|)|Paste|Peer Review|People|Performance Car|Plan|Poetry|Polite|Preservation|Prevention|Primary Health Care|Proceedings|Profit|Prospect|Purchasing|Purple|Putt)',
		'(Q|R&R|Radio|Ray|Reason|Revolution|Rubbish)',
		'(Safeguard|Sales Promotion|Science|Security Management|Sha[pv]e|Shook|Slate|Smallholder|Sounds|Southeast Asia Building|Spectroscopy|Speech Technology|Spin|Sport|Standpoint|Stern|Straight No Chaser|Strategie|Sunstone|Supply Management|SWA|Swindle)',
		'(Taxation|Time|Time Out|Top Gear|Travel Agent|Trend|Trouble|Trust|TWX)',
		'(The (?:Accountant|Antiquary|Artist|Believer|Business|Common|Current|Cut|Deal|Engineer|Executive|Fly|Music Trades|Rebel|Reporter))',
		'(Uncut|Upside|Vanity Fair|Variant|Variety|Venture|Vibe|Village|Vogue|Vs\\.|Waters|Wired|Wood|Worth)',
	];
 
	for (i=0; i<table.length; i++) {
		var expr = [
			['(<ref[^>]*>[^<]+?\\s\'\'\\\[\\[)',				'(\\]\\]\'\'(?:[^\\w ][^\\]<]*?|)<\\/ref>)'],
			['((?:journal|newspaper|periodical|work)\\s*=\\s*\\[\\[)',			'(\\]\\][\\s]*[\\|\\}])'],

		];
		for (j=0; j<expr.length; j++) {
			var re = new RegExp(expr[j][0] + table[i] + expr[j][1], 'g')
			regex(re, '$1$2 \(magazine\)|$2$3')
		}
	}
         regex(/((?:journal|newspaper|periodical|work)\s*=\s*\[\[)(Nature|Science)(\]\])/g, '$1$2 (journal)|$2$3'); 
         regex(/(''\[\[)(Nature|Science)(\]\]'')/g, '$1$2 (journal)|$2$3');
         regex(/((?:journal|newspaper|periodical|work)\s*=\s*\[\[)(Salon)(\]\])/g, '$1$2 (website)|$2$3'); 
         regex(/(''\[\[)(Salon)(\]\]'')/g, '$1$2 (website)|$2$3');
         regex(/((?:journal|newspaper|periodical|work)\s*=\s*\[\[)(Marca|Spits)(\]\])/g, '$1$2 (newspaper)|$2$3'); 
         regex(/(''\[\[)(Marca|Spits)(\]\]'')/g, '$1$2 (newspaper)|$2$3');

         regex(/((?:publisher)\s*=\s*\[\[)(Bloomberg)(\]\])/g, '$1$2 L.P.|$2$3'); 
//         regex(/(\[\[)(Bloomberg)(\]\])/g, '$1$2 L.P.|$2$3');


}
function Ohc_unpipe(){
 
 
//undo awkward or unnecessary piped links – replaces piping with direct output string
	var table = {
//		'Foobar,? Inc(?:orporated|\\.|)':	'Foobar Inc.', 
//		'(?:Foobar,? Inc(?:orporated|\\.|))':	'Foobar Inc.', 
 
		'(?:(?:the |)(?:daily |london |)|www\\.|)times(?:online\\.co\\.uk| online| newspaper| \\((?:newspaper|uk|united kingdom)\\)|)':	'The Times',
		'(?:(?:the |)(?:daily |london |)|www\\.|)(?:telegraph|torygraph)(?:\\.co\\.uk| online| newspaper| \\((?:newspaper|uk|united kingdom)\\)|)':	'The Daily Telegraph',
		'Belfast ?(?:Telegraph|telegraph\\.co\\.uk)':	'The Belfast Telegraph', 
 
		'(?:(?:the |)(?:daily |london |manchester |)|www\\.|media ?|education ?|)(?:guardian|grauniad)(?:\\.co(?:m|\\.uk)| unlimited| newspaper| \\((?:newspaper|uk|united kingdom)\\)|)':	'The Guardian',
		'(?:(?:the |www\\.|)(?:New ?York ?|ny ?))times(?:\\.com| \\((?:ny|new york)\\)|)':	'The New York Times',
		'Time,? Inc(?:orporated|\\.|)':	'Time Inc.',
 
		'(?:la ?times(?:\\.com|)|L\\. ?A\\. Times)':			'Los Angeles Times',
		'(?:the ?|)Los Angeles Times':				'Los Angeles Times',
		'(?:chicago ?|)sun[ -]?times(?:\\.com|)':			'Chicago Sun-Times',
		'chicagotribune(?:\\.com|)':					'Chicago Tribune',
		'miami ?herald(?:\\.com|)':					'The Miami Herald',
		'(?:chron|houstonchronicle)(?:\\.com|)':			'Houston Chronicle',
		'(?:sf ?gate|SF ?Chronicle)(?:\\.com|)':				'San Francisco Chronicle',
		'denver ?post(?:\\.com|)':					'The Denver Post',
		'contracostatimes(?:\\.com|)':					'Contra Costa Times',
		'freep(?:\\.com|)':						'Detroit Free Press',
		'newsday(?:\\.com|)':						'Newsday',
		'insidebayarea(?:\\.com|)':					'Oakland Tribune',
		'philly\\.com':						'Philadelphia Daily News',
		'mercurynews(?:\\.com|)':					'San Jose Mercury News',
		'(?:seattle ?)pi(?:\\.com|)':			'Seattle Post-Intelligencer',
		'(?:the ?|)(?:seattle |)post[- ]intelligencer':			'Seattle Post-Intelligencer',
		'startribune(?:\\.com|)':					'Star Tribune',
		'tampabay(?:times|)(?:\\.com|)':				'Tampa Bay Times',
		'(?:azcentral|az ?republic)(?:\\.com|)':			'The Arizona Republic',
		'dallasnews(?:\\.com|)':					'The Dallas Morning News',
		'oregonlive(?:\\.com|)':					'The Oregonian',
		'philly\\.newspaperdirect\\.com':				'The Philadelphia Inquirer',
		'(?:cleveland(?:\\.com)|plain ?dealer)':			'The Plain Dealer',
		'(?:(?:sandiegouniontribune|signonsandiego|utsandiego)(?:\\.com|)|(?:the |)San Diego Union[- ]Tribune)':		'The San Diego Union-Tribune',
		'seattle ?times(?:\\.com|)':					'The Seattle Times',
		'nj(?:\\.com)':						'The Star-Ledger',
		'usatoday(?:\\.com|)':						'USA Today',
		'(?:Christian ?Science ?Monitor|csmonitor)(?:\\.com|)':		'The Christian Science Monitor',
		'Christian ?post(?:\\.com|)':					'The Christian Post',
 
		'smh(?:\\.com\\.au|)':						'Sydney Morning Herald',  
		'The Sydney Morning Herald':						'Sydney Morning Herald',  
		'theage(?:\\.com\\.au|)':					'The Age',
		'theaustralian(?:\\.com\\.au|)':				'The Australian',
		'canberra ?times(?:\\.com\\.au|)':				'The Canberra Times',
		'(?:the ?|)herald ?sun(?:\\.com\\.au|)':					'Herald Sun',
		'nzherald(?:\\.co\\.nz|\\.com|)':				'The New Zealand Herald',
		'New Zealand Herald':						'The New Zealand Herald',
 
		'(?:(?:the|)globeandmail(?:\\.com|)|globe (?:and|&) mail)':		'The Globe and Mail',
		'(?:the ?|)(?:Toronto |)Globe and Mail':				'The Globe and Mail',
		'(?:the ?|)national ?post(?:\\.com|)':					'National Post',
		'(?:the ?|)ottawa ?citizen(?:\\.com|)':					'Ottawa Citizen',
		'theprovince(?:\\.com|)':					'The Province',
		'thestar(?:\\.com)':						'Toronto Star',
		'the ?toronto ?star(?:\\.com|)':					'Toronto Star',
		'(?:the |)toronto ?sun(?:\\.com|)':					'Toronto Sun',
		'vancouver ?sun(?:\\.com|)':					'The Vancouver Sun',
		'(?:the ?|)Winnipeg ?free ?press(?:\\.com|)':					'Winnipeg Free Press',
 
		'Foobar,? Inc(?:orporated|\\.|)':	'Foobar Inc.'   //placeholder end of file
 
	};
 
	var word, newWord;
	for (var word in table) {
	newWord = '$1' + table[ word ] + '$2';
	newWord3 = '$1\[\[' + table[ word ] + '\]\]$2';
		var txt="";
		try {
		//  source names that are agencies - linked  –>unlinked
			var re = new RegExp('([ ]*=[ ]*\\[\\[)' + word + '(?:\\|[^\\]]*)(\\]\\][\\s\\.]*[\\|\\}])', 'gi');
			regex( re, newWord );
 
		//  unitalicise agency name - unlinked
			var re = new RegExp('(<ref[^>]*>[^<]+?\\s\'\')\\[\\[' + word + '\\|[^\\]]*\\]\\](\'\'(?:[^\\w ][^\\]<]*?|)<\\/ref>)', 'gi');
			regex(re, newWord3); //NOTE: adaptation to linked sources and relink is built into 'newWord3'
 
		}
		catch(err) {
			txt="There was an error on function Ohc_undo_piped(), when changing '"+ word + "' => '"+ table[word] +"'.\n\n";
			txt+="Error: " + err.message + "\n\n";
			txt+="Click OK to continue.\n\n";
			alert(txt);
		}
	}

 
//undo awkward or unnecessary piped links – replaces piping with direct output string
	var table = {
//		'Foobar,? Inc(?:orporated|\\.|)':	'Foobar Inc.', 
//		'(?:Foobar,? Inc(?:orporated|\\.|))':	'Foobar Inc.', 

		'Haymarket (?:(?:Media |)Group|Media|Press|Publishing)':		'Haymarket Media Group',
		'pc ?world(?:\\.com| magazine| \\(magazine\\)|)':			'PC World',
		'Formula ?(?:1|One)(?:\\.com| Group| Administration)':			'Formula One',
		'The ?verge(?: \\(website\\)|\\.com)':			'The Verge',

		'aap(?:\\.com\\au|)':			'Australian Associated Press',
		'(?:ap(?:\\.org|\\.com|)|(?:The ?|)Associated Press)':	'Associated Press',
		'(?:afp(?:\\.com|)|Agence France[- ]Presse?)':	'Agence France-Presse',
		'kyodo ?news(?:\\.com|\\.jp|)':			'Kyodo News',
		'pressassociation(?:\\.com|)':			'Press Association',
		'pr ?newswire(?:\\.com|)':			'PR Newswire',
		'dpa(?:\\.com|)':				'Deutsche Presse-Agentur',
		'maan ?news(?: ?agency|)(?:\\.net|)':	'Ma\'an News Agency',
		'reuters(?:\\.com|)':				'Reuters',
		'(?:rian(?:\\.com|\\.ru|)|RIA ?Novosti)':	'RIA Novosti',
		'(?:Syrian Arab News Agency|sana\\.sy)':	'Syrian Arab News Agency',
		'upi(?:\\.com|)':				'United Press International',
		'xinhua(?:(?:net|)\\.com|\\.com\\.cn|)':		'Xinhua News Agency',

		'Foobar,? Inc(?:orporated|\\.|)':	'Foobar Inc.'   //placeholder end of file

	};
 
	var word, newWord;
	for (var word in table) {
	newWord = '$1' + table[ word ] + '$2';
	newWord3 = '$1\[\[' + table[ word ] + '\]\]$2';
    		var txt="";
		try {
		//  source names that are agencies - linked  –>unlinked
			var re = new RegExp('([ ]*=[ ]*\\[\\[)' + word + '(?:\\|[^\\]]*)(\\]\\][\\s\\.]*[\\|\\}])', 'gi');
			    regex( re, newWord );
 
		//  unitalicise agency name - unlinked
			var re = new RegExp('(<ref[^>]*>[^<]+?\\s)\'\'\\[\\[' + word + '\\|[^\\]]*\\]\\]\'\'((?:[^\\w ][^\\]<]*?|)<\\/ref>)', 'gi');
			regex(re, newWord3); //NOTE: adaptation to un-italicise linked sources and relink is built into 'newWord3'
 
		}
		catch(err) {
			txt="There was an error on function Ohc_undo_piped(), when changing '"+ word + "' => '"+ table[word] +"'.\n\n";
			txt+="Error: " + err.message + "\n\n";
			txt+="Click OK to continue.\n\n";
			alert(txt);
		}
	}
}

$(function () {
 if(document.forms.editform) {
//  mw.util.addPortletLink('p-tb', 'javascript:function_name()', 'Button name', 't-dmy', 'Hover text', '', '');
 
//  mw.util.addPortletLink('p-tb', 'javascript:Ohc_redo_pipe()', 'Redo pipe', 't-citefix', 'Reconstruct source pipes – subscript3', '', '');
  mw.util.addPortletLink('p-tb', 'javascript:Ohc_unpipe()', 'Unpipe', 't-citefix', 'Undo awkward source pipes – subscript3', '', '');
  }
});