Entkolonialisierung/Apartheid und Widget:Autorenbox: Unterschied zwischen den Seiten
Aus ZUM-Unterrichten
< Entkolonialisierung(Unterschied zwischen Seiten)
(+Weblinks) Markierung: 2017-Quelltext-Bearbeitung |
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
||
Zeile 1: | Zeile 1: | ||
<includeonly> | |||
<div class="uk-panel uk-panel-box uk-panel-box-primary zum-hintergrund-links zum-farbe-xx-heller uk-hidden"> | |||
<strong>Autoren</strong> | |||
<small class="uk-align-right" data-zum-hook="last-modified">aktualisiert am: </small> | |||
<div class="uk-flex uk-flex-wrap uk-width-1-1" data-zum-hook="userlist"> | |||
</div> | </div> | ||
</div> | |||
<script type="text/javascript"> | |||
(function(){ | |||
const paramArtikel = "<!--{$artikel|escape:'javascript'}-->"||null; | |||
const paramKategorie = "<!--{$kategorie|escape:'javascript'}-->"||null; | |||
=== | const element = document.currentScript && document.currentScript.previousElementSibling; | ||
if(element){ | |||
window.RLQ.push(function(){ | |||
mw.loader.enqueue(['mediawiki.api'], function(){ | |||
const getCurrentTitle = () => mw.Title.makeTitle( | |||
mw.config.get('wgNamespaceNumber'), | |||
mw.config.get('wgTitle') | |||
).getPrefixedText() | |||
; | |||
const userlistEl = $(element).find('[data-zum-hook="userlist"]'); | |||
const lastModifiedEl = $(element).find('[data-zum-hook="last-modified"]'); | |||
const api = new mw.Api(); | |||
const query = paramKategorie ? { | |||
action:'query', | |||
indexpageids: 1, | |||
prop:['revisions', 'contributors', 'info'], | |||
generator: 'categorymembers', | |||
gcmtitle: `Kategorie:${paramKategorie}`, | |||
gcmnamespace:0, | |||
gcmtype: 'page', | |||
gcmlimit: 500, | |||
rvlimit:1000 | |||
} : { | |||
action:'query', | |||
indexpageids: 1, | |||
prop:['revisions', 'contributors', 'info'], | |||
titles: paramArtikel || getCurrentTitle(), | |||
rvlimit:1000 | |||
}; | |||
const response = api.get(query); | |||
response.then((data) => { | |||
//TODO continuation handling | |||
if (data.query.pageids[0] === "-1") { | |||
return; | |||
} | |||
const userCounts = data.query.pageids.reduce((acc, pageid) => { | |||
const pageData = data | |||
.query | |||
.pages[pageid]; | |||
acc.lastmodified = Math.max(acc.lastmodified, Date.parse(pageData.touched)); | |||
acc = pageData | |||
.contributors | |||
.reduce((acc, c)=> {acc.userChanges[c.name] = acc.userChanges[c.name]||{count:0, last:0, id:c.id}; return acc;}, acc); | |||
acc = pageData.revisions.reduce((acc, r) => { | |||
acc.userChanges[r.user] = acc.userChanges[r.user] || {count:0, last:0}; | |||
acc.userChanges[r.user].count += r.minor === '' ? 0.1 : 1; | |||
acc.userChanges[r.user].last = Math.max(acc.userChanges[r.user].last, r.revid); | |||
return acc; | |||
}, acc); | |||
return acc; | |||
}, {lastmodified: -1, userChanges:{}}); | |||
const usernames = Object.keys(userCounts.userChanges).sort((a,b) => { | |||
let diff = userCounts.userChanges[b].count - userCounts.userChanges[a].count; | |||
if(diff !== 0){ | |||
return diff; | |||
} | |||
return userCounts.userChanges[b].last - userCounts.userChanges[a].last; | |||
}) | |||
{{ | $(lastModifiedEl).append(new Date(userCounts.lastmodified).toLocaleDateString()); | ||
const userdatas = usernames.map((user) => api | |||
.parse(`{{#avatar:${user}|l}}`) | |||
.then((imgTag) => $(imgTag)) | |||
.then((img$) => img$.find('img').andSelf().filter('img').attr('src')) | |||
.then((imgSrc) => {return {user, imgSrc};}) | |||
.fail((ignored)=> null) | |||
); | |||
$.when(...userdatas) | |||
.then((...userdatas) => userdatas.filter((ud) => ud !== null)) | |||
.then((userdatas) => { | |||
userdatas.forEach(({user, imgSrc}) => { | |||
$('<img>') | |||
.attr('src', imgSrc) | |||
.wrap('<a>') | |||
.parent() | |||
.attr('href', mw.Title.makeTitle(mw.config.get('wgNamespaceIds')['benutzer'], user).getUrl()) | |||
.wrap('<div class="uk-border-circle uk-text-center" style="overflow:hidden;width:60%;margin:auto;">') | |||
.parent() | |||
.wrap('<div class="uk-panel uk-panel-border uk-text-small" style="max-width:12ch">') | |||
== | .parent() | ||
.append($('<a>').append(user).attr('href', mw.Title.makeTitle(mw.config.get('wgNamespaceIds')['benutzer'], user).getUrl()).wrap('<div class="uk-text-center uk-text-truncate">').parent()) .appendTo($(userlistEl)); | |||
}); | |||
}) | |||
.then((ignored) => $(element).removeClass('uk-hidden')); | |||
});//end response.then | |||
});//end loader.enqueue | |||
});//end RLQ.push | |||
}//end if | |||
})(); | |||
</script> | |||
</includeonly> |