-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathget_deleted_revs.js
74 lines (60 loc) · 1.81 KB
/
get_deleted_revs.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
/*
get_deleted_revs.js
MediaWiki API Demos
Demo of `Deleted revisions:Get a list of deleted revision for Talk:Main Page` module
MIT License
*/
var request = require('request').defaults({jar: true}),
url = "https://en.wikipedia.org/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 a list of deleted revisions
var url = "https://en.wikipedia.org/w/api.php";
var params_2 = {
action: "query",
format: "json",
titles: "Talk:MainPage",
prop: "deletedrevisions",
drprop: "user|comment|content"
};
url = url + "?origin=*";
Object.keys(params_2).forEach(function(key){url += "&" + key + "=" + params_2[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
console.log(response);
})
.catch(function(error){console.log(error);});