-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathget_deleted_revisions.js
79 lines (69 loc) · 2.02 KB
/
get_deleted_revisions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
get_deleted_revisions.js
MediaWiki API Demos
Demo of `Deletedrevs` module: List the six most recent deleted revisions from User:Catrope
MIT License
*/
var request = require('request').defaults({jar: true}),
url = "http://dev.wiki.local.wmftest.net:8080/w/api.php";
// Step 1: GET Request to fetch login token
function getLoginToken() {
var params_0 = {
action: "query",
meta: "tokens",
type: "login",
format: "json"
};
request.get({ url: url, qs: params_0 }, function (error, res, body) {
if (error) {
return;
}
var data = JSON.parse(body);
loginRequest(data.query.tokens.logintoken);
});
}
// Step 2: POST Request to log in.
// Use of main account for login is not
// supported. Obtain credentials via Special:BotPasswords
// (https://www.mediawiki.org/wiki/Special:BotPasswords) for lgname & lgpassword
function loginRequest(login_token) {
var params_1 = {
action: "login",
lgname: "bot_username",
lgpassword: "bot_password",
lgtoken: login_token,
format: "json"
};
request.post({ url: url, form: params_1 }, function (error, res, body) {
if (error) {
return;
}
deleted_revisions();
});
}
// Step 3: GET request to get the deleted revisions
function deleted_revisions() {
var params_2 = {
action: "query",
list: "deletedrevs",
druser: "Catrope",
drprop: "revid|user|minor|len|token",
drlimit: "6",
format: "json"
};
request.get({ url: url, qs: params_2 }, function(error, res, body) {
if (error) {
return;
}
var data = JSON.parse(body);
var pages = data.query.deletedrevs;
for (var p in pages) {
console.log("Revision for Page " + pages[p].title);
for (var drev in pages[p].revisions) {
console.log(pages[p].revisions[drev]);
}
}
});
}
// Start From Step 1
getLoginToken();