Widget:Autorenbox: Unterschied zwischen den Versionen
Aus ZUM-Unterrichten
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
||
(6 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 9: | Zeile 9: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
(function(){ | (function(){ | ||
const paramArtikel = "<!--{$artikel|escape:'javascript'}-->"||null; | |||
const kategorieArtikel = "<!--{$kategorie|escape:'javascript'}-->"||null; | |||
const element = document.currentScript && document.currentScript.previousElementSibling; | const element = document.currentScript && document.currentScript.previousElementSibling; | ||
if(element){ | if(element){ | ||
Zeile 21: | Zeile 24: | ||
const lastModifiedEl = $(element).find('[data-zum-hook="last-modified"]'); | const lastModifiedEl = $(element).find('[data-zum-hook="last-modified"]'); | ||
const api = new mw.Api(); | const api = new mw.Api(); | ||
. const query = kategorieArtikel ? { | |||
action:'query', | action:'query', | ||
indexpageids: 1, | indexpageids: 1, | ||
prop:['revisions', 'contributors', 'info'], | prop:['revisions', 'contributors', 'info'], | ||
generator: categorymembers, | |||
gcmtitle: `Kategorie:${category}`, | |||
gcmnamespace:0, | |||
gcmtype: 'page', | |||
gcmlimit: 500 | |||
rvlimit:1000 | rvlimit:1000 | ||
}); | } : { | ||
action:'query', | |||
indexpageids: 1, | |||
prop:['revisions', 'contributors', 'info'], | |||
titles: paramArtikel || getCurrentTitle(); | |||
rvlimit:1000 | |||
}; | |||
const response = api.get(query); | |||
response.then((data) => { | response.then((data) => { | ||
//TODO continuation handling | |||
if (data.query.pageids[0] === "-1") { | |||
return; | return; | ||
} | } | ||
const pageData = data | |||
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; | return acc; | ||
}, userChanges); | }, {lastmodified: -1, userChanges:{}}); | ||
const usernames = Object.keys(userChanges).sort((a,b) => { | const usernames = Object.keys(userCounts.userChanges).sort((a,b) => { | ||
let diff = userChanges[b].count - userChanges[a].count; | let diff = userCounts.userChanges[b].count - userCounts.userChanges[a].count; | ||
if(diff !== 0){ | if(diff !== 0){ | ||
return diff; | return diff; | ||
} | } | ||
return userChanges[b].last - userChanges[a].last; | return userCounts.userChanges[b].last - userCounts.userChanges[a].last; | ||
}) | }) | ||
$(lastModifiedEl).append(new Date(userCounts.lastmodified).toLocaleDateString()); | |||
const userdatas = usernames.map((user) => api | const userdatas = usernames.map((user) => api | ||
.parse(`{{#avatar:${user}|l}}`) | .parse(`{{#avatar:${user}|l}}`) | ||
Zeile 74: | Zeile 99: | ||
.parent() | .parent() | ||
.wrap('<div class="uk-panel uk-panel-border uk-text-small" style="max-width:12ch">') | .wrap('<div class="uk-panel uk-panel-border uk-text-small" style="max-width:12ch">') | ||
.parent() | .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)); | |||
}); | }); | ||
}) | }) |