Content deleted Content added
create |
update |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1:
Generated by the following code:
<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 44 ⟶ 41:
}
if (data && data['continue']) {
return apiGet(
} else {
apiDone();
Line 54 ⟶ 51:
function apiDone() {
output = 'return {\n';
for (title in redirects) {
Line 61 ⟶ 58:
}
output += '}';
apiPost("redirects", output);
}
function apiPost(alias, text) {
apiGet(query);▼
var params = {
</syntaxhighlight>▼
action: "edit",
title: titlePrefix + alias.replace(/\s/, "_"),
summary: "Extracting data from templates with prefix [[Template:Country data]]",
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>
|