User:Dethomas/monobook.js

//

/*************************** * BEGIN LIBRARY FUNCTIONS * ***************************/

function addlilink( tabs, url, name, id, title, key ) { var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) {		if(key && title) {		   ta[id] = [key, title]; }				else if(key) {		   ta[id] = [key, '']; }		else if(title) {		   ta[id] = ['', title]; }	}	// re-render the title and accesskeys from existing code in wikibits.js	akeytt; return li; }

function addTab( url, name, id, title, key ) { var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; return addlilink(tabs, url, name, id, title, key); }

function addToolboxLink( url, name, id ) { var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; addlilink(tb, url, name, id); }

/************************* * END LIBRARY FUNCTIONS * *************************/

/******************************** * BEGIN IMAGE AUTOTAGGER      * * User:Mdd4696/monobook.js * ********************************/

/****************************************************************************** *                                                                           * * This script is under development! There are many bugs and unimplemented   * * features, so it may break occasionally. If you find a bug that's not      * * listed below or you have a neat idea, leave me a message on my talk page. * *                                                                           * ****************************************************************************** *                                                                            * * Bugs:                                                                      * * - License drop-downs do not populate in Firefox 1.0.7 on Linux            * *                                                                           * * Other issues:                                                              * * - Layout needs tweaking                                                   * * - Image viewer window needs improvement                                   * *                                                                           * * To Do:                                                                     * * - License lists                                                           * * - Automatic uploader notification                                         * * - Automatically remove tagged images from list                            * * - Load all images uploaded by a particular user                           * * - Image preview in tagger instead of seperate window                      * * - Destroy tagger on close instead of hiding it                            * * - Improve message logic                                                   * * - IE compatibility                                                        * * - Reformat code (configurable variables, seperate styles)                 * * - Turn into javascript "plug-in"                                          * * - Documentation                                                           * *                                                                           * ******************************************************************************/

/*+ | Global vars                                                               | +*/

var imageViewer; var messageTimeoutId;

var fastTaggerBodyFlag = false; var fastTaggerTabFlag = false; var listLimit = 1000;

var summaryDefaultText = "Thousands of images have no copyright tags. You can help!";

/*+ | Tag arrays                                                                | +*/

var commonTags = new Array( "subst:nld", "subst:nsd", "GFDL-presumed", "imagevio", "Missing image" );

var publicDomainTags = new Array( "Military-Insignia", "PD", "PD-flag-50", "PD-flag-70",	"PD-flag-100", "PD-flag-US", "PD-ineligible", "PD-old", "PD-old-50",	"PD-old-70", "PD-stamp", "CopyrightedFreeUse", "PD-release", "PD-link",	"PD-self", "PD-user", "PD-art", "PD-art-life-50", "PD-art-life-70",	"PD-art-US", "Iraqcopyright", "PD-AR-Photo", "PD-Australia", "PD-Australia-CC",	"PD-AustraliaGov", "PD-BritishGov", "PD-Canada", "PD-China", "PD-CzechGov",	"PD-India", "PD-Iran", "PD-LithuaniaGov", "PD-Pakistan", "PD-PakistanGov",	"PD-Philippines", "PD-PhilippinesGov", "PD-Poland", "PD-PolishGov",	"PD-RU-exempt", "PD-SAGov", "PD-UA-exempt", "PD-USSR", "PD-BY-exempt",	"Gray's Anatomy plate", "PD-8BS", "PD-GWPDA", "PD-Meyers",	"PD-Open Clipart Library", "PD-PCL", "PD-PDphoto.org", "PD-Vardion",	"PD-Catholic", "money-US" );

var freeTags = new Array( "ABr", "AMI", "Attribution",	"cc-by-2.0", "CACTVSGIF", "CopyrightedFreeUse", "CopyrightedFreeUse-Link",	"CopyrightedFreeUse-User", "CopyrightedFreeUseProvidedThat", "EU image",	"FinnishDefenceForces", "Flphoto", "money-EU", "MosNews", "No rights reserved",	"Sejm", "SocEur", "Trainweb", "WorldCoin", "BSD", "BSDu", "cc-by", "cc-by-2.0",	"cc-by-2.0-map", "cc-by-2.0-map-of", "cc-by-2.5", "cc-sa", "cc-by-sa",	"cc-by-sa-2.0", "cc-by-sa-2.0-kr", "cc-by-sa-2.5", "FAL", "GermanGov", "GFDL",	"GFDL-small", "GFDL 1.2", "GFDL-self", "GFDL-retouched", "GFDL-invariants",	"GPL", "LGPL", "GFDL-OpenGeoDB", "MIT", "NZCrownCopyright", "PD-NZSection27",	"CrownCopyright", "LearningandSkillsCouncilCopyright",	"NationalAuditOfficeCopyright", "NHSCopyright" );

var fairUseTags = new Array( "art",	"Digimonimage", "Fairusein", "Music sample", "Pokeimage", "smithsonian",	"Standard test", "USPSstamp", "YuGiOhimage", "Logo", "DisneyLogo", "icon",	"radiologo", "scoutlogo", "sports-logo", "hqfl_logos", "Olympics-logo",	"tv-logo", "tv-program-logo", "Albumcover", "Boardgamecover", "Bookcover",	"Comiccover", "Comicpanel", "Comicscene", "DVDcover", "Gamecover",	"Magazinecover", "Newspapercover", "TIME", "Video tape cover",	"DisneyAttractionPoster", "Eventposter", "Movieposter",	"ParliamentofAustralia", "Politicalposter", "Promophoto", "Promotional",	"Sportsposter", "Screenshot", "film-screenshot", "game-screenshot",	"musicpromo-screenshot", "software-screenshot", "linux-software-screenshot",	"mac-software-screenshot", "windows-software-screenshot",	"web-software-screenshot", "tv-screenshot",	"web-screenshot", "wikipedia-screenshot" );

/*+ | Message arrays                                                            | +*/

var generalMessages = new Array (	"Wunderbar!", "That's it!", "Keep going!", "Alright now!", "Superb!",	"Amazing!", "Keep it coming.", "Wow. Just wow.", "Speed demon!",	"You're on fire!", ":-)", "Sweet!", "Who's da man?", "Watch it now!", "Woo woo!", "The image tagging train is chugging along!", "Going to town!", "Zoooom!", "You like to move it, move it.", "Bot-like.", "You are the image tagging master!", "Sha-wing!", "Tired yet?", "Wrist hurt yet?", "Jolly good.", "Brilliant!", "Sacre Bleu!", "Oh. My. God. Becky, look at her tagger. It is so big.", "Tagger skillz.", "ur l33t", "Blimey!", "Gotta catch them all!", "Gooooaaaal!", "Such a good little Wikipedian.", "Faster than a speeding bullet.", "Einstein would approve.", "Ben Franklin would approve.", "Jefferson would approve.", "Washington would approve.", "Shiny!", "Double whammy!", "Home run!", "That minty fresh feeling!", "Another?", "Bingo!", "Another round!", "Please, sir, I want some more.", "So fast!", "If you were a car, I'd call you Ferrari.", "Tag. It. Tag it.", "I am a banana!", "Tickle-me tagger!", "The wonderful thing about taggers is taggers are wonderful things!", "Booyah!", "No need to thank me, just doing my job.", "Bagged and tagged." );

var sourceMessages = new Array (	"The internet is for porn.", "I found it under the couch.",	"Where did you say you were from?", "Lost children that way ->",	"It came oughtta nowhere!", "In Soviet Russia, the images tag *you*!",	"Dumpster diving works wonders." );

var licenseMessages = new Array (	"Sir, I'll need to see your license and registration.", "License to kill.",	"License to thrill.", "License to ill.", "License to... oh I give up.",	"You can't get in, this is a fake id.", "The RIAA sucks.", "Freeeedom!" );

var ifdMessages = new Array (	"Down the tube...", "Get it out of here!", "I don't think so.", "Yeah, right.",	"My eyes!", "lol", "wtf", "lolwtfbbq", "Move along, nothing to see here.",	"It's real I tell ya'!", "Mmmm... delete!",	"Some say I'm deletionist, others say I'm inclusionally challenged.",	"Baloney.", "It's just one of those days.", "Nein, das ist verboten!",	"I love the smell of deletion in the morning.",	"I scream, you scream, we throw the frickin' computer out of the window.",	"Outta sight!", "Zip. Nada. Nothing.", "Kill it!",	"How do you spell bannable?", "It's peanut butter jelly time!",	"One Thousand Years of Death!", "Oh, be-have!",	"Absolutely and completely gone!",	"That's where I saw the leprechaun. He told me to burn things." );

/*+ | Creation functions                                                        | +*/

function createTaggerBody { window.name = "taggerWin";

var taggerBox = document.createElement( "div" ); taggerBox.id = "taggerBox";

taggerBox.style.background = "#F9F9F9"; taggerBox.style.border = "1px solid #000000"; taggerBox.style.left = "15%"; taggerBox.style.padding = "15px"; taggerBox.style.position = "absolute"; taggerBox.style.top = "15%"; taggerBox.style.width = "635px"; taggerBox.style.zIndex = "100";

var retVal = ""; retVal += "&times; "; retVal += " "; retVal += "	Common "; retVal += "	 "; retVal += "	Public Domain "; retVal += "	 "; retVal += "	Free "; retVal += "	 "; retVal += "	Fair use "; retVal += "	 "; retVal += " "; retVal += ""; retVal += " "; retVal += " "; retVal += ""; retVal += " "; retVal += " "; retVal += ""; retVal += " "; retVal += " Default summary"; retVal += " "; retVal += "<input type='button' value='Tag image' onClick='tagImage;' />"; retVal += "<input type='button' value='Spawn image viewer' onClick='createImageViewer( document.getElementById( \"imageList\" ).value );' />"; retVal += " "; retVal += " "; taggerBox.innerHTML = retVal;

document.body.appendChild( taggerBox );

populateSelect( document.getElementById( "commonSel" ), commonTags ); populateSelect( document.getElementById( "publicDomainSel" ), publicDomainTags ); populateSelect( document.getElementById( "freeSel" ), freeTags ); populateSelect( document.getElementById( "fairUseSel" ), fairUseTags ); }

function createFastTaggerBody( mouseXPos, mouseYPos ) { var fastTaggerBox = document.createElement( "div" ); fastTaggerBox.id = "fastTaggerBox";

fastTaggerBox.setAttribute( "onMouseOut", "setFastTaggerBodyFlag( false );" ); fastTaggerBox.setAttribute( "onMouseOver", "setFastTaggerBodyFlag( true );" );

fastTaggerBox.style.background = "#F9F9F9"; fastTaggerBox.style.border = "1px solid #000000"; fastTaggerBox.style.left = mouseXPos + "px"; fastTaggerBox.style.padding = "15px"; fastTaggerBox.style.position = "absolute"; fastTaggerBox.style.top = mouseYPos + "px"; fastTaggerBox.style.zIndex = "101";

var retVal = ""; retVal += "<input type='button' value='No License' style='width: 150px;' onClick='fastTagImage( \"subst:nld\", \"licensing\", document.getElementById( \"customSummary\" ).value );' />"; retVal += " "; retVal += "<input type='button' value='No Source' style='width: 150px;' onClick='fastTagImage( \"subst:nsd\", \"summary\", document.getElementById( \"customSummary\" ).value );' />"; retVal += " "; retVal += "<input type='button' value='IFD' style='width: 150px;' onClick='fastTagImage( \"subst:ifd\", \"top\", document.getElementById( \"customSummary\" ).value );' />"; retVal += "

";	retVal += "<input type='checkbox' id='summaryCheckbox' checked='true' onClick='toggleSummary;' /> Default summary";	retVal += " ";	retVal += "<input type='text' id='customSummary' value='" + summaryDefaultText + "' style='display: none; width: 150px;' />";	fastTaggerBox.innerHTML = retVal;

document.body.appendChild( fastTaggerBox ); }

function createImageViewer( atUrl ) { if ( atUrl == "" ) { atUrl = "http://en.wikipedia.org/wiki/Image:TestImage.jpg"; }

if ( ! imageViewer || imageViewer.closed ) { imageViewer = window.open( atUrl, "imageViewer", "width = 800, height = 600, resizable = yes, scrollbars = yes, toolbar = no, location = yes, directories = no, status = no, menubar = no, copyhistory = no" ); imageViewer.name = "editorWin"; } else { imageViewer.location.href = atUrl; imageViewer.focus; } }

/*+ | Show/Hide functions                                                       | +*/

function hideMessage { document.getElementById( "messageText" ).innerHTML = ""; }

function showMessage { var randIndex = Math.round( Math.random * ( generalMessages.length - 1 ) ); document.getElementById( "messageText" ).innerHTML = generalMessages[ randIndex ];

window.clearTimeout( messageTimeoutId ); messageTimeoutId = window.setTimeout( "hideMessage", 5000 ); }

function hideTagger { window.clearTimeout( messageTimeoutId ); hideMessage;

document.getElementById( "taggerBox" ).style.display = "none"; }

function showTagger { if ( document.getElementById( "taggerBox" ) ) { document.getElementById( "taggerBox" ).style.display = "block"; } else { createTaggerBody; } }

function setFastTaggerBodyFlag( newFlag, mouseXPos, mouseYPos ) { fastTaggerBodyFlag = newFlag; toggleFastTagger( mouseXPos, mouseYPos ); }

function setFastTaggerTabFlag( newFlag, mouseXPos, mouseYPos ) { fastTaggerTabFlag = newFlag; toggleFastTagger( mouseXPos, mouseYPos ); }

function toggleFastTagger( mouseXPos, mouseYPos ) { if ( fastTaggerTabFlag || fastTaggerBodyFlag ) { if ( document.getElementById( "fastTaggerBox" ) ) { document.getElementById( "fastTaggerBox" ).style.display = "block"; } else { createFastTaggerBody( mouseXPos, mouseYPos ); }

if ( mouseXPos < parseInt( document.getElementById( "fastTaggerBox" ).style.left ) ) { document.getElementById( "fastTaggerBox" ).style.left = mouseXPos + "px"; }

if ( mouseYPos > parseInt( document.getElementById( "fastTaggerBox" ).style.top ) ) { document.getElementById( "fastTaggerBox" ).style.top = mouseYPos + "px"; }	} else { document.getElementById( "fastTaggerBox" ).style.display = "none"; } }

function loadImage( imageName ) { if ( ! imageViewer || imageViewer.closed ) { createImageViewer( "http://en.wikipedia.org/wiki/" + imageName ); } else { imageViewer.location.href = "http://en.wikipedia.org/wiki/" + imageName; }

var xmlhttp = new XMLHttpRequest; xmlhttp.open( "GET", "http://en.wikipedia.org/w/index.php?title=" + imageName + "&action=raw&ctype=text/xml", true ); xmlhttp.onreadystatechange = function { if ( xmlhttp.readyState == 4 ) { if ( xmlhttp.status == 200 ) { document.getElementById( "pageText" ).value = xmlhttp.responseText; } else if ( xmlhttp.status == 404 ) { alert( "Error 404: Document not found" ); } else { alert( "Unspecified error: " + xmlhttp.status ); }		}	}	xmlhttp.send( null ); document.getElementById( "pageText" ).value = "Loading..."; }

function loadList( pageName ) { var xmlhttp = new XMLHttpRequest; xmlhttp.open( "GET", "http://en.wikipedia.org/w/index.php?title=" + pageName + "&action=raw&ctype=text/xml", true ); xmlhttp.onreadystatechange = function { if ( xmlhttp.readyState == 4 ) { if ( xmlhttp.status == 200 ) { var rawListText = xmlhttp.responseText;

// Remove Wiki formatting rawListText = rawListText.replace( /# \[\[:/g, "" ); rawListText = rawListText.replace( /\]\]/g, "" );

// Escape any remaining special characters //var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\" ]; //rawListText = rawListText.replace( new RegExp( "(\\" + specials.join( "|\\" ) + ")", "g" ), "\\$1" );

var listArr = rawListText.split( "\n" ); for ( var i = 0; i < listArr.length && i < listLimit; i++ ) { document.getElementById( "imageList" ).options[ i ] = new Option( listArr[ i ], listArr[ i ] ); }			} else if ( xmlhttp.status == 404 ) { alert( "Error 404: Document not found" ); } else { alert( "Unspecified error: " + xmlhttp.status ); }		}	}	xmlhttp.send( null ); document.getElementById( "imageList" ).options.length = 0; document.getElementById( "imageList" ).options[ 0 ] = new Option( "Loading...", "" ); }

function defaultSummary( summaryField, defaultFlag ) { if ( defaultFlag ) { summaryField.value = summaryDefaultText; } }

function populateSelect( selectObj, optionArr ) { for ( var i = 1; i <= optionArr.length; i++ ) { var newOption = document.createElement( "option" ); selectObj.options[ i ] = new Option( optionArr[ i - 1 ], optionArr[ i - 1 ] ); } }

function toggleSummary { if ( document.getElementById( "summaryCheckbox" ).checked ) { document.getElementById( "customSummary" ).style.display = "none"; document.getElementById( "customSummary" ).value = "Thousands of images have no copyright tags. You can help!"; } else { document.getElementById( "customSummary" ).style.display = "inline"; } }

/* *       Name: insertTag * Description: Inserts tag template into the edit box * Parameters: tag - Tag text *             location - Where to place tag (top, summary, *                         licensing, bottom) *    Returns: Boolean value indicating success */ function insertTag( textFieldObj, tag, location ) { var retVal = true; var sumTagNewline = "\n"; var sumRegExp = /=+\s*Summary\s*=+\n?/i; var licRegExp = /=+\s*Licens[a-zA-Z]+\s*=+\n?/i; var wpTextboxVal = textFieldObj.value;

tag = "";

// Summary heading if ( ! wpTextboxVal.match( sumRegExp ) ) { var newlines = "\n";

if ( wpTextboxVal.search( licRegExp ) == 0 ) { newlines += "\n\n"; sumTagNewline = ""; }

wpTextboxVal = "== Summary ==" + newlines + wpTextboxVal; }

// Licensing heading if ( ! wpTextboxVal.match( licRegExp ) ) { wpTextboxVal = wpTextboxVal + "\n== Licensing ==\n"; }

// Add the tag switch ( location ) { case "top": wpTextboxVal = tag + "\n\n" + wpTextboxVal; break; case "summary": wpTextboxVal = wpTextboxVal.replace( sumRegExp, "== Summary ==\n" + tag + sumTagNewline ); break; case "licensing": wpTextboxVal = wpTextboxVal.replace( licRegExp, "== Licensing ==\n" + tag + "\n" ); break; case "bottom": wpTextboxVal = wpTextboxVal + "\n" + tag; break; default: retVal = false; }

// Update the textarea textFieldObj.value = wpTextboxVal; return retVal; }

function imageUpdated { document.getElementById( "imageList" ).options[ document.getElementById( "imageList" ).selectedIndex ] = null; document.getElementById( "pageText" ).value = ""; }

function tagImage { showMessage;

var imageName = document.getElementById( "imageList" ).value;

if ( ! imageViewer || imageViewer.closed ) { createImageViewer( "http://en.wikipedia.org/w/index.php?title=" + imageName + "&action=edit" ); } else { imageViewer.location.href = "http://en.wikipedia.org/w/index.php?title=" + imageName + "&action=edit"; }

//createImageViewer( "http://en.wikipedia.org/w/index.php?title=Image:TestImage.jpg&action=edit&tagImage=true" );

//imageViewer.location.href = ""; }

function fastTagImage( tag, location, summaryText ) { if ( document.title.indexOf( "Editing Image:" ) == 0 ) { insertTag( document.editform.wpTextbox1, tag, location ); document.editform.wpSummary.value = summaryText; document.editform.wpMinoredit.checked = false; document.editform.wpWatchthis.checked = false; document.editform.submit; } else { var imageName = document.title.substring( 0, document.title.indexOf( " - Wikipedia, the free encyclopedia" ) ); document.location.href = "http://en.wikipedia.org/w/index.php?title=" + escape( imageName ) + "&action=edit&tagImage=true&tagText=" + escape( tag ) + "&tagLocation=" + escape( location ) + "&summaryText=" + escape( summaryText ); } }

$( function {

addToolboxLink( "javascript:showTagger", "Image Autotagger", "ca-showtagger" );

if ( window.name == "editorWin" && window.opener != null ) { document.getElementById( "ca-edit" ).parentNode.removeChild( document.getElementById( "ca-edit" ) ); }

if ( document.title.indexOf( "Editing Image:" ) == 0 && window.name == "editorWin" && window.opener != null ) { document.editform.wpTextbox1.value = window.opener.document.getElementById( "pageText" ).value; document.editform.wpSummary.value = window.opener.document.getElementById( "taggerEditSummary" ).value; document.editform.wpMinoredit.checked = false; document.editform.wpWatchthis.checked = false; document.editform.submit;

window.opener.imageUpdated; } else if ( document.title.indexOf( "Image:" ) == 0 || document.title.indexOf( "Editing Image:" ) == 0 ) { addTab( "", "tag", "ca-tagnow", "Tag this image", "" ); document.getElementById( "ca-tagnow" ).setAttribute( "onMouseOver", "setFastTaggerTabFlag( true, event.clientX, event.clientY );" ) document.getElementById( "ca-tagnow" ).setAttribute( "onMouseOut", "setFastTaggerTabFlag( false, event.clientX, event.clientY );" )

if ( document.location.search.indexOf( "tagImage" ) > -1 ) { var keyValArr = new Array; var qPairs = document.location.search.substring( 1 ).split( "&" );

for ( var i = 0; i < qPairs.length; i++ ) { var qKey = qPairs[ i ].substring( 0, qPairs[ i ].indexOf( "=" ) ); var qValue = qPairs[ i ].substring( qPairs[ i ].indexOf( "=" ) + 1, qPairs[ i ].length ); keyValArr[ qKey ] = unescape( qValue ); }

fastTagImage( keyValArr[ "tagText" ], keyValArr[ "tagLocation" ], keyValArr[ "summaryText" ] ); }	} } );

/*********************************** * END IMAGE AUTOTAGGER - DEV CODE * ***********************************/

// //Retrieved from "http://en.wikipedia.org/wiki/User:Mdd4696/monobook.js"

//This page was last modified 00:19, 15 February 2006. All text is available //under the terms of the GNU Free Documentation License (see Copyrights for details). //Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.