includes/pageutils.php
changeset 32 4d87aad3c4c0
parent 29 e5484a9e0818
child 39 c83ff194977a
equal deleted inserted replaced
31:dc8741857bde 32:4d87aad3c4c0
  1238    
  1238    
  1239   function flushlogs($page_id, $namespace)
  1239   function flushlogs($page_id, $namespace)
  1240   {
  1240   {
  1241     global $db, $session, $paths, $template, $plugins; // Common objects
  1241     global $db, $session, $paths, $template, $plugins; // Common objects
  1242     if(!$session->get_permissions('clear_logs')) die('Administrative privileges are required to flush logs, you loser.');
  1242     if(!$session->get_permissions('clear_logs')) die('Administrative privileges are required to flush logs, you loser.');
  1243     $e = $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
  1243     $e = $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';');
  1244     if(!$e) $db->_die('The log entries could not be deleted.');
  1244     if(!$e) $db->_die('The log entries could not be deleted.');
  1245     $e = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
  1245     
  1246     if(!$e) $db->_die('The current page text could not be selected; as a result, creating the backup of the page failed. Please make a backup copy of the page by clicking Edit this page and then clicking Save Changes.');
  1246     // If the page exists, make a backup of it in case it gets spammed/vandalized
  1247     $row = $db->fetchrow();
  1247     // If not, the admin's probably deleting a trash page
  1248     $db->free_result();
  1248     if ( isset($paths->pages[ $paths->nslist[$namespace] . $page_id ]) )
  1249     $q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape($row['page_text']).'\', \''.$row['char_tag'].'\', \''.$session->username.'\', \''."Automatic backup created when logs were purged".'\', '.'false'.');';
  1249     {
  1250     if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.');
  1250       $e = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';');
       
  1251       if(!$e) $db->_die('The current page text could not be selected; as a result, creating the backup of the page failed. Please make a backup copy of the page by clicking Edit this page and then clicking Save Changes.');
       
  1252       $row = $db->fetchrow();
       
  1253       $db->free_result();
       
  1254       $q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape($row['page_text']).'\', \''.$row['char_tag'].'\', \''.$session->username.'\', \''."Automatic backup created when logs were purged".'\', '.'false'.');';
       
  1255       if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.');
       
  1256     }
  1251     return('The logs for this page have been cleared. A backup of this page has been added to the logs table so that this page can be restored in case of vandalism or spam later.');
  1257     return('The logs for this page have been cleared. A backup of this page has been added to the logs table so that this page can be restored in case of vandalism or spam later.');
  1252   }
  1258   }
  1253   
  1259   
  1254   /**
  1260   /**
  1255    * Deletes a page.
  1261    * Deletes a page.