Advertisement
Guest User

Untitled

a guest
Jul 18th, 2013
1,271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function afcHelper_ffu_performActions() {
  2.     // Load all of the data.
  3. for (var i = 0; i < afcHelper_Submissions.length; i++) {
  4.     var action = document.getElementById("afcHelper_ffu_action_" + i).value;
  5.     afcHelper_Submissions[i].action = action;
  6.     console.log("Selected action:"+action);
  7.     if (action == 'none')
  8.         continue;
  9.     if (action == 'accept') {
  10.             afcHelper_Submissions[i].to = document.getElementById("afcHelper_ffu_to_" + i).value;
  11.             afcHelper_Submissions[i].notify = document.getElementById("afcHelper_ffu_notify_" + i).value;
  12.             afcHelper_Submissions[i].talkpage = document.getElementById("afcHelper_ffu_filetalkpage_" + i).value;
  13.             afcHelper_Submissions[i].append = document.getElementById("afcHelper_ffu_append_" + i).value;
  14.             afcHelper_Submissions[i].recent = document.getElementById("afcHelper_ffu_recent_" + i).value;
  15.             afcHelper_Submissions[i].recenttext = document.getElementById("afcHelper_ffu_recenttext_" + i).value;
  16.             //console.log(afcHelper_Submissions[i]);
  17.             //console.log("Original FFU \"to\" value: "+document.getElementById("afcHelper_ffu_to_" + i).value);
  18.             /* We don't need this block; let's just let users enter wikicode...
  19.             if (afcHelper_Submissions[i].append == 'custom') {
  20.                 afcHelper_Submissions[i].append = prompt("Please enter the template to append for " + afcHelper_Submissions[i].title + ". Do not include the curly brackets.");
  21.             }
  22.             if (afcHelper_Submissions[i].append == 'none' || afcHelper_Submissions[i].append == null)
  23.                 afcHelper_Submissions[i].append = '';
  24.             else
  25.                 afcHelper_Submissions[i].append = '\{\{' + afcHelper_Submissions[i].append + '\}\}'; */
  26.     } else if (action == 'decline') {
  27.         afcHelper_Submissions[i].reason = document.getElementById('afcHelper_ffu_decline_' + i).value;
  28.     }
  29.     afcHelper_Submissions[i].comment = document.getElementById('afcHelper_ffu_comment_' + i).value;
  30. }
  31.  
  32. //console.log(afcHelper_Submissions)
  33. // Data loaded. Show progress screen and get edit token and WP:FFU page text.
  34. displayMessage('<ul id="afcHelper_status"></ul><ul id="afcHelper_finish"></ul>');
  35. 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>';
  36. var token = mw.user.tokens.get('editToken');
  37. pagetext = afcHelper_getPageText(afcHelper_ffuPageName, true);
  38. var totalaccept = 0;
  39. var totaldecline = 0;
  40. var totalcomment = 0;
  41. // traverse the submissions and locate the relevant sections.
  42.  
  43. console.log(afcHelper_ffuSubmissions.length);
  44. for (var i = 0; i < afcHelper_ffuSubmissions.length; i++) {
  45.     var sub = afcHelper_ffuSubmissions[i];
  46.     //console.log("THIS IS BROKEN DOWN BY LINK",afcHelper_Submissions[i]);
  47.     if (pagetext.indexOf(afcHelper_ffuSections[sub.section]) == -1) {
  48.         // Someone has modified the section in the mean time. Skip.
  49.         document.getElementById('afcHelper_status').innerHTML += '<li>Skipping ' + sub.title + ': Cannot find section. Perhaps it was modified in the mean time?</li>';
  50.         continue;
  51.     }
  52.     var text = afcHelper_ffuSections[sub.section];
  53.     var startindex = pagetext.indexOf(afcHelper_ffuSections[sub.section]);
  54.     var endindex = startindex + text.length;
  55.  
  56.     console.log(sub);
  57.     if (typeof(sub.from) != 'undefined' && sub.from.length > 0) {
  58.         for (var i = 0; i < sub.from.length; i++) {
  59.             mainid = sub.from[i]['id'];
  60.             var sub = afcHelper_Submissions[mainid];
  61.             if (sub.action == 'accept'){
  62.                 console.log('yay!!! we accepted it!');
  63.                 //create local file description talkpage?
  64.                 if((sub.talkpage==true)&&(sub.to!='')){
  65.                     console.log("Saving local file description page");
  66.                     //afcHelper_editPage('File talk\:'+afcHelper_Submissions[i].to, '\{\{subst:WPAFCF\}\}\n'+afcHelper_Submissions[i].append, token, 'Placing [[WP:AFC|WPAFC]] project banner', true);
  67.                         }
  68.                
  69.                 //First notify the user so we don't have to process yet another signature
  70.                 //todo list: if more files in one request were handled
  71.                 if(sub.notify==true){
  72.                     //assuming the first User/IP is the requester
  73.                     var requestinguser=/\[\[(User[_ ]talk:|User:|Special:Contributions\/)([^\||\]\]]*)([^\]]*?)\]\]/i.exec(text)[2];
  74.                     var userpagetext = afcHelper_getPageText('User talk:'+requestinguser, true);
  75.                     if (sub.to === '')
  76.                         userpagetext += '\n== Your request at \[\[WP:FFU|Files for upload\]\] ==\n\{\{subst:ffu talk\}\} \~\~\~\~\n';
  77.                     else
  78.                         userpagetext += '\n== Your request at \[\[WP:FFU|Files for upload\]\] ==\n\{\{subst:ffu talk|file=' + afcHelper_Submissions[i].to + '\}\} \~\~\~\~\n';
  79.                     console.log('attempting to edit user talk page??')
  80.                     //afcHelper_editPage('User talk:'+requestinguser, userpagetext, token, 'Notifying about the [[WP:FFU|FFU]] request', true);
  81.                         }
  82.  
  83.                 //update text of the FFU page
  84.                 var header = text.match(/==[^=]*==/)[0];
  85.                 text = header + "\n\{\{subst:ffu a\}\}\n" + text.substring(header.length);
  86.                 if (sub.to === '')
  87.                     text += '\n*\{\{subst:ffu|a\}\} \~\~\~\~\n';
  88.                 else
  89.                     text += '\n*\{\{subst:ffu|file=' + sub.to + '\}\} \~\~\~\~\n';
  90.                 text += '\{\{subst:ffu b\}\}\n';
  91.                         totalaccept++;                 
  92.  
  93.                 // update [[Wikipedia:Files for upload/recent]]
  94.                 if(sub.recent==true){
  95.                     recenttext = afcHelper_getPageText('Wikipedia:Files_for_upload/recent',true)
  96.                     var newentry = "\|File:" + sub.to + "|" + ( typeof sub.filedescription  !== "undefined" ? sub.filedescription : "" ) + "\n";
  97.                     var lastentry = recenttext.toLowerCase().lastIndexOf("| file:");
  98.                     var firstentry = recenttext.toLowerCase().indexOf("| file:");
  99.                     recenttext = recenttext.substring(0, lastentry);
  100.                     recenttext = recenttext.substring(0, firstentry) + newentry + recenttext.substring(firstentry) + '\n}}';
  101.                     //afcHelper_editPage("Wikipedia:Files for upload/recent", recenttext, token, 'Updating recently uploaded FFUs');
  102.                 }
  103.             } else if (sub.action == 'decline') {
  104.                 var header = text.match(/==[^=]*==/)[0];
  105.                 var reason = sub.reason;
  106.                 console.log('Reason: '+reason)
  107.                 if (reason == '')
  108.                     reason = sub.comment;
  109.                 else if (sub.comment != '')
  110.                     reason = reason + ': ' + sub.comment;
  111.                 if (reason == '') {
  112.                     document.getElementById('afcHelper_status').innerHTML += '<li>Skipping ' + sub.title + ': No decline reason specified.</li>';
  113.                     continue;
  114.                 }
  115.                 text = header + "\n\{\{subst:ffu d\}\}\n" + text.substring(header.length);
  116.                 if (sub.comment == '')
  117.                     text += '\n*\{\{subst:ffu|' + sub.reason + '\}\} \~\~\~\~\n';
  118.                 else
  119.                     text += '\n*\{\{subst:ffu|' + sub.reason + '\}\} ' + sub.comment + ' \~\~\~\~\n';
  120.                 text += '\{\{subst:ffu b\}\}\n';
  121.                 console.log('Text: '+text)
  122.                 totaldecline++;
  123.  
  124.             } else if (sub.action == 'comment') {
  125.                 if (sub.comment != '')
  126.                     text += '\n\{\{subst:ffu|c\}\} ' + sub.comment + '\~\~\~\~\n';
  127.                         totalcomment++;
  128.                     }
  129.                 pagetext = pagetext.substring(0, startindex) + text + pagetext.substring(endindex);
  130.         }
  131.     }  
  132. }
  133.  
  134.  
  135.     var summary = "Updating submission status:";
  136. if (totalaccept > 0)
  137.     summary += " accepting " + totalaccept + " request" + (totalaccept > 1 ? 's' : '');
  138. if (totaldecline > 0) {
  139.     if (totalaccept > 0)
  140.         summary += ',';
  141.     summary += " declining " + totaldecline + " request" + (totaldecline > 1 ? 's' : '');
  142. }
  143. if (totalcomment > 0) {
  144.     if (totalaccept > 0 || totaldecline > 0)
  145.         summary += ',';
  146.     summary += " commenting on " + totalcomment + " request" + (totalcomment > 1 ? 's' : '');
  147.         }
  148.  
  149.         //afcHelper_editPage(afcHelper_ffuPageName, pagetext, token, summary, false);
  150.         document.getElementById('afcHelper_finished_main').style.display = '';
  151.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement