/* If you want to use this script, simply add the following lines to your monobook.js: importScript('User:Anomie/previewtemplatelastmod.js'); // Linkback: ] * (Please keep the comment so I can see how many people use this). */ var PreviewTemplateLastMod={ node:null, LIs:, callback:function(r, sts, xhr){ if(!r.query){ if(typeof(window.console)=='undefined' || typeof(window.console.error)!='function') throw new Error('Bad response'); window.console.error("Bad response", r); return; } r=r.query; var node=PreviewTemplateLastMod.node; if(!node) return; var a=node.getElementsByTagName('A'); if(a.length==0) return; var pages={}; if(r.pages) for(var i in r.pages){ pages.title]=r.pages; } for(var j=a.length-1; j>=0; j--){ if(typeof(a.wikipage)=='undefined') continue; if(a.href.indexOf('action=edit')>=0) continue; if(typeof(pages.wikipage])=='undefined') continue; var p=pages.wikipage]; var li; for(li=a; li && li.nodeName!='LI'; li=li.parentNode); if(!li) continue; if(typeof(p.watched)!='undefined'){ a.className+=' mw-watched'; li.className+=' mw-watched'; } if(typeof(p.revisions)=='undefined') continue; var r=p.revisions; li.timestamp=r.timestamp; PreviewTemplateLastMod.LIs.push(li); var b=li.firstChild; var dt=r.timestamp.match(/^(\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d):\d\dZ$/); if(!dt) throw new Error('Invalid timestamp: '+r.timestamp); var s=document.createElement('SPAN'); s.className='PreviewTemplateLastMod_timestamp'; s.appendChild(document.createTextNode(dt+' '+dt+' '), li.firstChild); li.insertBefore(s, b); li.insertBefore(document.createTextNode('('), b); var x=document.createElement('A'); x.href=a.href+((a.href.indexOf('?')<0)?'?':'&')+'action=history'; x.className='PreviewTemplateLastMod_history'; x.appendChild(document.createTextNode('hist')); li.insertBefore(x, b); li.insertBefore(document.createTextNode(') '), b); li.appendChild(document.createTextNode(' ')); x=document.createElement('A'); x.href=mw.util.wikiScript()+'?title=User:'+encodeURIComponent(r.user); x.className='PreviewTemplateLastMod_user'; x.appendChild(document.createTextNode(r.user)); li.appendChild(x); li.appendChild(document.createTextNode(': ')); var s=document.createElement('SPAN'); if(typeof(r.comment) == 'undefined') { s.className='PreviewTemplateLastMod_no_comment'; s.appendChild(document.createTextNode('(no summary)')); } else { s.className='PreviewTemplateLastMod_comment'; s.appendChild(document.createTextNode(r.comment)); } li.appendChild(s); } PreviewTemplateLastMod.LIs.sort(function(a,b){ return (a.timestampb.timestamp)?1:0; }); var cur=PreviewTemplateLastMod.LIs.parentNode.firstChild; for(var j=PreviewTemplateLastMod.LIs.length-1; j>=0; j--){ if(PreviewTemplateLastMod.LIs===cur){ cur=cur.nextSibling; } else { cur.parentNode.insertBefore(PreviewTemplateLastMod.LIs,cur); } } }, onLoad:function(){ var node=$('div.templatesUsed'); if(!node || node.length!=1) return; node=node; PreviewTemplateLastMod.node=node; var a=node.getElementsByTagName('A'); if(a.length==0) return; a=Array.prototype.map.call(a, function(a){ a.wikipage=a.title; return a.wikipage; }).sort().filter(function(e,i,a){ return e!=='' && (i==0 || a!==e); }); while(a.length>0){ $.ajax({ url:mw.util.wikiScript('api'), dataType:'json', type:'POST', data:{ format:'json', action:'query', titles:a.splice(0,50).join('|'), prop:'info|revisions', rvprop:'timestamp|user|comment', inprop:'watched' }, success:PreviewTemplateLastMod.callback, error:function(xhr,textStatus,errorThrown){ throw new Error('AJAX error: '+textStatus+' '+errorThrown); } }); } } }; mw.loader.using('mediawiki.util', function(){ $(document).ready(PreviewTemplateLastMod.onLoad); });