Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function afcHelper_ffu_performActions() {
- // Load all of the data.
- for (var i = 0; i < afcHelper_Submissions.length; i++) {
- var action = document.getElementById("afcHelper_ffu_action_" + i).value;
- afcHelper_Submissions[i].action = action;
- console.log("Selected action:"+action);
- if (action == 'none')
- continue;
- if (action == 'accept') {
- afcHelper_Submissions[i].to = document.getElementById("afcHelper_ffu_to_" + i).value;
- afcHelper_Submissions[i].notify = document.getElementById("afcHelper_ffu_notify_" + i).value;
- afcHelper_Submissions[i].talkpage = document.getElementById("afcHelper_ffu_filetalkpage_" + i).value;
- afcHelper_Submissions[i].append = document.getElementById("afcHelper_ffu_append_" + i).value;
- afcHelper_Submissions[i].recent = document.getElementById("afcHelper_ffu_recent_" + i).value;
- afcHelper_Submissions[i].recenttext = document.getElementById("afcHelper_ffu_recenttext_" + i).value;
- //console.log(afcHelper_Submissions[i]);
- //console.log("Original FFU \"to\" value: "+document.getElementById("afcHelper_ffu_to_" + i).value);
- /* We don't need this block; let's just let users enter wikicode...
- if (afcHelper_Submissions[i].append == 'custom') {
- afcHelper_Submissions[i].append = prompt("Please enter the template to append for " + afcHelper_Submissions[i].title + ". Do not include the curly brackets.");
- }
- if (afcHelper_Submissions[i].append == 'none' || afcHelper_Submissions[i].append == null)
- afcHelper_Submissions[i].append = '';
- else
- afcHelper_Submissions[i].append = '\{\{' + afcHelper_Submissions[i].append + '\}\}'; */
- } else if (action == 'decline') {
- afcHelper_Submissions[i].reason = document.getElementById('afcHelper_ffu_decline_' + i).value;
- }
- afcHelper_Submissions[i].comment = document.getElementById('afcHelper_ffu_comment_' + i).value;
- }
- //console.log(afcHelper_Submissions)
- // Data loaded. Show progress screen and get edit token and WP:FFU page text.
- displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
- document.getElementById('afcHelper_finish').innerHTML += '<span id="afcHelper_finished_wrapper"><span id="afcHelper_finished_main" style="display:none"><li id="afcHelper_done"><b>Done (<a href="' + wgArticlePath.replace("$1", encodeURI(afcHelper_ffuPageName)) + '?action=purge" title="' + afcHelper_ffuPageName + '">Reload page</a>)</b></li></span></span>';
- var token = mw.user.tokens.get('editToken');
- pagetext = afcHelper_getPageText(afcHelper_ffuPageName, true);
- var totalaccept = 0;
- var totaldecline = 0;
- var totalcomment = 0;
- // traverse the submissions and locate the relevant sections.
- console.log(afcHelper_ffuSubmissions.length);
- for (var i = 0; i < afcHelper_ffuSubmissions.length; i++) {
- var sub = afcHelper_ffuSubmissions[i];
- //console.log("THIS IS BROKEN DOWN BY LINK",afcHelper_Submissions[i]);
- if (pagetext.indexOf(afcHelper_ffuSections[sub.section]) == -1) {
- // Someone has modified the section in the mean time. Skip.
- document.getElementById('afcHelper_status').innerHTML += '<li>Skipping ' + sub.title + ': Cannot find section. Perhaps it was modified in the mean time?</li>';
- continue;
- }
- var text = afcHelper_ffuSections[sub.section];
- var startindex = pagetext.indexOf(afcHelper_ffuSections[sub.section]);
- var endindex = startindex + text.length;
- console.log(sub);
- if (typeof(sub.from) != 'undefined' && sub.from.length > 0) {
- for (var i = 0; i < sub.from.length; i++) {
- mainid = sub.from[i]['id'];
- var sub = afcHelper_Submissions[mainid];
- if (sub.action == 'accept'){
- console.log('yay!!! we accepted it!');
- //create local file description talkpage?
- if((sub.talkpage==true)&&(sub.to!='')){
- console.log("Saving local file description page");
- //afcHelper_editPage('File talk\:'+afcHelper_Submissions[i].to, '\{\{subst:WPAFCF\}\}\n'+afcHelper_Submissions[i].append, token, 'Placing [[WP:AFC|WPAFC]] project banner', true);
- }
- //First notify the user so we don't have to process yet another signature
- //todo list: if more files in one request were handled
- if(sub.notify==true){
- //assuming the first User/IP is the requester
- var requestinguser=/\[\[(User[_ ]talk:|User:|Special:Contributions\/)([^\||\]\]]*)([^\]]*?)\]\]/i.exec(text)[2];
- var userpagetext = afcHelper_getPageText('User talk:'+requestinguser, true);
- if (sub.to === '')
- userpagetext += '\n== Your request at \[\[WP:FFU|Files for upload\]\] ==\n\{\{subst:ffu talk\}\} \~\~\~\~\n';
- else
- userpagetext += '\n== Your request at \[\[WP:FFU|Files for upload\]\] ==\n\{\{subst:ffu talk|file=' + afcHelper_Submissions[i].to + '\}\} \~\~\~\~\n';
- console.log('attempting to edit user talk page??')
- //afcHelper_editPage('User talk:'+requestinguser, userpagetext, token, 'Notifying about the [[WP:FFU|FFU]] request', true);
- }
- //update text of the FFU page
- var header = text.match(/==[^=]*==/)[0];
- text = header + "\n\{\{subst:ffu a\}\}\n" + text.substring(header.length);
- if (sub.to === '')
- text += '\n*\{\{subst:ffu|a\}\} \~\~\~\~\n';
- else
- text += '\n*\{\{subst:ffu|file=' + sub.to + '\}\} \~\~\~\~\n';
- text += '\{\{subst:ffu b\}\}\n';
- totalaccept++;
- // update [[Wikipedia:Files for upload/recent]]
- if(sub.recent==true){
- recenttext = afcHelper_getPageText('Wikipedia:Files_for_upload/recent',true)
- var newentry = "\|File:" + sub.to + "|" + ( typeof sub.filedescription !== "undefined" ? sub.filedescription : "" ) + "\n";
- var lastentry = recenttext.toLowerCase().lastIndexOf("| file:");
- var firstentry = recenttext.toLowerCase().indexOf("| file:");
- recenttext = recenttext.substring(0, lastentry);
- recenttext = recenttext.substring(0, firstentry) + newentry + recenttext.substring(firstentry) + '\n}}';
- //afcHelper_editPage("Wikipedia:Files for upload/recent", recenttext, token, 'Updating recently uploaded FFUs');
- }
- } else if (sub.action == 'decline') {
- var header = text.match(/==[^=]*==/)[0];
- var reason = sub.reason;
- console.log('Reason: '+reason)
- if (reason == '')
- reason = sub.comment;
- else if (sub.comment != '')
- reason = reason + ': ' + sub.comment;
- if (reason == '') {
- document.getElementById('afcHelper_status').innerHTML += '<li>Skipping ' + sub.title + ': No decline reason specified.</li>';
- continue;
- }
- text = header + "\n\{\{subst:ffu d\}\}\n" + text.substring(header.length);
- if (sub.comment == '')
- text += '\n*\{\{subst:ffu|' + sub.reason + '\}\} \~\~\~\~\n';
- else
- text += '\n*\{\{subst:ffu|' + sub.reason + '\}\} ' + sub.comment + ' \~\~\~\~\n';
- text += '\{\{subst:ffu b\}\}\n';
- console.log('Text: '+text)
- totaldecline++;
- } else if (sub.action == 'comment') {
- if (sub.comment != '')
- text += '\n\{\{subst:ffu|c\}\} ' + sub.comment + '\~\~\~\~\n';
- totalcomment++;
- }
- pagetext = pagetext.substring(0, startindex) + text + pagetext.substring(endindex);
- }
- }
- }
- var summary = "Updating submission status:";
- if (totalaccept > 0)
- summary += " accepting " + totalaccept + " request" + (totalaccept > 1 ? 's' : '');
- if (totaldecline > 0) {
- if (totalaccept > 0)
- summary += ',';
- summary += " declining " + totaldecline + " request" + (totaldecline > 1 ? 's' : '');
- }
- if (totalcomment > 0) {
- if (totalaccept > 0 || totaldecline > 0)
- summary += ',';
- summary += " commenting on " + totalcomment + " request" + (totalcomment > 1 ? 's' : '');
- }
- //afcHelper_editPage(afcHelper_ffuPageName, pagetext, token, summary, false);
- document.getElementById('afcHelper_finished_main').style.display = '';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement