Content deleted Content added
cleanup |
update |
||
Line 2:
<syntaxhighlight lang="js">
var api = new mw.Api();
var titlePrefix = "Module:Sandbox/Ahecht/flag/"
var query = {▼
action: "query",▼
generator: "allpages",▼
gapprefix: "Country data ",▼
gapnamespace: "10",▼
gapfilterredir: "nonredirects",▼
gaplimit: "max",▼
prop: "redirects",▼
rdlimit: "max"▼
};▼
pageIDs = {};
redirects = {};
function apiGet(
▲ var query = {
▲ };
if (cont) {
query = Object.assign(query, cont);
Line 40 ⟶ 41:
}
if (data && data['continue']) {
return apiGet(
} else {
apiDone();
Line 50 ⟶ 51:
function apiDone() {
output = 'return {\n';
for (title in redirects) {
Line 57 ⟶ 58:
}
output += '}';
apiPost("redirects", output);
}
function apiPost(alias, text) {
apiGet(query);▼
var params = {
action: "edit",
title: titlePrefix + alias.replace(/\s/, "_"),
summary: "Extracting data from [[Template:Country data " + alias + "]]",
text: text
};
api.postWithEditToken( params ).done( function ( data ) {
if ( data && data.edit && data.edit.result && data.edit.result === "Success" ) {
showStatus(
"Edit saved successfully to https:" +
(mw.config.values.wgServer + mw.config.values.wgArticlePath).replace("$1", data.edit.title.replace(/\s/, "_"))
);
} else {
showStatus( "Couldn't save due to error: " + JSON.stringify( data ) );
}
} ).fail( function ( error ) {
showStatus( "Couldn't save due to error: " + JSON.stringify( error ) );
} );
}
function showStatus(status) {
console.log(status);
}
</syntaxhighlight>
|