<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://anotherwiki.org/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-PrettyLog.js</id>
	<title>MediaWiki:Gadget-PrettyLog.js - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://anotherwiki.org/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-PrettyLog.js"/>
	<link rel="alternate" type="text/html" href="https://anotherwiki.org/index.php?title=MediaWiki:Gadget-PrettyLog.js&amp;action=history"/>
	<updated>2026-04-29T10:56:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://anotherwiki.org/index.php?title=MediaWiki:Gadget-PrettyLog.js&amp;diff=727&amp;oldid=prev</id>
		<title>Jarandhel: 1 revision</title>
		<link rel="alternate" type="text/html" href="https://anotherwiki.org/index.php?title=MediaWiki:Gadget-PrettyLog.js&amp;diff=727&amp;oldid=prev"/>
		<updated>2012-04-01T19:08:00Z</updated>

		<summary type="html">&lt;p&gt;1 revision&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;// &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
   PrettyLog - reformat log pages. If the log contains file uploads, add small thumbnails of the&lt;br /&gt;
   files. If the GalleryDetails gadget is also activated, make sure that it adds its sidebar link.&lt;br /&gt;
 &lt;br /&gt;
   Authors: [[User:Lupo]], January 2009; [[User:Ilmari Karonen]], April 2010&lt;br /&gt;
   License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0)&lt;br /&gt;
*/&lt;br /&gt;
 &lt;br /&gt;
if (wgCanonicalSpecialPageName == &amp;quot;Log&amp;quot;) $j(document).ready(function () {&lt;br /&gt;
    var maxThumbWidth = 70;&lt;br /&gt;
    var maxThumbHeight = 70;&lt;br /&gt;
 &lt;br /&gt;
    var apiBatchSize = 50;&lt;br /&gt;
    var maxPathLength = (/MSIE/.test(navigator.userAgent) ? 2048 : 4092 - wgServer.length) - 100; // safety margin&lt;br /&gt;
 &lt;br /&gt;
    var content = document.getElementById(&amp;quot;bodyContent&amp;quot;) ||       // monobook &amp;amp; vector skins&lt;br /&gt;
                  document.getElementById(&amp;quot;mw_contentholder&amp;quot;) ||  // modern skin&lt;br /&gt;
                  document.getElementById(&amp;quot;article&amp;quot;);             // classic skins&lt;br /&gt;
    if (!content) return;&lt;br /&gt;
 &lt;br /&gt;
    var list = content.getElementsByTagName(&amp;quot;ul&amp;quot;)[0];&lt;br /&gt;
    if (!list) return;&lt;br /&gt;
    list.className = &amp;#039;mw-search-results&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
    // That&amp;#039;s all that&amp;#039;s needed for the pretty layout!  All code below is for the image thumbnails.&lt;br /&gt;
 &lt;br /&gt;
    // Get list of upload log entries, abort early if there are none.&lt;br /&gt;
    var uploads = getElementsByClassName(list, &amp;quot;li&amp;quot;, &amp;quot;mw-logline-upload&amp;quot;);&lt;br /&gt;
    if (!uploads || uploads.length == 0) return;&lt;br /&gt;
 &lt;br /&gt;
    // Find image links within each upload entry.  For simplicity, we assume that all links are in&lt;br /&gt;
    // canonical prefixed text form, and that all file links thus begin with ns6prefix.  Otherwise&lt;br /&gt;
    // we&amp;#039;d have to extract and normalize the namespace prefix and look for it in wgNamespaceIds.&lt;br /&gt;
    var ns6prefix = wgFormattedNamespaces[&amp;quot;6&amp;quot;] + &amp;quot;:&amp;quot;;&lt;br /&gt;
    var imageLocations = {};&lt;br /&gt;
    for (var i = 0; i &amp;lt; uploads.length; i++) {&lt;br /&gt;
        var links = uploads[i].getElementsByTagName(&amp;quot;a&amp;quot;);&lt;br /&gt;
        for (var j = 0; j &amp;lt; links.length; j++) {&lt;br /&gt;
            var title = links[j].title;&lt;br /&gt;
            if (!title || title.substring(0, ns6prefix.length) != ns6prefix) continue;&lt;br /&gt;
            // Skip any redlinks, links in log summaries and links to uploaders&amp;#039; user/talk/contribs/etc. pages&lt;br /&gt;
            for (var e = links[j]; title &amp;amp;&amp;amp; e &amp;amp;&amp;amp; e != uploads[i]; e = e.parentNode) {&lt;br /&gt;
                if ( /(^|\s)(new|comment|mw-userlink|mw-usertoollinks|mw-revdelundel-link|searchResultImage)(\s|$)/.test(e.className) ) title = null;&lt;br /&gt;
            }&lt;br /&gt;
            if (title) {&lt;br /&gt;
                if (!imageLocations[title]) imageLocations[title] = [];&lt;br /&gt;
                imageLocations[title].push(uploads[i]);&lt;br /&gt;
            }                 &lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    uploads = links = null;  // we don&amp;#039;t need these NodeLists anymore&lt;br /&gt;
 &lt;br /&gt;
    // Callback function to show the thumbnails:&lt;br /&gt;
    window.prettyLogAddThumbnails = function (result) {&lt;br /&gt;
 &lt;br /&gt;
        if (result.error || !result.query || !result.query.pages)&lt;br /&gt;
            throw new Error(&amp;quot;PrettyLog: unexpected API result:\n&amp;quot; + result.toSource());&lt;br /&gt;
 &lt;br /&gt;
        // hopefully we don&amp;#039;t get any normalization, but just in case...&lt;br /&gt;
        if (result.query.normalized) {&lt;br /&gt;
            var norm = result.query.normalized;&lt;br /&gt;
            for (var i = 0; i &amp;lt; norm.length; i++) {&lt;br /&gt;
                imageLocations[norm[i].to] = imageLocations[norm[i].from].concat( imageLocations[norm[i].to] || [] );&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // now loop over the result and insert thumbs&lt;br /&gt;
        var pages = result.query.pages;&lt;br /&gt;
        for (var id in pages) {&lt;br /&gt;
            var title = pages[id].title;&lt;br /&gt;
            if (!title) continue;  // should not happen&lt;br /&gt;
 &lt;br /&gt;
            if (pages[id].imagerepository &amp;amp;&amp;amp; pages[id].imagerepository == &amp;quot;shared&amp;quot;)&lt;br /&gt;
                continue;  // don&amp;#039;t show thumbnails for remote images (could happen if an image shadowing a Commons image is uploaded locally and deleted)&lt;br /&gt;
 &lt;br /&gt;
            var info = pages[id].imageinfo;&lt;br /&gt;
            if (!info || !info.length) continue;  // can happen if the image has been deleted, or if it wasn&amp;#039;t an image at all&lt;br /&gt;
            info = info[0];&lt;br /&gt;
 &lt;br /&gt;
            if (!info.thumburl) {&lt;br /&gt;
                // KLUGE: for some reason, audio files sometimes get no thumburl; fix it here&lt;br /&gt;
                // TODO(?): there are more file type icons we could match to MIME types if needed&lt;br /&gt;
                if (/^(audio\/|application\/ogg$)/.test(info.mime)) {&lt;br /&gt;
                    info.thumburl = stylepath + &amp;quot;/common/images/icons/fileicon-ogg.png&amp;quot;;&lt;br /&gt;
                } else {&lt;br /&gt;
                    info.thumburl = stylepath + &amp;quot;/common/images/icons/fileicon.png&amp;quot;;  // generic fallback icon&lt;br /&gt;
                }&lt;br /&gt;
                info.thumbwidth = info.thumbheight = 120;  // all icons are currently 120x120&lt;br /&gt;
            }&lt;br /&gt;
 &lt;br /&gt;
            if (!info.thumbwidth || !info.thumbheight || !info.descriptionurl) continue;  // can&amp;#039;t happen?&lt;br /&gt;
 &lt;br /&gt;
            // if the returned thumb is too large for some reason, scale it proportionately so it fits&lt;br /&gt;
            if (info.thumbheight &amp;gt; maxThumbHeight) {&lt;br /&gt;
                info.thumbwidth *= maxThumbHeight / info.thumbheight;&lt;br /&gt;
                info.thumbheight = maxThumbHeight;&lt;br /&gt;
            }&lt;br /&gt;
            if (info.thumbwidth &amp;gt; maxThumbWidth) {&lt;br /&gt;
                info.thumbheight *= maxThumbWidth / info.thumbwidth;&lt;br /&gt;
                info.thumbwidth = maxThumbWidth;&lt;br /&gt;
            }&lt;br /&gt;
 &lt;br /&gt;
            // if the URL is local, strip the hostname prefix (avoids needless external link icons on some browsers)&lt;br /&gt;
            if (info.descriptionurl.indexOf(wgServer + &amp;quot;/&amp;quot;) === 0)&lt;br /&gt;
                info.descriptionurl = info.descriptionurl.substring(wgServer.length);&lt;br /&gt;
 &lt;br /&gt;
            var loglines = imageLocations[title];&lt;br /&gt;
            if (!loglines) continue;  // should not happen&lt;br /&gt;
 &lt;br /&gt;
            for (var i = 0; i &amp;lt; loglines.length; i++) {&lt;br /&gt;
                // safety check: don&amp;#039;t process the same line twice&lt;br /&gt;
                if (/^table$/i.test(loglines[i].firstChild.tagName)) continue;&lt;br /&gt;
 &lt;br /&gt;
                // create image and link elements for the thumbnail&lt;br /&gt;
                var img = document.createElement(&amp;quot;img&amp;quot;);&lt;br /&gt;
                img.src = info.thumburl;&lt;br /&gt;
                img.width = Math.round(info.thumbwidth);&lt;br /&gt;
                img.height = Math.round(info.thumbheight);&lt;br /&gt;
 &lt;br /&gt;
                var link = document.createElement(&amp;quot;a&amp;quot;);&lt;br /&gt;
                link.href = info.descriptionurl;&lt;br /&gt;
                link.title = title;&lt;br /&gt;
                link.className = &amp;quot;image&amp;quot;;&lt;br /&gt;
                link.appendChild(img);&lt;br /&gt;
 &lt;br /&gt;
                // transform the contents of this logline into a table&lt;br /&gt;
                var tbl = document.createElement(&amp;quot;table&amp;quot;);&lt;br /&gt;
                tbl.className = &amp;quot;searchResultImage&amp;quot;;&lt;br /&gt;
                var tr = tbl.insertRow(-1);&lt;br /&gt;
                tr.setAttribute(&amp;quot;valign&amp;quot;, &amp;quot;top&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
                var td = document.createElement(&amp;quot;td&amp;quot;);&lt;br /&gt;
                td.width = maxThumbWidth + 10;&lt;br /&gt;
                td.setAttribute(&amp;quot;align&amp;quot;, &amp;quot;center&amp;quot;);&lt;br /&gt;
                td.appendChild(link);&lt;br /&gt;
                tr.appendChild(td);&lt;br /&gt;
 &lt;br /&gt;
                td = document.createElement(&amp;quot;td&amp;quot;);&lt;br /&gt;
                while (loglines[i].firstChild) td.appendChild(loglines[i].firstChild);&lt;br /&gt;
                tr.appendChild(td);&lt;br /&gt;
 &lt;br /&gt;
                loglines[i].appendChild (tbl);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        // if [[MediaWiki:Gadget-GalleryDetails.js]] is enabled but inactive, rerun it now that we have some images&lt;br /&gt;
        if (typeof (GalleryDetailsLoader) != &amp;#039;undefined&amp;#039; &amp;amp;&amp;amp; !document.getElementById(&amp;#039;t-gallerydetails&amp;#039;) &amp;amp;&amp;amp; GalleryDetailsLoader.initialized) {&lt;br /&gt;
            GalleryDetailsLoader.initialize();        &lt;br /&gt;
        }&lt;br /&gt;
    };&lt;br /&gt;
 &lt;br /&gt;
    // Build array of unique image titles and URL-encode them.&lt;br /&gt;
    var images = [];&lt;br /&gt;
    for (var title in imageLocations) {&lt;br /&gt;
        if (typeof (title) == &amp;#039;string&amp;#039;) images.push( encodeURIComponent( title ) );&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // Make the queries in batches, to avoid tripping API and URL length limits.&lt;br /&gt;
    var queryPrefix = wgScriptPath + &amp;quot;/api.php?format=json&amp;amp;callback=prettyLogAddThumbnails&amp;amp;action=query&amp;amp;maxage=3600&amp;amp;smaxage=3600&amp;amp;prop=imageinfo&amp;amp;iiprop=url%7Cmime&amp;amp;iiurlwidth=&amp;quot;+maxThumbWidth+&amp;quot;&amp;amp;iiurlheight=&amp;quot;+maxThumbHeight+&amp;quot;&amp;amp;titles=&amp;quot;;&lt;br /&gt;
    while (images.length &amp;gt; 0) {&lt;br /&gt;
        var query = queryPrefix + images.shift();&lt;br /&gt;
        var n = 1;&lt;br /&gt;
        while (images.length &amp;gt; 0 &amp;amp;&amp;amp; n &amp;lt; apiBatchSize &amp;amp;&amp;amp; query.length + images[0].length + 3 &amp;lt;= maxPathLength) {&lt;br /&gt;
            query += &amp;quot;%7C&amp;quot; + images.shift(); n++;&lt;br /&gt;
        }&lt;br /&gt;
        importScriptURI(query);&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
 &lt;br /&gt;
//&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jarandhel</name></author>
	</entry>
</feed>