Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// <source lang="javascript">/* PrettyLog - reformat log pages. If the log contains file uploads, add small thumbnails of the files. If the GalleryDetails gadget is also activated, make sure that it adds its sidebar link. Authors: [[User:Lupo]], January 2009; [[User:Ilmari Karonen]], April 2010 License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0)*/if(wgCanonicalSpecialPageName=="Log")addOnloadHook(function(){varmaxThumbWidth=70;varmaxThumbHeight=70;varapiBatchSize=50;varmaxPathLength=(/MSIE/.test(navigator.userAgent)?2048:4092)-100;// safety marginvarcontent=document.getElementById("bodyContent")||// monobook & vector skinsdocument.getElementById("mw_contentholder")||// modern skindocument.getElementById("article");// classic skinsif(!content)return;varlist=content.getElementsByTagName("ul")[0];if(!list)return;list.className='mw-search-results';// That's all that's needed for the pretty layout! All code below is for the image thumbnails.// Get list of upload log entries, abort early if there are none.varuploads=getElementsByClassName(list,"li","mw-logline-upload");if(!uploads||uploads.length==0)return;// Find image links within each upload entry. For simplicity, we assume that all links are in// canonical prefixed text form, and that all file links thus begin with ns6prefix. Otherwise// we'd have to extract and normalize the namespace prefix and look for it in wgNamespaceIds.varns6prefix=wgFormattedNamespaces["6"]+":";varimageLocations={};for(vari=0;i<uploads.length;i++){varlinks=uploads[i].getElementsByTagName("a");for(varj=0;j<links.length;j++){vartitle=links[j].title;if(!title||title.substring(0,ns6prefix.length)!=ns6prefix)continue;// Skip any redlinks, links in log summaries and links to uploaders' user/talk/contribs/etc. pagesfor(vare=links[j];title&&e&&e!=uploads[i];e=e.parentNode){if(/(^|\s)(new|comment|mw-userlink|mw-usertoollinks|mw-revdelundel-link|searchResultImage)(\s|$)/.test(e.className))title=null;}if(title){if(!imageLocations[title])imageLocations[title]=[];imageLocations[title].push(uploads[i]);}}}uploads=links=null;// we don't need these NodeLists anymore// Callback function to show the thumbnails:window.prettyLogAddThumbnails=function(result){if(result.error||!result.query||!result.query.pages)thrownewError("PrettyLog: unexpected API result:\n"+result.toSource());// hopefully we don't get any normalization, but just in case...if(result.query.normalized){varnorm=result.query.normalized;for(vari=0;i<norm.length;i++){imageLocations[norm[i].to]=imageLocations[norm[i].from].concat(imageLocations[norm[i].to]||[]);}}// now loop over the result and insert thumbsvarpages=result.query.pages;for(varidinpages){vartitle=pages[id].title;if(!title)continue;// should not happenif(pages[id].imagerepository&&pages[id].imagerepository=="shared")continue;// don't show thumbnails for remote images (could happen if an image shadowing a Commons image is uploaded locally and deleted)varinfo=pages[id].imageinfo;if(!info||!info.length)continue;// can happen if the image has been deleted, or if it wasn't an image at allinfo=info[0];if(!info.thumburl||!info.thumbwidth||!info.thumbheight||!info.descriptionurl)continue;// can happen e.g. for audio files// if the returned thumb is too large for some reason, scale it proportionately so it fitsif(info.thumbheight>maxThumbHeight){info.thumbwidth*=maxThumbHeight/info.thumbheight;info.thumbheight=maxThumbHeight;}if(info.thumbwidth>maxThumbWidth){info.thumbheight*=maxThumbWidth/info.thumbwidth;info.thumbwidth=maxThumbWidth;}// if the URL is local, strip the hostname prefix (avoids needless external link icons on some browsers)if(info.descriptionurl.indexOf(wgServer+"/")===0)info.descriptionurl=info.descriptionurl.substring(wgServer.length);varloglines=imageLocations[title];if(!loglines)continue;// should not happenfor(vari=0;i<loglines.length;i++){// safety check: don't process the same line twiceif(/^table$/i.test(loglines[i].firstChild.tagName))continue;// create image and link elements for the thumbnailvarimg=document.createElement("img");img.src=info.thumburl;img.width=Math.round(info.thumbwidth);img.height=Math.round(info.thumbheight);varlink=document.createElement("a");link.href=info.descriptionurl;link.title=title;link.className="image";link.appendChild(img);// transform the contents of this logline into a tablevartbl=document.createElement("table");tbl.className="searchResultImage";vartr=tbl.insertRow(-1);tr.setAttribute("valign","top");vartd=document.createElement("td");td.width=maxThumbWidth+10;td.setAttribute("align","center");td.appendChild(link);tr.appendChild(td);td=document.createElement("td");while(loglines[i].firstChild)td.appendChild(loglines[i].firstChild);tr.appendChild(td);loglines[i].appendChild(tbl);}}// if [[MediaWiki:Gadget-GalleryDetails.js]] is enabled but inactive, rerun it now that we have some imagesif(typeof(GalleryDetailsLoader)!='undefined'&&!document.getElementById('t-gallerydetails')&&GalleryDetailsLoader.initialized){GalleryDetailsLoader.initialize();}};// Build array of unique image titles and URL-encode them.varimages=[];for(vartitleinimageLocations){if(typeof(title)=='string')images.push(encodeURIComponent(title));}// Make the queries in batches, to avoid tripping API and URL length limits.varqueryPrefix=mw.config.get('wgServer')+mw.config.get('wgScriptPath')+"/api.php?format=json&callback=prettyLogAddThumbnails&action=query&maxage=3600&smaxage=3600&prop=imageinfo&iiprop=url&iiurlwidth="+maxThumbWidth+"&iiurlheight="+maxThumbHeight+"&titles=";while(images.length>0){varquery=queryPrefix+images.shift();varn=1;while(images.length>0&&n<apiBatchSize&&query.length+images[0].length+3<=maxPathLength){query+="%7C"+images.shift();n++;}vars=document.createElement('script');s.src=query;s.type='text/javascript';document.getElementsByTagName('head')[0].appendChild(s);}});//</source>