More actions
No edit summary |
No edit summary |
||
| Line 356: | Line 356: | ||
}); | }); | ||
mw.loader.using(['jquery', 'mediawiki. | mw.loader.using(['jquery', 'mediawiki.api'], function () { | ||
$(function () { | $(function () { | ||
$('.main-banner[data-files]').each(function () { | $('.main-banner[data-files]').each(function () { | ||
var $box = $(this); | var $box = $(this); | ||
var list = String($box.attr('data-files')) | var list = String($box.attr('data-files')) | ||
.split(/\s*\|\s*|\s*,\s*/) | .split(/\s*\|\s*|\s*,\s*/) | ||
| Line 368: | Line 367: | ||
if (!list.length) return; | if (!list.length) return; | ||
var pick = list[Math.floor(Math.random() * list.length)]; | var pick = list[Math.floor(Math.random() * list.length)]; | ||
// | // Use MediaWiki API to resolve actual file path | ||
new mw.Api().get({ | |||
action: 'query', | |||
titles: 'File:' + pick, | |||
prop: 'imageinfo', | |||
iiprop: 'url', | |||
format: 'json' | |||
}).done(function (data) { | |||
var pages = data.query.pages; | |||
for (var pageId in pages) { | |||
if (pages.hasOwnProperty(pageId) && pages[pageId].imageinfo) { | |||
var url = pages[pageId].imageinfo[0].url; | |||
var $img = $('<img>', { | |||
src: url, | |||
width: 2450, | |||
height: 450, | |||
alt: '' | |||
}); | |||
$box.empty().append($img); | |||
} | |||
} | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||
}); | }); | ||