Deletion vote reset is now logged and able to be rolled back
authorDan
Wed, 15 Apr 2009 17:14:20 -0400
changeset 913 3ec535acd11e
parent 912 95d0d8596c87
child 914 f808e55fb92a
Deletion vote reset is now logged and able to be rolled back
includes/log.php
includes/pageprocess.php
includes/pageutils.php
language/english/core.json
language/english/tools.json
plugins/SpecialLog.php
--- a/includes/log.php	Wed Apr 15 16:20:33 2009 -0400
+++ b/includes/log.php	Wed Apr 15 17:14:20 2009 -0400
@@ -405,6 +405,9 @@
         case 'create':
           $html .= $lang->get('log_action_create');
           break;
+        case 'votereset':
+          $html .= $lang->get('log_action_votereset', array('num_votes' => $row['edit_summary'], 'plural' => ( intval($row['edit_summary']) == 1 ? '' : $lang->get('meta_plural'))));
+          break;
         case 'prot':
         case 'unprot':
         case 'semiprot':
--- a/includes/pageprocess.php	Wed Apr 15 16:20:33 2009 -0400
+++ b/includes/pageprocess.php	Wed Apr 15 17:14:20 2009 -0400
@@ -754,6 +754,44 @@
           );
         
         break;
+      case 'votereset':
+        if ( !$this->perms->get_permissions('history_rollback_extra') )
+          return 'Denied!';
+        
+        // pull existing vote data
+        $q = $db->sql_query('SELECT delvotes, delvote_ips FROM ' . table_prefix . "pages WHERE urlname = '$this->page_id' AND namespace = '$this->namespace';");
+        if ( !$q )
+          $db->_die();
+        
+        if ( $db->numrows() < 1 )
+          return array(
+              'success' => false,
+              'error' => 'page_not_exist',
+              'action' => $log_entry['action']
+            );
+          
+        list($curr_delvotes, $curr_delvote_ips) = $db->fetchrow_num();
+        $db->free_result();
+        
+        // merge with existing votes
+        $old_delvote_ips = unserialize($log_entry['page_text']);
+        $new_delvote_ips = unserialize($curr_delvote_ips);
+        $new_delvote_ips['u'] = array_unique(array_merge($new_delvote_ips['u'], $old_delvote_ips['u']));
+        $new_delvote_ips['ip'] = array_unique(array_merge($new_delvote_ips['ip'], $old_delvote_ips['ip']));
+        $new_delvotes = count($new_delvote_ips['ip']);
+        $new_delvote_ips = $db->escape(serialize($new_delvote_ips));
+        
+        // update pages table
+        $q = $db->sql_query('UPDATE ' . table_prefix . "pages SET delvotes = $new_delvotes, delvote_ips = '$new_delvote_ips' WHERE urlname = '$this->page_id' AND namespace = '$this->namespace';");
+        
+        $cache->purge('page_meta');
+        
+        return array(
+            'success' => true,
+            'dateline' => $dateline,
+            'action' => $log_entry['action']
+          );
+        break;
       default:
         
         return array(
--- a/includes/pageutils.php	Wed Apr 15 16:20:33 2009 -0400
+++ b/includes/pageutils.php	Wed Apr 15 17:14:20 2009 -0400
@@ -515,6 +515,7 @@
         elseif($r['action']=='create')   echo $lang->get('history_log_create') . '</td><td class="' . $cls . '">';
         elseif($r['action']=='delete')   echo $lang->get('history_log_delete') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . $r['edit_summary'];
         elseif($r['action']=='reupload') echo $lang->get('history_log_uploadnew') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . ( $r['edit_summary'] === '__ROLLBACK__' ? $lang->get('history_extra_upload_reversion') : htmlspecialchars($r['edit_summary']) );
+        elseif($r['action']=='votereset')echo $lang->get('history_log_votereset') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_numvotes') . ' ' . $r['edit_summary'];
         echo '</td>';
         
         // Actions!
@@ -1312,11 +1313,36 @@
     global $lang;
     global $cache;
     
-    if(!$session->get_permissions('vote_reset'))
+    if ( !$session->get_permissions('vote_reset') )
     {
       return $lang->get('etc_access_denied');
     }
-    $q = 'UPDATE ' . table_prefix.'pages SET delvotes=0,delvote_ips=\'' . $db->escape(serialize(array('ip'=>array(),'u'=>array()))) . '\' WHERE urlname=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\'';
+    
+    $page_id = $db->escape($page_id);
+    $namespace = $db->escape($namespace);
+    
+    // pull existing info
+    $q = $db->sql_query('SELECT delvotes, delvote_ips FROM ' . table_prefix . "pages WHERE urlname = '$page_id' AND namespace = '$namespace'");
+    if ( !$q )
+      $db->_die();
+    if ( $db->numrows() < 1 )
+      return $lang->get('page_err_page_not_exist');
+    
+    list($delvotes, $delvote_ips) = $db->fetchrow_num();
+    $db->free_result();
+    $delvote_ips = $db->escape($delvote_ips);
+    $username = $db->escape($session->username);
+    
+    // log action
+    $time = time();
+    $q = $db->sql_query('INSERT INTO ' . table_prefix . "logs (time_id, log_type, action, edit_summary, page_text, author, page_id, namespace) VALUES\n"
+                      . "  ( $time, 'page', 'votereset', '$delvotes', '$delvote_ips', '$username', '$page_id', '$namespace' )");
+    if ( !$q )
+      $db->_die();
+    
+    // reset votes
+    $empty_vote_record = $db->escape(serialize(array('ip'=>array(),'u'=>array())));
+    $q = 'UPDATE ' . table_prefix.'pages SET delvotes=0,delvote_ips=\'' . $empty_vote_record . '\' WHERE urlname=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\'';
     $e = $db->sql_query($q);
     if ( !$e )
     {
@@ -1541,6 +1567,8 @@
   public static function setwikimode($page_id, $namespace, $level)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
+    global $cache;
+    
     if(!$session->get_permissions('set_wiki_mode')) return('Insufficient access rights');
     if ( !isset($level) || ( isset($level) && !preg_match('#^([0-2]){1}$#', (string)$level) ) )
     {
@@ -1551,6 +1579,8 @@
     {
       return('Error during update query: '.$db->get_error()."\n\nSQL Backtrace:\n".$db->sql_backtrace());
     }
+    
+    $cache->purge('page_meta');
     return('GOOD');
   }
   
--- a/language/english/core.json	Wed Apr 15 16:20:33 2009 -0400
+++ b/language/english/core.json	Wed Apr 15 17:14:20 2009 -0400
@@ -128,6 +128,7 @@
       err_rb_action_not_supported: 'Rolling back actions of type "%action%" isn\'t supported.',
       err_rb_file_rename_failed: 'Could not rename the file to its new name (1.1.x format)',
       err_protection_already_there: 'The protection level you selected is already in effect for this page.',
+      err_page_not_exist: 'The page you tried to perform this action on does not exist.',
       
       msg_this_is_a_redirector: '<b>This page is a <i>redirector</i>.</b><br />
                     This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />
@@ -139,12 +140,14 @@
       msg_rb_success_rename: 'The page has been restored the name it had on %dateline%.',
       // next 3 are mostly identical
       msg_rb_success_prot: 'The page\'s protection has been undone and replaced with the previous level it had as of %dateline%.',
-      msg_rb_success_unprot: 'The page\'s protection has been undone and replaced with the previous level it had as of %dateline%.',
+      msg_rb_success_unprot: 'The page\'s unprotection has been undone and replaced with the previous level it had as of %dateline%.',
       msg_rb_success_semiprot: 'The page\'s semi-protection has been undone and replaced with the previous level it had as of %dateline%.',
       
       msg_rb_success_delete: 'The deletion of this page, which occurred on %dateline%, has been undone. This page has been restored, but comments and categorization data may have been lost.',
       msg_rb_success_reupload: 'The file has been restored to the version uploaded on %dateline%.',
       
+      msg_rb_success_votereset: 'The votes for deletion of this page as of %dateline% have been restored and merged with any existing votes.',
+      
       msg_passrequired_title: 'Password required',
       msg_passrequired: 'Access to this page requires a password. Please enter the password for this page below:',
       msg_pass_wrong: 'The password you entered for this page was incorrect. Please enter the password for this page below:',
@@ -428,6 +431,7 @@
       extra_oldtitle: 'Old title:',
       extra_protection_reversion: '(Reversion of previous protection)',
       extra_upload_reversion: '(Restoration of previous upload)',
+      extra_numvotes: 'Number of votes:',
       tip_rdns: 'Click cell background for reverse DNS info',
       action_view: 'View',
       action_contrib: 'User contribs',
@@ -440,6 +444,7 @@
       log_create: 'Created page',
       log_delete: 'Deleted page',
       log_uploadnew: 'Uploaded new file version',
+      log_votereset: 'Reset deletion votes',
       lbl_comparingrevisions: 'Comparing revisions:',
       summary_none_given: 'No edit summary provided.',
       err_wrong_password: 'Please enter the password for this page before viewing its history.'
--- a/language/english/tools.json	Wed Apr 15 16:20:33 2009 -0400
+++ b/language/english/tools.json	Wed Apr 15 17:14:20 2009 -0400
@@ -158,6 +158,7 @@
       action_protect_semi: 'Semiprotected page (%reason%)',
       action_protect_full: 'Protected page (%reason%)',
       action_reupload: 'Uploaded new revision: %reason%',
+      action_votereset: 'Reset deletion votes (had %num_votes% vote%plural%)',
       action_protect: 'Protect and unprotect',
       action_edit: 'Edit',
       
@@ -179,6 +180,8 @@
       formaction_rename: 'Rename',
       formaction_create: 'Create page',
       formaction_delete: 'Delete page',
+      formaction_reupload: 'File reupload',
+      formaction_votereset: 'Reset of deletion votes',
       
       heading_addfilter: 'Add a filter',
       heading_logdisplay: 'Log filter results',
--- a/plugins/SpecialLog.php	Wed Apr 15 16:20:33 2009 -0400
+++ b/plugins/SpecialLog.php	Wed Apr 15 17:14:20 2009 -0400
@@ -239,6 +239,8 @@
               <option value="delete"><?php echo $lang->get('log_formaction_delete'); ?></option>
               <option value="protect"><?php echo $lang->get('log_action_protect'); ?></option>
               <option value="edit"><?php echo $lang->get('log_action_edit'); ?></option>
+              <option value="edit"><?php echo $lang->get('log_formaction_reupload'); ?></option>
+              <option value="edit"><?php echo $lang->get('log_formaction_votereset'); ?></option>
             </select>
           </div>
         </td>
@@ -318,7 +320,8 @@
         $crumb = $lang->get('log_breadcrumb_page', array('page' => '<a href="' . makeUrl($value, false, true) . '">' . htmlspecialchars(get_page_title($value)) . '</a>'));
         break;
       case 'action':
-        $crumb = $lang->get('log_breadcrumb_action', array('action' => htmlspecialchars($lang->get("log_action_{$value}"))));
+        $action = ( $lang->get("log_formaction_{$value}") === "log_formaction_{$value}" ) ? $lang->get("log_action_{$value}") : $lang->get("log_formaction_{$value}");
+        $crumb = $lang->get('log_breadcrumb_action', array('action' => htmlspecialchars($action)));
         break;
       case 'within':
         $value = intval($value);