Revision as of 23:02, 2 August 2005 view sourceLupin (talk | contribs)19,513 edits exclude section editing links, handle #anchors properly, less moronic namespace removal, link from talk page links to corresponding articles← Previous edit |
Revision as of 05:04, 3 August 2005 view source Lupin (talk | contribs)19,513 edits image loading improved - can load thumbs, and also commons imagesNext edit → |
Line 2: |
Line 2: |
|
// Popup stuff |
|
// Popup stuff |
|
//////////////////////////////////////////////////////////////////// |
|
//////////////////////////////////////////////////////////////////// |
|
|
|
|
|
document.write('<script type="text/javascript" src="/search/?title=User:Lupin/md5.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); |
|
|
|
|
|
document.write('<script type="text/javascript" src="/search/?title=User:Lupin/overlib.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); |
|
document.write('<script type="text/javascript" src="/search/?title=User:Lupin/overlib.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); |
|
|
|
|
document.write('<script type="text/javascript" src="/search/?title=User:Lupin/md5.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); |
|
|
|
|
|
|
// we're not set up for interwiki stuff yet - only affect en links |
|
// we're not set up for interwiki stuff yet - only affect en links |
|
|
|
|
|
var re=/*:\/\/en\.wikipedia\.org\/w(iki\/|\/index\.php\?title=)(*)/ |
|
var re=/*:\/\/en\.wikipedia\.org\/w(iki\/|\/index\.php\?title=)(*)/ |
|
|
|
|
// omit Special and section editing links |
|
|
|
|
|
var exceptions=/((title=|\/)Special:|section=)/ |
|
var exceptions=/((title=|\/)Special:|section=)/ |
|
var contributions=/(title=|\/)Special:Contributions&target=(.*)/ |
|
var contributions=/(title=|\/)Special:Contributions&target=(.*)/ |
Line 24: |
Line 21: |
|
|
|
|
|
function titledWikiLink(article, action, text, title) { |
|
function titledWikiLink(article, action, text, title) { |
|
base = titlebase + article; |
|
var base = titlebase + article; |
|
url=base; |
|
var url=base; |
|
// no need to add action&view, and this confuses anchors |
|
// no need to add action&view, and this confuses anchors |
|
if (action != 'view') url = base + '&action=' + action; |
|
if (action != 'view') url = base + '&action=' + action; |
|
|
|
|
|
var hint; |
|
if (title == null || title == '') |
|
if (title == null || title == '') |
|
hint = '' |
|
hint = '' |
Line 37: |
Line 36: |
|
|
|
|
|
function specialLink(article, specialpage, text) { |
|
function specialLink(article, specialpage, text) { |
|
base = titlebase + 'Special:'+specialpage; |
|
var base = titlebase + 'Special:'+specialpage; |
|
url = base + '&target=' + article; |
|
var url = base + '&target=' + article; |
|
hint = myDecodeURI(specialpage+':'+article) ; |
|
var hint = myDecodeURI(specialpage+':'+article) ; |
|
return '<a href="' + url + '" title="' + hint + '">' + text + '</a>'; |
|
return '<a href="' + url + '" title="' + hint + '">' + text + '</a>'; |
|
} |
|
} |
Line 47: |
Line 46: |
|
return null; |
|
return null; |
|
|
|
|
|
i=article.indexOf(':'); |
|
var i=article.indexOf(':'); |
|
if (i == -1) return 'Talk:'+article; |
|
if (i == -1) return 'Talk:'+article; |
|
else return article.substring(0,i)+'_talk:' + article.substring(i+1); |
|
else return article.substring(0,i)+'_talk:' + article.substring(i+1); |
|
|
|
|
} |
|
} |
|
|
|
|
|
function articleFromTalkPage(talkpage) { |
|
function articleFromTalkPage(talkpage) { |
|
i=talkpage.indexOf('Talk:'); |
|
var i=talkpage.indexOf('Talk:'); |
|
j=talkpage.indexOf('_talk:'); |
|
var j=talkpage.indexOf('_talk:'); |
|
if ( i == -1 && j == -1 ) |
|
if ( i == -1 && j == -1 ) |
|
return null; |
|
return null; |
Line 61: |
Line 59: |
|
return talkpage.split('_talk:').join(':'); |
|
return talkpage.split('_talk:').join(':'); |
|
} |
|
} |
|
|
|
|
|
|
|
|
function userName(article) { |
|
function userName(article) { |
|
i=article.indexOf('User'); |
|
var i=article.indexOf('User'); |
|
j=article.indexOf(':'); |
|
var j=article.indexOf(':'); |
|
if (i != 0 || j < -1) return null; |
|
if (i != 0 || j < -1) return null; |
|
k=article.indexOf('/'); |
|
var k=article.indexOf('/'); |
|
if (k==-1) return article.substring(j+1); |
|
if (k==-1) return article.substring(j+1); |
|
else return article.substring(j+1,k); |
|
else return article.substring(j+1,k); |
Line 73: |
Line 70: |
|
|
|
|
|
function isInNamespace(article, namespace) { |
|
function isInNamespace(article, namespace) { |
|
i=article.indexOf(namespace+':'); |
|
var i=article.indexOf(namespace+':'); |
|
j=article.indexOf(namespace+'_talk:'); |
|
var j=article.indexOf(namespace+'_talk:'); |
|
if (i == -1 && j == -1) return false; |
|
if (i == -1 && j == -1) return false; |
|
return true; |
|
return true; |
Line 82: |
Line 79: |
|
// this isn't very sophisticated |
|
// this isn't very sophisticated |
|
// it just removes everything up to the final : |
|
// it just removes everything up to the final : |
|
list = article.split(':'); |
|
var list = article.split(':'); |
|
return list; |
|
return list; |
|
} |
|
} |
|
|
|
|
|
function imageHTML(article) { |
|
function contribsLink(article, text) { |
|
|
return specialLink(userName(article), 'Contributions', text); |
|
|
} |
|
|
|
|
|
function imagePathComponent(article) { |
|
if (isInNamespace(article, 'Image')) { |
|
if (isInNamespace(article, 'Image')) { |
|
stripped=stripNamespace(article); |
|
var stripped=stripNamespace(article); |
|
forhash=myDecodeURI(stripped).split(' ').join('_'); |
|
var forhash=myDecodeURI(stripped).split(' ').join('_'); |
|
hash=hex_md5(forhash); |
|
var hash=hex_md5(forhash); |
|
|
var pathcpt=hash.substring(0,1) + '/' + hash.substring(0,2) + '/'; |
|
|
return pathcpt; |
|
|
} |
|
|
else return null; |
|
|
} |
|
|
|
|
|
|
function imageURL(article, wiki) { |
|
// pathComponent is the mysterious bit of the image url, like 4/4a/ |
|
|
|
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) { |
|
pathComponent=hash.substring(0,1) + '/' + hash.substring(0,2) + '/'; |
|
|
|
// |
|
imgurl="http://upload.wikimedia.org/wikipedia/en/" + pathComponent + stripped; |
|
|
|
// 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; |
|
} |
|
} |
|
else imgurl=null; |
|
return imgurl; |
|
|
} |
|
|
|
|
|
var imageSources=new Array (); |
|
|
|
|
|
|
imageSources.push( |
|
ret=''; |
|
|
|
{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( |
|
if (imgurl != null) { |
|
|
|
// {wiki: 'en', thumb: true, width: 120}, |
|
ret += '<img src="' + imgurl |
|
|
|
// {wiki: 'en', thumb: false, width: 0} |
|
+ '" width=60 align="right" valign="top"></img>'; |
|
|
|
// ); |
|
|
|
|
|
|
|
|
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; |
|
} |
|
} |
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
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 contribsLink(article, text) { |
|
|
|
|
|
return specialLink(userName(article), 'Contributions', text); |
|
|
|
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; |
|
} |
|
} |
|
|
|
|
|
kateBase='http://kohl.wikimedia.org/~kate/cgi-bin/count_edits?dbname=enwiki&user=' |
|
var kateBase='http://kohl.wikimedia.org/~kate/cgi-bin/count_edits' |
|
|
+ '?dbname=enwiki&user=' |
|
|
|
|
|
function kateLink(article, text) { |
|
function kateLink(article, text) { |
Line 119: |
Line 265: |
|
+ text + '">' + text + '</a>'; |
|
+ text + '">' + text + '</a>'; |
|
} |
|
} |
|
|
|
|
|
|
|
|
var decodeExtras = new Array (); |
|
var decodeExtras = new Array (); |
Line 124: |
Line 271: |
|
decodeExtras = {from: '_', to: ' ' }; |
|
decodeExtras = {from: '_', to: ' ' }; |
|
decodeExtras = {from: '%26', to: '&' }; |
|
decodeExtras = {from: '%26', to: '&' }; |
|
|
|
|
|
|
|
|
function myDecodeURI (str) { |
|
function myDecodeURI (str) { |
|
ret=decodeURI(str); |
|
var ret=decodeURI(str); |
|
for ( i=0; i<decodeExtras.length; ++i) { |
|
for (var i=0; i<decodeExtras.length; ++i) { |
|
from=decodeExtras.from; |
|
var from=decodeExtras.from; |
|
to=decodeExtras.to; |
|
var to=decodeExtras.to; |
|
ret=ret.split(from).join(to); |
|
ret=ret.split(from).join(to); |
|
} |
|
} |
Line 136: |
Line 284: |
|
|
|
|
|
// defaults |
|
// defaults |
|
var dpopupDelay=2; |
|
var dpopupDelay=1.5; |
|
var dpopupFgColor='#CCCCFF'; |
|
var dpopupFgColor='#CCCCFF'; |
|
var dpopupBgColor='#333399'; |
|
var dpopupBgColor='#333399'; |
Line 146: |
Line 294: |
|
var dremoveTitles=true; |
|
var dremoveTitles=true; |
|
var removeTitles; |
|
var removeTitles; |
|
|
|
|
|
|
|
|
function removeAnchor(article) { |
|
function removeAnchor(article) { |
|
// is there a #? if not, we're done |
|
// is there a #? if not, we're done |
|
i=article.indexOf('#'); |
|
var i=article.indexOf('#'); |
|
if (i == -1) return article; |
|
if (i == -1) return article; |
|
|
|
|
|
// head#tail |
|
// head#tail |
|
head = article.substring(0,i); |
|
var head = article.substring(0,i); |
|
tail = article.substring(i+1); |
|
var tail = article.substring(i+1); |
|
|
|
|
|
return head; |
|
return head; |
Line 161: |
Line 308: |
|
|
|
|
|
function mouseOverWikiLink() { |
|
function mouseOverWikiLink() { |
|
|
// FIXME: should not generate the HTML until the delay has elapsed, |
|
a=this; |
|
|
|
// and then popup immediately. Can be a CPU hog otherwise. |
|
h=a.href; |
|
|
|
|
|
|
var a=this; |
|
|
var h=a.href; |
|
|
|
|
|
var contribs=contributions.exec(h); |
|
var contribs=contributions.exec(h); |
Line 171: |
Line 321: |
|
article=m; |
|
article=m; |
|
} |
|
} |
|
|
var hint=a.originalTitle; |
|
|
|
|
hint=a.originalTitle; |
|
|
if (hint == '' || hint == null) |
|
if (hint == '' || hint == null) |
|
hint = myDecodeURI(article); |
|
hint = myDecodeURI(article); |
|
|
|
|
|
|
|
html=''; |
|
var html=''; |
|
|
|
|
|
html +=imageHTML(article); |
|
html +=imageHTML(article); |
|
|
|
|
html +='<b>'; |
|
|
html += titledWikiLink(article, 'view', myDecodeURI(article),hint); |
|
html+='<b>'; |
|
|
html+=titledWikiLink(article, 'view', myDecodeURI(article),hint); |
|
html +='</b>'; |
|
html+='</b>'; |
|
|
|
|
|
html+='<span id="popupImageStatus'+popupImageId+'"></span>'; |
|
|
|
|
|
// Get rid of anchor now |
|
// Get rid of anchor now |
Line 190: |
Line 342: |
|
html += ' ' + kateLink(article, 'count'); |
|
html += ' ' + kateLink(article, 'count'); |
|
} |
|
} |
|
|
|
|
html += '<br>' + wikiLink(article, 'edit', 'edit'); |
|
html += '<br>' + wikiLink(article, 'edit', 'edit'); |
|
html += ' ' + wikiLink(article, 'history', 'history'); |
|
html += ' ' + wikiLink(article, 'history', 'history'); |
|
html += ' (' + wikiLink(article, 'unwatch', 'un') + ')'; |
|
html += ' (' + wikiLink(article, 'unwatch', 'un') + ')'; |
|
html += '' + wikiLink(article, 'watch', 'watch'); |
|
html += wikiLink(article, 'watch', 'watch'); |
|
t=talkPage(article); |
|
var t=talkPage(article); |
|
if (t != null) html += ' ' + wikiLink(t, 'view', 'talk') + |
|
if (t != null) html += ' ' + wikiLink(t, 'view', 'talk') + |
|
' ' + wikiLink(t, 'edit', 'editTalk') + |
|
' ' + wikiLink(t, 'edit', 'editTalk') + |
|
' ' + wikiLink(t, 'edit§ion=new', 'newTopic'); |
|
' ' + wikiLink(t, 'edit§ion=new', 'newTopic'); |
|
|
var ta=articleFromTalkPage(article); |
|
|
|
|
ta=articleFromTalkPage(article); |
|
|
if (ta != null) html +=' ' + |
|
if (ta != null) html +=' ' + |
|
wikiLink(article, 'edit§ion=new', 'newTopic') + |
|
wikiLink(article, 'edit§ion=new', 'newTopic') + |
|
' ' + wikiLink(ta, 'view', 'article') + |
|
' ' + wikiLink(ta, 'view', 'article') + |
|
' ' + wikiLink(ta, 'edit', 'editArticle'); |
|
' ' + wikiLink(ta, 'edit', 'editArticle'); |
|
|
|
|
|
|
|
html += '<br>' + specialLink(article, 'Whatlinkshere', 'whatLinksHere'); |
|
html += '<br>' + specialLink(article, 'Whatlinkshere', 'whatLinksHere'); |
|
html += ' ' + specialLink(article, 'Recentchangeslinked', 'relatedChanges'); |
|
html += ' ' + specialLink(article, 'Recentchangeslinked', 'relatedChanges'); |
Line 215: |
Line 367: |
|
OFFSETX, 2, OFFSETY, 2, DELAY, popupDelay*1000, |
|
OFFSETX, 2, OFFSETY, 2, DELAY, popupDelay*1000, |
|
FGCOLOR, popupFgColor, BGCOLOR, popupBgColor); |
|
FGCOLOR, popupFgColor, BGCOLOR, popupBgColor); |
|
|
|
|
|
loadImages(article); |
|
} |
|
} |
|
|
|
|
|
function setupTooltips() { |
|
function setupTooltips() { |
|
var anchors=document.getElementsByTagName('A'); |
|
var anchors=document.getElementsByTagName('A'); |
|
|
// alert(anchors.length + 'anchors'); |
|
var s=''; |
|
var s=''; |
|
|
|
|
|
if (removeTitles==null) removeTitles=dremoveTitles; |
|
if (removeTitles==null) removeTitles=dremoveTitles; |
|
|
|
|
|
for (i=0; i<anchors.length; ++i) |
|
for (var i=0; i<anchors.length; ++i) |
|
{ |
|
{ |
|
a=anchors; |
|
var a=anchors; |
|
h=a.href; |
|
var h=a.href; |
|
var contribs=contributions.exec(h); |
|
var contribs=contributions.exec(h); |
|
var exc=exceptions.exec(h); |
|
var exc=exceptions.exec(h); |