Difference between revisions of "User:Fbstj/gadget/history-test.js"

From The Coppermind
Jump to navigation Jump to search
m (oops)
m (Fbstj moved page User:Fbstj/common.js to User:Fbstj/gadget/history-test.js without leaving a redirect)
 
(155 intermediate revisions by the same user not shown)
Line 1: Line 1:
  +
mw.hook('wikipage.content').add(function revs_gadget() {
/* Add edit buttons to templates */
 
  +
$('.navbar').attr('id', function(i, v) { $('.title', this).append("<span style='float: right; font-size: small;' >[<a href='/edit/Template:"+v+"'>edit</a>]</span>"); })
 
  +
const pageid = mw.config.get('wgArticleId')
  +
const query = {
  +
// request the history of this page
  +
pageids: [pageid],
  +
prop: 'revisions',
  +
// request the oldest edits first
  +
rvdir: 'newer',
  +
// request as many as you can at once
  +
rvlimit: 'max',
  +
// properties to fetch:
  +
rvprop: [ 'ids', 'user', 'timestamp', 'size', 'tags', ],
  +
}
  +
const api = new mw.Api({ parameters: query, })
  +
  +
api.get().then(function old_hist(resp) {
  +
  +
const page = resp.query.pages[pageid]
  +
page.revisions.forEach(console.log)
  +
  +
})
   
$('.infobox').attr('id', function(i, v) {
 
if (!v) return v;
 
v = v.replace('.26', '&').replace('.27', "'");
 
var a = "<a href='/edit/Template:" + v +"'>edit</a>";
 
$('.title', this).append("<span style='float: right; font-size: small;' >[" + a + "]</span>");
 
 
})
 
})

Latest revision as of 19:54, 20 August 2019

mw.hook('wikipage.content').add(function revs_gadget() {

const pageid = mw.config.get('wgArticleId')
const query = {
  // request the history of this page
  pageids: [pageid],
  prop: 'revisions',
   // request the oldest edits first
   rvdir: 'newer',
   // request as many as you can at once
   rvlimit: 'max',
   // properties to fetch:
   rvprop: [ 'ids', 'user', 'timestamp', 'size', 'tags', ],
}
const api = new mw.Api({ parameters: query, })

api.get().then(function old_hist(resp) {

const page = resp.query.pages[pageid]
page.revisions.forEach(console.log)

})

})