/*************
*** 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');
 
/* menu links */
// In the function below, add more lines like "regexTool('link text','function_name()')" to add
// links to the sidebar menu. The function name is the function defined in rfmscripts() below.
function rmflinks() {
	regexTool('Custom regex','custom()'); // a default tool which performs regex input in a dynamic form             
        regexTool('PostOCR','postOCR()');
        regexTool('Apostrofi','apostrofi()');
 
}
 
/* scripts */
// Below, define the functions linked to from rmflinks() above. These functions can use any JavaScript,
// but there is a set of simplified tools documented at
// http://meta.wikimedia.org/wiki/User:Pathoschild/Script:Regex_menu_framework .
/* sidebar code for use with P/c's Regex code */
 
function DNBset() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/\{\{header\n \| title      \=.+\n \| author     \= \n \| translator \= \n \| section    \= \n \| previous   \= \n \| next       \= \n \| notes      \= \n\}\}\n/, '{{subst:DNBset\n |article= \n |previous= \n |next= \n |volume = \n |contributor = \n |wikipedia = \n |extra_notes= \n |from= \n |to= \n |section= \n}}');
}
 
function postOCR() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/'/g, '’')
	.replace(/’’’/g, '\'\'\'')
	.replace(/’’/g, '\'\'')
	.replace(/E’ /g, 'È ')
	.replace(/lP/g, 'll’')
	.replace(/I’/g, 'l’')
	.replace(/1’/g, 'l’')
	.replace(/ :/g, ': ')
        .replace(/([dlznt])’ /g, "$1’")
        .replace(/[(\[] /g, " $1")
        .replace(/ \n/g, '\n')
	.replace(/\n\n/g, '<2p>')
	.replace(/\n\n\n/g, '<3p>')
	.replace(/-\n/g, '')
	.replace(/\n/g, ' ')
	.replace(/<2p>/g, '\n\n')
	.replace(/<3p>/g, '\n\n\n')
        .replace(/ ,/g, ", ")
        .replace(/ ;/g, "; ")
        .replace(/ !/g, "! ")
        .replace(/ \?/g, "? ")
        .replace(/ \./g, ". ")
        .replace(/ :/g, ": ")
        ;
}
function apostrofi() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/'/g, '’')
	.replace(/’’’/g, '\'\'\'')
	.replace(/’’/g, '\'\'')
 
        ;
}
 
function dashes() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/--/g, '—')
}
 
function lines() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/ \n/g, '\n');
	editbox.value = editbox.value.replace(/\n\n/g, '<p>');
	editbox.value = editbox.value.replace(/-\n/g, '');
	editbox.value = editbox.value.replace(/\n/g, ' ');
	editbox.value = editbox.value.replace(/<p>/g, '\n\n')
}
 
function rmTextQual() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/\{\{TextQuality\|\d\d\%\}\}/, '');
}
 
function trans() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/ translator\w+\=/, ' override_translator = ');
}
 
function und2ital() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/\_/g, '\'\'');
}
 
function chapcase() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/CHAPTER/g, '{{sc|Chapter}}');
}
 
function welcome() {
	var headerbox = document.getElementsByName('wpHeaderTextbox')[0];
	editbox.value = editbox.value + '{{welcome}}-- ~~' + '~~';
        editreason.value = editreason.value + 'welcome';
}
 
function weliptest() {
	var headerbox = document.getElementsByName('wpHeaderTextbox')[0];
	editbox.value = editbox.value + '{{subst:' + 'welcomeip}}-- ~~' + '~~\n{{test}}';
        editreason.value = editreason.value + 'welcome & test';
}
 
function similar() {
	var editbox = document.getElementsByName('wpTextbox1')[0];
	editbox.value = editbox.value.replace(/\{\{header/g, '{{similar|}}\n{{header');
        editreason.value = editreason.value + '{{similar}}';
}
 
 
//