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

From The Coppermind
Jump to navigation Jump to search
m (smaller links)
m (Fbstj moved page User:Fbstj/common.js to User:Fbstj/gadget/history-test.js without leaving a redirect)
 
(152 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 */
 
$(function () {
 
   
  +
const pageid = mw.config.get('wgArticleId')
function edit_button(i, v) {
 
  +
const query = {
if (!v) return v;
 
  +
// request the history of this page
v = v.replace(/\.(\d+)/, "%$1");
 
  +
pageids: [pageid],
var a = "<a href='/edit/Template:" + v +"'>edit</a>";
 
  +
prop: 'revisions',
$('.title', this).append("<span class="mw-editsection" style="float: right;" >[" + a + "]</span>");
 
  +
// 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) {
$('.navbar').attr('id', edit_button);
 
   
  +
const page = resp.query.pages[pageid]
$('.infobox').attr('id', edit_button);
 
  +
page.revisions.forEach(console.log)
   
});
+
})
  +
  +
})

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)

})

})