Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const results = {
- pages: []
- };
- const promises = [];
- const defaultParams = {
- action: "query",
- format: "json",
- };
- // Object.keys(mw.config.values.wgFormattedNamespaces).forEach((key) => {
- const namespaces = [0,1,2,3,4,5,6,7,8,9];
- namespaces.forEach((key) => {
- const queryParams = {
- generator: "allpages",
- gaplimit: 5000,
- gapfilterredir: "nonredirects",
- prop: "info|pageprops",
- gapnamespace: key,
- ...defaultParams,
- };
- promises.push(getInfo('pages', queryParams));
- });
- Promise.all(promises).then((values) => {
- console.log("Done, the file will be downloaded");
- download("results.txt", JSON.stringify(results, null, 2));
- });
- function getInfo(key, queryParams) {
- return new Promise((resolve) => {
- const api = new mw.Api();
- api.post(queryParams).done((data) => {
- if (data.continue) {
- const [next] = Object.entries(data.continue);
- const [continueKey, continueValue] = next;
- queryParams[continueKey] = continueValue;
- resolve(getInfo(key, queryParams));
- } else {
- resolve();
- }
- console.log("fetching data ...");
- results[key].push(data.query);
- });
- });
- }
- function download(filename, text) {
- var element = document.createElement("a");
- element.setAttribute(
- "href",
- "data:text/plain;charset=utf-8," + encodeURIComponent(text)
- );
- element.setAttribute("download", filename);
- element.style.display = "none";
- document.body.appendChild(element);
- element.click();
- document.body.removeChild(element);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement