User:LilDice/tags.js

// // User:LilDice/tags.js // // // Tags script by Seed 2.0 - // uber-alpha hack // heavily based on CleanupTab.js // My thanks and major props go to AzaToth.

//requires: //importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu'); //importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css');

var thedate = new Date;

var edFocus = false;

if( typeof( FlexiTagConfig ) == 'undefined' ) { FlexiTagConfig = {}; }

/*Autosubmit? true/false*/ if( typeof( FlexiTagConfig.autosubmit ) == 'undefined' ) { FlexiTagConfig.autosubmit = false; }

/*Mark all edits as minor true/false*/ if( typeof( FlexiTagConfig.minoredit ) == 'undefined' ) { FlexiTagConfig.minoredit = false; }

var defaultTagset = { name:'tags', namespace:'Main,User_talk', tagset:%date','See [[WP:EL'], ['trivia','Adding Trivia Section'], ['Autobio-warn|%prompt(Article Name)'], ['cleanup','Adding Cleanup Tag']] };

if( typeof( FlexiTagConfig.tabs ) == 'undefined' ) { FlexiTagConfig.tabs = new Array; FlexiTagConfig.tabs.push(defaultTagset); }

Date.monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; Date.prototype.getMonthName = function { return Date.monthNames[ this.getMonth ]; } Date.prototype.getUTCMonthName = function { return Date.monthNames[ this.getUTCMonth ]; }

function insertAtCursor(myField, myValue) {

if(!edFocus) {   myField.value =  myValue + '\n' + myField.value; return; } //IE support if (document.selection) { myField.focus; sel = document.selection.createRange; sel.text = myValue; } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); } else { myField.value = myValue + '\n' + myField.value; } }

function addTab(flexitag) { var tabs = document.getElementById( 'p-cactions' ).getElementsByTagName( 'ul' )[0]; addlimenu(tabs,flexitag.name,flexitag.name); for(j=0;j<flexitag.tagset.length;j++) { mw.util.addPortletLink(flexitag.name, "javascript:doAddTag(" + i + "," + j + ")", flexitag.tagset[j][0],flexitag.tagset[j][0] ,flexitag.tagset[j][0], ""); } }

function parseTag(tagtext) {

var promptmatch = /%prompt\((.+?)\)/i.exec(tagtext); if(promptmatch) { tagtext = tagtext.replace(/%prompt\(.+?\)/,prompt(promptmatch[1])); } if(tagtext.match(/%date/)) { tagtext = tagtext.replace(/%date/,thedate.getUTCMonthName + ' ' + thedate.getUTCFullYear); }

return tagtext; /*if( QueryString.exists( 'vanarticle' ) ) { article = decodeURI(QueryString.get( 'vanarticle' )).replace( /^(Image|Category):/i, ':$1:' ); } else { article = prompt('Which article?').replace( /^(Image|Category):/i, ':$1:' ); }*/ }

function doAddTag(tabindex,tagindex) {

text = document.editform.wpTextbox1.value; tag = "";

insertAtCursor(document.editform.wpTextbox1,tag);

document.editform.wpSummary.value = thetabs[tabindex].tagset[tagindex][1];

if (FlexiTagConfig.minoredit == true) { document.editform.wpMinoredit.checked = true; }

if (FlexiTagConfig.autosubmit == true) { document.editform.submit; } }

addOnloadHook(function { if(document.getElementById('editform')) {

document.getElementById('wpTextbox1').onfocus = function {edFocus=true;}; } if(document.editform) { for(i=0;i<FlexiTagConfig.tabs.length;i++) { tmpTab = FlexiTagConfig.tabs[i]; if('namespace' in tmpTab) {  if ( tmpTab.namespace.match(new RegExp(wgCanonicalNamespace)) ) {   addTab(tmpTab); }    }  else {   addTab(tmpTab); } } } });

// //