Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Ahecht/flag/redirects/doc
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Generated by the following code: <syntaxhighlight lang="js"> var api = new mw.Api(); var titlePrefix = "Module:Sandbox/Ahecht/flag/" pageIDs = {}; redirects = {}; function apiGet(cont) { var query = { action: "query", generator: "allpages", gapprefix: "Country data ", gapnamespace: "10", gapfilterredir: "nonredirects", gaplimit: "max", prop: "redirects", rdlimit: "max" }; if (cont) { query = Object.assign(query, cont); } api.get( query ) .done (function (data) { if (data && data.query) { if (data.query.pages) { Object.entries(data.query.pages).forEach(function(item) { if (!/\//.test(item[1].title) ) { itemTitle = item[1].title.replace(/Template:(?:Flag|Country) data /,''); pageIDs[itemTitle] = item[1].pageid; if(item[1].redirects) { for (var i = 0; i < item[1].redirects.length; i++) { fromTitle = item[1].redirects[i].title.replace(/Template:(?:Flag|Country) data /,''); if (fromTitle != itemTitle) { redirects[fromTitle] = itemTitle; } } } } } ); } } if (data && data['continue']) { showStatus("Getting...") return apiGet(data['continue']); } else { apiDone(); return; } } ); } function apiDone() { showStatus("Done!"); showStatus(Object.keys(pageIDs).length + " pages, " + Object.keys(redirects).length + " redirects."); output = 'return {\n'; for (title in redirects) { output += '\t["' + title + '"] = "' + redirects[title] + '",\n'; } output += '}'; showStatus(output); apiPost("redirects", output); } function apiPost(alias, text) { var params = { 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); } apiGet(); </syntaxhighlight>
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)