Widget:Autorenbox: Unterschied zwischen den Versionen
Aus ZUM-Unterrichten
| KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung | KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung | ||
| Zeile 21: | Zeile 21: | ||
|      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 response = api.get({ |      const response = api.get({ | ||
|        action:'query', |        action:'query', | ||
| Zeile 29: | Zeile 32: | ||
|      }); |      }); | ||
|      response.then((data) => { |      response.then((data) => { | ||
|        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 = 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; | ||
|        } |        }); | ||
|        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; | ||
|        }) |        }) | ||
|        const userdatas = usernames.map((user) => api |        const userdatas = usernames.map((user) => api | ||
