User:DeirdreAnne/common.js

/* global $, mw, pathoschild */ importScript('User:Inductiveload/InlinePagenums.js');

importScript('User:Inductiveload/Metadata_form.js');

importScript('User:Inductiveload/Roman numerals.js'); importScript('User:Inductiveload/Running header.js');

importScript('User:Inductiveload/Visibility.js');

// MOST OF THIS IS COPIED STRAIGHT FROM USER:BILLINGHURST/MONOBOOK.JS popupFixDabs=true; /* No idea what this does */ popupAdminLinks=true; /* I'm guessing this is admin specific */

// == THIS AUTOFILLS SOME OF THE PARAMETERS IN THE AUTHOR HEADER == importScript('User:Phe/Author fill.js');

// == THIS SEARCHES FOR WORKS ABOUT THE AUTHOR IN CERTAIN REFERENCES BUT IF THERE AREN'T ANY IT JUST ADDS AN EDIT SUMMARY - IT IS IMPLEMENTED BELOW == importScript('User:Phe/Works about.js');

// == GLOBAL PARAMETERS == /*most from User:Billinghurst/monobook.js - those I don't need I'm keeping as models*/ /*set some global parameters for selection */ //preset variables, REMINDER THAT THESE HAVE UNDERSCORE WORD SEPARATORS for location.href var isUserNS = (-1 != location.href.indexOf("User_talk:")); var isPageNS = (-1 != location.href.indexOf("Page:")); var isAuthorNS = (-1 !== location.href.indexOf("Author:")); /*why double ==?*/ var isAgrippa = (-1 != location.href.indexOf("Page:[\w\_]+Occult_Philosophy")); /*not sure if I'll use this but it's a long project*/ var isIndianBio = (-1 != location.href.indexOf("Page:The_Indian_Biographical_Dictionary.djvu/"));/*model only*/ var isIrishBio = (-1 != location.href.indexOf("Page:A_Compendium_of_Irish_Biography"));/*model only*/ var isBiography = (-1 != location.href.indexOf("Page:[\w\_]+Biography")); var isDNB00 = (-1 != location.href.indexOf("DNB00")); var isMainspace = (-1 == location.href.search(/title=(Talk|User|User_talk|Wikisource|Wikisource_talk|File|File_talk|Mediawiki|Mediawiki_talk|Template|Template_talk|Help|Help_talk|Category|Category_talk|Portal|Portal_talk|Author|Author_talk|Page|Page_talk|Index):/));

// == SIDEBAR SCRIPTS /*I prefer the cleanness of a portlet like en:User:Jsimlo/shortcuts, I wonder if that's possible*/ == /** * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor. * @see https://meta.wikimedia.org/wiki/TemplateScript * @update-token */ // $.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function {	/*********	** Register scripts	*********/	// === CALLS FOR USE IN ALL NAMESPACES ===	pathoschild.TemplateScript.add([ {			name: 'clean up', script: cleanup }	]);

// === CALLS FOR USE IN THE PAGESPACE === if(isPageNS) { pathoschild.TemplateScript.add([			{				name: 'Indent',				script: function(editor) {					editor.forField('#wpHeaderTextbox')						.replace(//g, ' ');				}			},			{				name: 'IndianBio',				enabled: isIndianBio,				script: function(editor) {					// Page:The Indian Biographical Dictionary.djvu tools					// cleanup for Page:The Indian Biographical Dictionary.djv

editor.forField('#wpHeaderTextbox') .append('INDIAN BIOGRAPHICAL DICTIONARY, 1915.\n\n');

cleanup(editor); editor .replace(/([\n\s])([bmsd]\.)/g, '$1\'\'$2\'\'') .replace(/([\n\s])(Address|Clubs?|educ|Publications|Recreations)\:/g, '$1\'\'$2\'\':') .replace(/CLE\.?/g, 'C.I.E.')

// VU -> VII; followed by U in the middle of a word -> ll						.replace(/VU/g, 'VII') .replace(/(\w)U(\w)/, '$1ll$2'); }			},			{				name: 'Anchor', enabled: isBiography, script: function(editor) { // applies // Page:A Compendium of Irish Biography tools editor.replaceSelection(function(pre) {						return '';					}); }			},			{				name: 'internal nslink', enabled: isBiography, script: function(editor) { //set to internal namespace link, set specifically for subpage xref editor.replaceSelection(function(pre) {						return '';					}); }			},			{				name: 'djvu pagelink', enabled: isBiography, script: function(editor) { //adds template 'DJVU page link' editor.replaceSelection(function(pre) {						var work = isIrishBio ? 24 : ;						return ;					}); }			},			{				name: 'Header', script: function(editor) { // PAGE NAMESPACE headerbox or footerbox // puts in to headerbox editor.forField('#wpHeaderTextbox') .append(''); }			},			{				name: 'Footer', script: function(editor) { //*Footerbox app; for archaic books where the first word on the next page is placed at bottom editor.forField('#wpFooterTextbox') .replace(/(<\/div>)/, '$1'); }			},			{				name: 'nop', script: function(editor) { // nop, though it puts it at the bottom of editbox, so only useful in Page: editor.append('\n'); }			},			{				name: 's to ſ', script: function(editor) { editor.replace(/s(?![\Wf])/g, 'ſ'); }			},			{				name: 'ſ to ', script: function(editor) { editor.replace(/ſ/g, ''); }			},			{				name: 'quoteleft', script: function(editor) { editor.replace(/([\s—'])(\")(?=[\w\[])/g, '$1“');				}			},			{				name: 'quoteright',				script: function(editor) {					editor.replace(/((\")(?=[\s—']))/g, '”'); }			},			{				name: 'squoteright', script: function(editor) { editor.replace(/(\w)(\')(\s)/g, '$1’$3'); }			},			{				name: 'squoteleft', script: function(editor) { editor.replace(/([\s—])(\')(?=\w)/g, '$1‘'); }			},			{				name: 'apostrophe', script: function(editor) { editor.replace(/(\w)(\')([tsTS][—\s\.\!\?])/g, '$1’$3'); }			}		]);	}

// === CALLS FOR USE IN THE MAIN NAMESPACE === if(isMainspace) { pathoschild.TemplateScript.add([			{				name: 'DefSort Subpage',				script: function(editor) {					editor.append();				}			},			{				name: 'DNBset',				script: function(editor) {					// replaces with 					editor.replace(/\{\{header[^\}]+\}\}\n/, );				},				enabled: isDNB00			},			//{			//	name: 'override transl',			//	script: otranslator // I don't see any script for this to call			//},			{				name: 'remove TQ',				script: function(editor) {					// removes 					editor.replace(/\{\{TextQuality\|\d{2,3}%\}\}/, );				}			},			{				name: ,				script: function(editor) {					// adds  above header					editor						.replace(/\{\{header/g, '\n{{header')						.appendEditSummary('');				}			},			{				name: 'Ch.prev & next',				script: function(editor) {					// from  section, wikis Chapter -1/+1 to Prev/Next					var newtitle = parseInt(mw.config.get('wgTitle').replace(/^.*\/Chapter (\d+)$/,'$1'))-1; var headerprevious = '../Chapter '+newtitle+'/'; var newtitle = parseInt(mw.config.get('wgTitle').replace(/^.*\/Chapter (\d+)$/,'$1'))+1; var headernext = '../Chapter '+newtitle+'/'; editor.replace(/\| previous  \= \n \| next       \= /, '| previous   \= ' + headerprevious +'\n \| next       \= ' + headernext); }			},			{				name: 'Pages', script: function(editor) { // subst: #tag and some fields // applies using #tag and index  fromsection tosection take editor.replaceSelection(''); }			}		]);	}

// === CALLS FOR USE IN THE USER NAMESPACE === if(isUserNS) { pathoschild.TemplateScript.add([			{				name: 'welcome',				script: function(editor) {					// applies 					editor						.append(' ' + )						.appendEditSummary('welcome');				}			},			{				name: 'welcomeip & test',				script: function(editor) {					// subst applies 					editor						.append(' ' + '\n')						.appendEditSummary('welcome & test');				}			},			{				name: 'welcomeip',				script: function(editor) {					// subst 					editor						.append(' ' + )						.appendEditSummary('welcome');				}			},			{				name: 'toggle in Page:',				script: function(editor) {					//subst: User:Billinghurst/HeaderToggle which tells how to toggle header in Page:					editor.append('');				}			}		]); }

/*********	** Define scripts *********/	//ALL NAMESPACE USE function cleanup(editor) { // all sorts of text cleaning from OCR editor // Digitized by Google (kill) .replace(/Digitized[\s\n]+by[\s\n]+Google/, '')

// remove trailing spaces at the end of each line .replace(/ +\n/g, '\n')

// remove trailing whitespace preceding a hard line break .replace(/ +/g, ' ')

// remove trailing whitespace at the end of page text .replace(/\s+$/g, '')

// remove trailing spaces at the end of refs .replace(/ +<\/ref>/g, ' ')

// remove trailing spaces at the end of template calls .replace(/ +}}/g, '}}')

// convert double-hyphen to mdash (avoiding breaking HTML comment syntax) .replace(/([^\!])--([^>])/g, '$1—$2')

// remove spacing around mdash, but only if it has spaces on both sides // (we don't want to remove the trailing space from "...as follows:— ",			// bearing in mind that the space will already be gone if at end of line). .replace(/ +— +/g, '—')

// join words that are hyphenated across a line break // (but leave "|-" table syntax alone) .replace(/([^\|])-\n/g, '$1');

// stuff to do only if the page doesn't contain a tag: if (editor.get.indexOf(" ") != -1) { editor // remove single line breaks; preserve multiple. // but not if there's a tag, template or table syntax either side of the line break .replace(/([^>}\n])\n([^<{\|\n])/g, '$1 $2')

// collapse sequences of spaces into a single space .replace(/ +/g, ' '); }

editor // remove unwanted spaces around punctuation marks .replace(/ ([;:\?!,])/g, '$1')

//OCR fixes // convert i9 to 19, etc.			.replace(/[il]([0-9])/g, '1$1')

// "the", "them", "their", etcetera .replace(/tlie/g, 'the')

// "U" -> "ll" when preceded by a lowercase letter. .replace(/([a-z])U/g, '$1ll'); } }); //

// == CUSTOM TABS == // === Adds a tab for soft redirects below "move" === /* Soft redirect */ /* See WS:SCRIPTS; adds "soft redirect" tab in Firefox. */      mw.loader.load('//en.wikisource.org/w/index.php?title=User:Bookofjude/softredirect.js&action=raw&ctype=text/javascript');

// == CUSTOM BUTTONS == /*Import from subpage*/ importScript('User:Doug/custombuttons.js');