User:Wikidudeman/tags.js

// // User:LilDice/flexitags.js // // //Flexitags script, based on Tags by Seed 2.0 //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; } if( typeof( FlexiTagConfig.addSigOnTalk ) == 'undefined' ) { FlexiTagConfig.addSigOnTalk = true; } /*Mark all edits as minor true/false*/ if( typeof( FlexiTagConfig.minoredit ) == 'undefined' ) { FlexiTagConfig.minoredit = false; } /*Mark all edits as minor true/false*/ if( typeof( FlexiTagConfig.summarySuffix ) == 'undefined' ) { FlexiTagConfig.summarySuffix = ' '; } 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 oc(a) { var o = {}; for(var i=0;i<a.length;i++) { o[a[i]]=''; } return o; } function addTab(flexitag,i) { var tabs = document.getElementById( 'p-cactions' ).getElementsByTagName( 'ul' )[0]; addlimenu(tabs,flexitag.name,flexitag.name); for(j=0;j<flexitag.tagset.length;j++) { tmpName = flexitag.tagset[j][0]; pipematch = /^(.+?)\|/.exec(tmpName); if(pipematch) { tmpName = pipematch[1]; } if (flexitag.tagset[j][2] != null) { tmpName = flexitag.tagset[j][2] } mw.util.addPortletLink(flexitag.name, "javascript:doAddTag(" + i + "," + j + ")", tmpName,tmpName,tmpName, ""); } } function parseTag(tagtext) { matched = false; if(tagtext.match(/%twinkarticle/)) { if( QueryString.exists( 'vanarticle' ) ) { article = decodeURI(QueryString.get( 'vanarticle' )).replace( /^(Image|Category):/i, ':$1:'); tagtext = tagtext.replace(/%twinkarticle/,article); matched = true; } else { tagtext = tagtext.replace(/%twinkarticle/,prompt('Which Article?')); matched = true; } } var promptmatch = /%prompt\((.+?)\)/i.exec(tagtext); if(promptmatch) { tagtext = tagtext.replace(/%prompt\(.+?\)/,prompt(promptmatch[1])); matched = true; } if(tagtext.match(/%date/)) { tagtext = tagtext.replace(/%date/,thedate.getUTCMonthName + ' ' + thedate.getUTCFullYear); matched = true; } if(matched) { return parseTag(tagtext); } else { return tagtext; } } function doAddTag(tabindex,tagindex) { // copy wikEd (http://en.wikipedia.org/wiki/User:Cacycle/wikEd.js) frame to wpTextbox1 textarea if (typeof(wikEdUseWikEd) != 'undefined') { if (wikEdUseWikEd == true) { WikEdUpdateTextarea; } } text = document.editform.wpTextbox1.value; tag = ""; if(FlexiTagConfig.addSigOnTalk && mw.config.get('wgCanonicalNamespace').match(/talk/i)) { tag += "~"; } insertAtCursor(document.editform.wpTextbox1,tag); // make the changes to the classic wpTextbox1 textarea // // copy wpTextbox1 textarea back to wikEd frame if (typeof(wikEdUseWikEd) != 'undefined') { if (wikEdUseWikEd == true) { WikEdUpdateFrame; } } document.editform.wpSummary.value = FlexiTagConfig.tabs[tabindex].tagset[tagindex][1] + FlexiTagConfig.summarySuffix; 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) { theNs = mw.config.get('wgCanonicalNamespace'); if(theNs == '') {theNs = 'Main'}; for(i=0;i<FlexiTagConfig.tabs.length;i++) { tmpTab = FlexiTagConfig.tabs[i]; if('namespace' in tmpTab) { if ( theNs in oc(tmpTab.namespace) ) { addTab(tmpTab,i); }   } else { addTab(tmpTab); } } } }); // //