Widget:Autorenbox: Unterschied zwischen den Versionen
Aus ZUM-Unterrichten
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
||
(44 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
<includeonly> | <includeonly> | ||
<div class="uk-panel uk-panel-box uk-panel-box-primary zum-hintergrund-links zum-farbe-xx-heller"> | <div class="uk-panel uk-panel-box uk-panel-box-primary zum-hintergrund-links zum-farbe-xx-heller uk-hidden"> | ||
<strong>Autoren</strong> | <strong>Autoren</strong> | ||
<small class="uk-align-right" data-zum-hook="last-modified">aktualisiert am: </small> | <small class="uk-align-right" data-zum-hook="last-modified">aktualisiert am: </small> | ||
Zeile 8: | Zeile 8: | ||
</div> | </div> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
(function(){ | |||
const paramArtikel = "<!--{$artikel|escape:'javascript'}-->"||null; | |||
const paramKategorie = "<!--{$kategorie|escape:'javascript'}-->"||null; | |||
const element = document.currentScript && document.currentScript.previousElementSibling; | const element = document.currentScript && document.currentScript.previousElementSibling; | ||
if(element){ | if(element){ | ||
window.RLQ.push(function(){ | window.RLQ.push(function(){ | ||
mw.loader.enqueue(['mediawiki.api'], function(){ | mw.loader.enqueue(['mediawiki.api'], function(){ | ||
const userlistEl = $(element). | const getCurrentTitle = () => mw.Title.makeTitle( | ||
const lastModifiedEl = $(element). | 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 api = new mw.Api(); | ||
const | const query = paramKategorie ? { | ||
action:'query', | |||
prop:['contributors', 'info'], | |||
generator: 'categorymembers', | |||
gcmtitle: `Kategorie:${paramKategorie}`, | |||
gcmnamespace:0, | |||
gcmtype: 'page', | |||
gcmlimit: 'max' | |||
} : { | |||
action:'query', | action:'query', | ||
prop:['revisions', 'contributors', 'info'], | prop:['revisions', 'contributors', 'info'], | ||
titles: paramArtikel || getCurrentTitle(), | |||
rvlimit: | rvprop:['userid', 'user', 'flags', 'timestamp'], | ||
} | rvlimit:150 | ||
}; | |||
response. | const response = jQuery.Deferred(); | ||
. | function continueQueryOrResolve(response, query, pages, lastContinue){ | ||
api.get({...query, ...lastContinue}) | |||
.then((response) => { | |||
const newResult = Object.values(response.query.pages).reduce((pages, page) => { | |||
pages[page.pageid] = {...pages[page.pageid], ...page}; | |||
return pages; | |||
}, pages); | |||
if (response.continue !== undefined) { | |||
continueOrResolve(response, query, newResult, response.continue); | |||
} else if (response.batchcomplete !== undefined) { | |||
response.resolve(newResult); | |||
if( | |||
} | } | ||
}); | }); | ||
}) | } | ||
.then(( | continueQueryOrResolve(response, query, {}, null); | ||
const | response.then((pages) => { | ||
.map((user) => api.parse(`{{ | const userCounts = pages.reduce((acc, pageData) => { | ||
acc.touched = Math.max(acc.touched||-1, Date.parse(pageData.touched)); | |||
$.when(... | acc.userChanges = (pageData.contributors||[]) | ||
.then((... | .reduce((userChanges, c)=> { | ||
.then(( | userChanges[c.userid] = userChanges[c.userid] || {count:0, last:-1, userid: c.userid, username: c.name}; | ||
userChanges[c.userid].count += 1; | |||
return userChanges; | |||
}, acc.userChanges||{}); | |||
acc.userChanges = (pageData.revisions||[]) | |||
.reduce((userChanges, r) => { | |||
userChanges[r.userid] = userChanges[r.userid] || {count:0, last:-1, userid: r.userid, username: r.user}; | |||
userChanges[r.userid].count += r.minor !== undefined ? 0.1 : 1; | |||
userChanges[r.userid].last = Math.max(userChanges[r.userid].last, r.revid); | |||
return userChanges; | |||
}, acc.userChanges||{}); | |||
return acc; | |||
}, {}); | |||
const usernames = Object.values(userCounts.userChanges).sort((a,b) => { | |||
let diff = b.count - a.count; | |||
if(diff !== 0){ | |||
return diff; | |||
} | |||
return b.last - a.last; | |||
}).map((user) => user.username); | |||
$(lastModifiedEl).append(new Date(userCounts.touched).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> | </script> | ||
</includeonly> | </includeonly> |