Revision as of 16:39, 3 August 2005 view sourceLupin (talk | contribs)19,513 edits will this work on the commons? :)← Previous edit |
Latest revision as of 14:34, 9 February 2021 view source Xaosflux (talk | contribs)Edit filter managers, Autopatrolled, Bureaucrats, Importers, Interface administrators, Oversighters, Administrators83,869 edits expand directions |
(113 intermediate revisions by 17 users not shown) |
Line 1: |
Line 1: |
|
|
var popScript = '//en.wikipedia.org/search/?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-popups.js'; |
|
//////////////////////////////////////////////////////////////////// |
|
|
|
var popStyleSheet = '//en.wikipedia.org/search/?action=raw&ctype=text/css&title=MediaWiki:Gadget-navpop.css'; |
|
// Popup stuff |
|
|
|
if ( window.localCSS ) { popStyleSheet = 'http://localhost:8080/js/navpop.css'; } |
|
//////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
function popups_importScriptURI(url) { |
|
document.write('<script type="text/javascript" src="http://en.wikipedia.org/search/?title=User:Lupin/md5.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); |
|
|
|
var s = document.createElement('script'); |
|
|
|
|
|
s.setAttribute('src',url); |
|
document.write('<script type="text/javascript" src="http://en.wikipedia.org/search/?title=User:Lupin/overlib.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); |
|
|
|
s.setAttribute('type','text/javascript'); |
|
|
|
|
|
document.getElementsByTagName('head').appendChild(s); |
|
// we're not set up for interwiki stuff yet - only affect en links |
|
|
|
return s; |
|
|
|
|
var exceptions=/((title=|\/)Special:|section=)/ |
|
|
var contributions=/(title=|\/)Special:Contributions&target=(.*)/ |
|
|
var talk=/Talk:/i |
|
|
|
|
|
var whichWiki=window.location.href.split('.org/'); |
|
|
var re; |
|
|
var titlebase; |
|
|
|
|
|
if (whichWiki=='http://commons.wikimedia') { |
|
|
titlebase='http://commons.wikipedia.org/search/?title='; |
|
|
re=/*:\/\/en\.wikipedia\.org\/w(iki\/|\/index\.php\?title=)(*)/ |
|
|
} else { |
|
|
titlebase='http://en.wikipedia.org/search/?title='; |
|
|
re=/*:\/\/en\.wikipedia\.org\/w(iki\/|\/index\.php\?title=)(*)/ |
|
|
} |
|
|
|
|
|
function wikiLink(article, action, text) { |
|
|
hint = myDecodeURI(article + '&action=' + action); |
|
|
return titledWikiLink(article, action, text, hint); |
|
|
} |
|
} |
|
|
|
|
|
|
function popups_importStylesheetURI(url) { |
|
function titledWikiLink(article, action, text, title) { |
|
|
|
return document.createStyleSheet ? document.createStyleSheet(url) : popups_appendCSS('@import "' + url + '";'); |
|
var base = titlebase + article; |
|
|
var url=base; |
|
|
// no need to add action&view, and this confuses anchors |
|
|
if (action != 'view') url = base + '&action=' + action; |
|
|
|
|
|
var hint; |
|
|
if (title == null || title == '') |
|
|
hint = '' |
|
|
else |
|
|
hint = 'title="' + title + '"'; |
|
|
|
|
|
return '<a href="' + url + '"' + hint + '>' + text + '</a>'; |
|
|
} |
|
} |
|
|
|
|
|
function specialLink(article, specialpage, text) { |
|
function popups_appendCSS(text) { |
|
|
var s = document.createElement('style'); |
|
var base = titlebase + 'Special:'+specialpage; |
|
|
|
s.type = 'text/css'; |
|
var url = base + '&target=' + article; |
|
|
|
s.rel = 'stylesheet'; |
|
var hint = myDecodeURI(specialpage+':'+article) ; |
|
|
|
if (s.styleSheet) s.styleSheet.cssText = text //IE |
|
return '<a href="' + url + '" title="' + hint + '">' + text + '</a>'; |
|
|
|
else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null |
|
|
document.getElementsByTagName('head').appendChild(s); |
|
|
return s; |
|
} |
|
} |
|
|
|
|
|
|
popups_importStylesheetURI(popStyleSheet); |
|
function talkPage(article) { |
|
|
|
popups_importScriptURI(popScript); |
|
if (article.indexOf('Talk:') > -1 || article.indexOf('talk:') > -1 ) |
|
|
return null; |
|
|
|
|
|
var i=article.indexOf(':'); |
|
|
if (i == -1) return 'Talk:'+article; |
|
|
else return article.substring(0,i)+'_talk:' + article.substring(i+1); |
|
|
} |
|
|
|
|
|
function articleFromTalkPage(talkpage) { |
|
|
var i=talkpage.indexOf('Talk:'); |
|
|
var j=talkpage.indexOf('_talk:'); |
|
|
if ( i == -1 && j == -1 ) |
|
|
return null; |
|
|
if ( i > -1 ) return talkpage.substring(i+5); |
|
|
return talkpage.split('_talk:').join(':'); |
|
|
} |
|
|
|
|
|
function userName(article) { |
|
|
var i=article.indexOf('User'); |
|
|
var j=article.indexOf(':'); |
|
|
if (i != 0 || j < -1) return null; |
|
|
var k=article.indexOf('/'); |
|
|
if (k==-1) return article.substring(j+1); |
|
|
else return article.substring(j+1,k); |
|
|
} |
|
|
|
|
|
function isInNamespace(article, namespace) { |
|
|
var i=article.indexOf(namespace+':'); |
|
|
var j=article.indexOf(namespace+'_talk:'); |
|
|
if (i == -1 && j == -1) return false; |
|
|
return true; |
|
|
} |
|
|
|
|
|
function stripNamespace(article) { |
|
|
// this isn't very sophisticated |
|
|
// it just removes everything up to the final : |
|
|
var list = article.split(':'); |
|
|
return list; |
|
|
} |
|
|
|
|
|
function contribsLink(article, text) { |
|
|
return specialLink(userName(article), 'Contributions', text); |
|
|
} |
|
|
|
|
|
function imagePathComponent(article) { |
|
|
if (isInNamespace(article, 'Image')) { |
|
|
var stripped=stripNamespace(article); |
|
|
var forhash=myDecodeURI(stripped).split(' ').join('_'); |
|
|
var hash=hex_md5(forhash); |
|
|
var pathcpt=hash.substring(0,1) + '/' + hash.substring(0,2) + '/'; |
|
|
return pathcpt; |
|
|
} |
|
|
else return null; |
|
|
} |
|
|
|
|
|
function imageURL(article, wiki) { |
|
|
var imgurl=null; |
|
|
if (isInNamespace(article, 'Image')) { |
|
|
var pathcpt = imagePathComponent(article); |
|
|
var stripped=stripNamespace(article); |
|
|
var imgurl="http://upload.wikimedia.org/wikipedia/" + wiki + '/' |
|
|
+ pathcpt + stripped; |
|
|
} |
|
|
return imgurl; |
|
|
} |
|
|
|
|
|
function imageThumbURL(article, wiki, width) { |
|
|
// |
|
|
// eg http://upload.wikimedia.org/wikipedia/en/thumb/6/61/ |
|
|
// Rubiks_cube_solved.jpg/120px-Rubiks_cube_solved.jpg |
|
|
|
|
|
var imgurl=null; |
|
|
if (isInNamespace(article, 'Image')) { |
|
|
var pathcpt = imagePathComponent(article); |
|
|
var stripped=stripNamespace(article); |
|
|
var imgurl="http://upload.wikimedia.org/wikipedia/" + wiki + "/thumb/" |
|
|
+ pathcpt + stripped + '/' + width +"px-" + stripped; |
|
|
} |
|
|
return imgurl; |
|
|
} |
|
|
|
|
|
var imageSources=new Array (); |
|
|
|
|
|
imageSources.push( |
|
|
{wiki: 'en', thumb: true, width: 60}, |
|
|
{wiki: 'en', thumb: true, width: 180}, |
|
|
{wiki: 'en', thumb: true, width: 120}, |
|
|
{wiki: 'en', thumb: false, width: 0}, |
|
|
{wiki: 'commons', thumb: true, width: 60}, |
|
|
{wiki: 'commons', thumb: true, width: 180}, |
|
|
{wiki: 'commons', thumb: true, width: 120}, |
|
|
{wiki: 'commons', thumb: false, width: 0} |
|
|
); |
|
|
|
|
|
//imageSources.push( |
|
|
// {wiki: 'en', thumb: true, width: 120}, |
|
|
// {wiki: 'en', thumb: false, width: 0} |
|
|
// ); |
|
|
|
|
|
|
|
|
var imageArray=new Array(); |
|
|
var popupImageTimer=null; |
|
|
|
|
|
function loadImages(article) { |
|
|
|
|
|
if(! isInNamespace(article, 'Image') ) { |
|
|
return; |
|
|
} |
|
|
|
|
|
for (var i=0; i<imageSources.length; ++i) { |
|
|
|
|
|
var url; |
|
|
|
|
|
if (imageSources.thumb) |
|
|
url=imageThumbURL(article, imageSources.wiki, imageSources.width); |
|
|
else |
|
|
url=imageURL(article, imageSources.wiki); |
|
|
|
|
|
imageArray=new Image(); |
|
|
imageArray.src=url; |
|
|
|
|
|
} |
|
|
if (popupImageTimer != null) { |
|
|
clearInterval(popupImageTimer); |
|
|
counter=0; |
|
|
} |
|
|
popupImageTimer=setInterval("checkImages()", 250); |
|
|
return; |
|
|
} |
|
|
|
|
|
function isImageOk(img) |
|
|
{ |
|
|
// IE test |
|
|
if (!img.complete) |
|
|
return false; |
|
|
|
|
|
// gecko test |
|
|
if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) |
|
|
return false; |
|
|
|
|
|
// No other way of checking: assume it's ok. |
|
|
return true; |
|
|
} |
|
|
|
|
|
var counter=0; |
|
|
var checkImagesTimer=null; |
|
|
var loopcounter=0; |
|
|
|
|
|
function checkImages() { |
|
|
|
|
|
if (checkImagesTimer!=null) { |
|
|
clearInterval(checkImagesTimer); |
|
|
checkImagesTimer=null; |
|
|
if (loopcounter > 10); {loopcounter=0; return;} |
|
|
loopcounter++; |
|
|
} else counter++; |
|
|
|
|
|
// document.title=counter + ',' + loopcounter; |
|
|
var popupImageStatus= |
|
|
document.getElementById("popupImageStatus"+popupImageId); |
|
|
if (popupImageStatus != null) { |
|
|
var status = ( counter % 2 ) ? '*' : '.' ; |
|
|
popupImageStatus.innerHTML=status; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (counter > 100) {counter = 0; clearInterval(popupImageTimer);} |
|
|
|
|
|
var popupImage=null; |
|
|
popupImage=document.getElementById("popupImage"+popupImageId); |
|
|
if (popupImage == null) { |
|
|
// this doesn't seem to happen any more in practise for some reason |
|
|
// still, I'll leave it in |
|
|
checkImagesTimer=setInterval("checkImages()",333); |
|
|
return; |
|
|
} |
|
|
|
|
|
// get the first image to successfully load |
|
|
// and put it in the popupImage |
|
|
for(var i = 0; i < imageArray.length; i++) { |
|
|
if(isImageOk(imageArray)) { |
|
|
|
|
|
clearInterval(popupImageTimer); |
|
|
|
|
|
popupImage.src=imageArray.src; |
|
|
if (popupImageStatus != null) popupImageStatus.innerHTML = ''; |
|
|
// reset evil nonconstant globals |
|
|
var l=imageArray.length; |
|
|
imageArray=null; imageArray=new Array(); |
|
|
popupImageTimer=null; |
|
|
|
|
|
// document.title='got '+hex_md5(popupImage.src)+' after '+counter+' tics'; |
|
|
counter=0; |
|
|
loopcounter=0; |
|
|
return popupImage.src; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
var popupImageId=0; |
|
|
|
|
|
function imageHTML(article) { |
|
|
var imgurl=''; // imageURL(article, 'en'); |
|
|
var ret=''; |
|
|
|
|
|
if (imgurl != null) { |
|
|
popupImageId++; |
|
|
ret += '<img src="' + imgurl + |
|
|
'" width=60 align="right" valign="top" + id="popupImage' |
|
|
+ popupImageId + '"></img>'; |
|
|
} |
|
|
return ret; |
|
|
} |
|
|
|
|
|
var kateBase='http://kohl.wikimedia.org/~kate/cgi-bin/count_edits' |
|
|
+ '?dbname=enwiki&user=' |
|
|
|
|
|
function kateLink(article, text) { |
|
|
return '<a href="' + kateBase + userName(article) + '" title="' |
|
|
+ text + '">' + text + '</a>'; |
|
|
} |
|
|
|
|
|
|
|
|
var decodeExtras = new Array (); |
|
|
decodeExtras = {from: '%2C', to: ',' }; |
|
|
decodeExtras = {from: '_', to: ' ' }; |
|
|
decodeExtras = {from: '%26', to: '&' }; |
|
|
|
|
|
|
|
|
function myDecodeURI (str) { |
|
|
var ret=decodeURI(str); |
|
|
for (var i=0; i<decodeExtras.length; ++i) { |
|
|
var from=decodeExtras.from; |
|
|
var to=decodeExtras.to; |
|
|
ret=ret.split(from).join(to); |
|
|
} |
|
|
return ret; |
|
|
} |
|
|
|
|
|
// defaults |
|
|
var dpopupDelay=1.5; |
|
|
var dpopupFgColor='#CCCCFF'; |
|
|
var dpopupBgColor='#333399'; |
|
|
|
|
|
var popupDelay; |
|
|
var popupFgColor; |
|
|
var popupBgColor; |
|
|
|
|
|
var dremoveTitles=true; |
|
|
var removeTitles; |
|
|
|
|
|
function removeAnchor(article) { |
|
|
// is there a #? if not, we're done |
|
|
var i=article.indexOf('#'); |
|
|
if (i == -1) return article; |
|
|
|
|
|
// head#tail |
|
|
var head = article.substring(0,i); |
|
|
var tail = article.substring(i+1); |
|
|
|
|
|
return head; |
|
|
} |
|
|
|
|
|
function mouseOverWikiLink() { |
|
|
// FIXME: should not generate the HTML until the delay has elapsed, |
|
|
// and then popup immediately. Can be a CPU hog otherwise. |
|
|
|
|
|
var a=this; |
|
|
var h=a.href; |
|
|
|
|
|
var contribs=contributions.exec(h); |
|
|
if (contribs != null) { |
|
|
article='User:'+contribs; |
|
|
} else { |
|
|
var m=re.exec(h); |
|
|
article=m; |
|
|
} |
|
|
var hint=a.originalTitle; |
|
|
if (hint == '' || hint == null) |
|
|
hint = myDecodeURI(article); |
|
|
|
|
|
var html=''; |
|
|
|
|
|
html +=imageHTML(article); |
|
|
|
|
|
html+='<b>'; |
|
|
html+=titledWikiLink(article, 'view', myDecodeURI(article),hint); |
|
|
html+='</b>'; |
|
|
|
|
|
html+='<span id="popupImageStatus'+popupImageId+'"></span>'; |
|
|
|
|
|
// Get rid of anchor now |
|
|
article=removeAnchor(article); |
|
|
|
|
|
if (userName(article) != null) { |
|
|
html += ' ' + contribsLink(article, 'contribs'); |
|
|
html += ' ' + kateLink(article, 'count'); |
|
|
} |
|
|
|
|
|
html += '<br>' + wikiLink(article, 'edit', 'edit'); |
|
|
html += ' ' + wikiLink(article, 'history', 'history'); |
|
|
html += ' (' + wikiLink(article, 'unwatch', 'un') + ')'; |
|
|
html += wikiLink(article, 'watch', 'watch'); |
|
|
var t=talkPage(article); |
|
|
if (t != null) html += ' ' + wikiLink(t, 'view', 'talk') + |
|
|
' ' + wikiLink(t, 'edit', 'editTalk') + |
|
|
' ' + wikiLink(t, 'edit§ion=new', 'newTopic'); |
|
|
var ta=articleFromTalkPage(article); |
|
|
if (ta != null) html +=' ' + |
|
|
wikiLink(article, 'edit§ion=new', 'newTopic') + |
|
|
' ' + wikiLink(ta, 'view', 'article') + |
|
|
' ' + wikiLink(ta, 'edit', 'editArticle'); |
|
|
|
|
|
html += '<br>' + specialLink(article, 'Whatlinkshere', 'whatLinksHere'); |
|
|
html += ' ' + specialLink(article, 'Recentchangeslinked', 'relatedChanges'); |
|
|
|
|
|
if (popupDelay==null) popupDelay=dpopupDelay; |
|
|
if (popupFgColor==null) popupFgColor=dpopupFgColor; |
|
|
if (popupBgColor==null) popupBgColor=dpopupBgColor; |
|
|
|
|
|
overlib(html, STICKY, MOUSEOFF, WRAP, CELLPAD, 5, |
|
|
OFFSETX, 2, OFFSETY, 2, DELAY, popupDelay*1000, |
|
|
FGCOLOR, popupFgColor, BGCOLOR, popupBgColor); |
|
|
|
|
|
loadImages(article); |
|
|
} |
|
|
|
|
|
function setupTooltips() { |
|
|
var anchors=document.getElementsByTagName('A'); |
|
|
// alert(anchors.length + 'anchors'); |
|
|
var s=''; |
|
|
|
|
|
if (removeTitles==null) removeTitles=dremoveTitles; |
|
|
|
|
|
for (var i=0; i<anchors.length; ++i) |
|
|
{ |
|
|
var a=anchors; |
|
|
var h=a.href; |
|
|
var contribs=contributions.exec(h); |
|
|
var exc=exceptions.exec(h); |
|
|
var m=re.exec(h); |
|
|
if (contribs != null || (exc == null && m != null) ) { |
|
|
a.onmouseover=mouseOverWikiLink; |
|
|
a.onmouseout=function () { if ( o3_showingsticky == 0 ) cClick(); } |
|
|
if (removeTitles) { |
|
|
a.originalTitle=a.title; |
|
|
a.title=''; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
if ( typeof mw !== 'undefined' ) { |
|
//////////////////////////////////////////////////////////////////// |
|
|
|
mw.loader.using( , function() { |
|
// Run things |
|
|
|
var k = 'User:Lupin/popups.js', |
|
//////////////////////////////////////////////////////////////////// |
|
|
|
t = 'Information: You are importing User:Lupin/popups.js' + |
|
|
' into your User:USERNAME/common.js or User:USERNAME/<skin>.js!\n' + |
|
|
'This script is unmaintained. Please remove this inclusion and enable the Navigation popups Gadget in the preferences of your account instead.', |
|
|
x = mw.storage.get( k ); |
|
|
|
|
|
|
if ( !x ) { |
|
if (window.addEventListener) |
|
|
|
mw.storage.set( k, 1 ); |
|
window.addEventListener("load",setupTooltips,false); |
|
|
|
alert( t ); |
|
else if (window.attachEvent) |
|
|
|
} else { |
|
window.attachEvent("onload",setupTooltips); |
|
|
|
x++; |
|
else { |
|
|
|
mw.storage.set( k, x ); |
|
window._old_ABCD_onload = window.onload; |
|
|
window.onload = function() { |
|
if ( x % 25 === 0 ) { |
|
|
mw.notify( t ); |
|
window._old_ABCD_onload(); |
|
|
|
} |
|
setupTooltips(); |
|
|
} |
|
} |
|
|
}); |
|
} |
|
} |