User:Timotheus Canens/massrestore.js

///Adapted from User:Animum/massdelete.js function doMassRestore { document.getElementById("wpMassRestoreSubmit").disabled = true; var articles = document.getElementById("wpMassRestorePages").value.split("\n"); if(articles.length == 0) return; var wpMassRestoreReason = document.getElementById("wpMassRestoreReason").value, restored = 0, failed = new Array, error = new Array; for(i=0;i 0) { var req = new XMLHttpRequest; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&prop=info&meta=tokens&type=csrf&titles=" + encodeURIComponent(article), false); req.send(null); var query = eval("(" + req.responseText + ")").query; var token = query.tokens.csrftoken; var response = query.pages; for(var index in response) { var info = response[index]; var postdata = "format=json" + "&action=undelete" + "&title=" + encodeURIComponent(article) + "&reason=" + encodeURIComponent(wpMassRestoreReason) + "&token=" + encodeURIComponent(token); var req = new XMLHttpRequest; req.open("POST", mw.config.get('wgScriptPath') + "/api.php", false); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Content-length", postdata.length); req.send(postdata); if(eval("(" + req.responseText + ")").undelete) { //If restored, update the restored count and the button. restored++; document.getElementById("wpMassRestoreSubmit").value = "(" + restored + ")"; } else { //If not deleted, add the title to the "failed" array and a description of the error to the "error" array. failed.push(article); error.push(eval("(" + req.responseText + ")").error.info); }           }        }        if(!articles[i+1]) { document.getElementById("wpMassRestoreSubmit").value = "Done (" + restored + ")"; if(failed.length > 0) { var linkedList = ""; for(x=0; x" + failed[x] + ": " + error[x] + ""; //Links the titles in the "failed" array }               document.getElementById("wpMassRestoreFailedContainer").innerHTML += ' Failed deletions:' + linkedList + ''; }       }    } } function massrestoreform { var bodyContent; switch (mw.config.get('skin')) { case 'modern': bodyContent = 'mw_contentholder'; break; case 'cologneblue': bodyContent = 'article'; break; case 'monobook': case 'vector': default: bodyContent = 'bodyContent'; break; }   document.getElementsByTagName("h1")[0].textContent = "Tim's mass-restoration tool"; document.title = "Tim's mass-restoration tool - Wikipedia, the free encyclopedia"; document.getElementById(bodyContent).innerHTML = 'From Wikipedia, the free encyclopedia

'       + '' + 'If you abuse this tool, it\'s your fault, not mine.' + ' '       + '

'           + 'Pages to restore(one on each line, please): '               + ' ' + '

'           + '  Reason: ' + '  ' + '  ' + ' '; } if(mw.config.get("wgNamespaceNumber") == -1 && (mw.config.get("wgTitle").toLowerCase == "massrestore") && /sysop/.test(mw.config.get("wgUserGroups"))) $(massrestoreform);