-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-Commons-wikitext.js
37 lines (29 loc) · 1.21 KB
/
delete-Commons-wikitext.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
// PURPOSE: For a given a category, gets the list of pages, edits existing content.
const Wikiapi= require('wikiapi');
const logins = require('./logins.js');
// Login credentials from .login*.js
var USER = logins.commons.user,
PASS = logins.commons.pass,
API = logins.commons.api;
(async () => {
// Connect
const targetWiki = new Wikiapi;
await targetWiki.login(USER, PASS, API);
console.log(`Username ${USER} is connected !`);
// List of targets
const list = await targetWiki.categorymembers('Category:Dragons Bot HSK');
// Loop on targets
for(i=0;i<list.length;i++){
console.log(list[i]);
var currPage = list[i]; // target page's page_data
// Page exist ?
var pageData = await targetWiki.page(currPage.title, {});
if(pageData.wikitext!=='') {
//Edit page, replace string:
await targetWiki.edit_page(currPage.title, function(page_data) {
return `{{Speedy|Request by creator or bot master; speedy on test file. ~~~~}}`; // <------- regex match and replacement
}, {bot: 1, nocreate: 1, minor: 1, summary: 'ShufaBot test: edit'});
console.log('Done.');
}
}
})();