includes/pageutils.php
changeset 1114 4f4d63a281cd
parent 1081 745200a9cc2a
child 1121 bf5adc446018
equal deleted inserted replaced
1113:000791abdc7e 1114:4f4d63a281cd
   996     }
   996     }
   997     if ( !$session->sid_super )
   997     if ( !$session->sid_super )
   998     {
   998     {
   999       return $lang->get('etc_access_denied_need_reauth');
   999       return $lang->get('etc_access_denied_need_reauth');
  1000     }
  1000     }
  1001     $e = $db->sql_query('DELETE FROM ' . table_prefix.'logs WHERE page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $db->escape($namespace) . '\';');
  1001     
  1002     if(!$e) $db->_die('The log entries could not be deleted.');
  1002     $page_id_db = $db->escape($page_id);
       
  1003     $namespace_db = $db->escape($namespace);
       
  1004     
       
  1005     // If we're flushing a file, also clear all revisions before the current
       
  1006     if ( $namespace == 'File' )
       
  1007     {
       
  1008       $q = $db->sql_query('SELECT file_id FROM ' . table_prefix . "files WHERE page_id='$page_id_db' ORDER BY time_id DESC;");
       
  1009       if ( !$q )
       
  1010         $db->_die();
       
  1011       // discard first row (current revision)
       
  1012       $db->fetchrow();
       
  1013       $id_list = array();
       
  1014       while ( $row = $db->fetchrow() )
       
  1015         $id_list[] = $row['file_id'];
       
  1016       
       
  1017       require_once(ENANO_ROOT . '/includes/namespaces/file.php');
       
  1018       
       
  1019       // clear out each file
       
  1020       foreach ( $id_list as $id )
       
  1021         Namespace_File::delete_file($id);
       
  1022     }
       
  1023     
       
  1024     $q = $db->sql_query('DELETE FROM ' . table_prefix . "logs WHERE page_id='$page_id_db' AND namespace='$namespace';");
       
  1025     if ( !$q )
       
  1026       $db->_die('The log entries could not be deleted.');
  1003     
  1027     
  1004     // If the page exists, make a backup of it in case it gets spammed/vandalized
  1028     // If the page exists, make a backup of it in case it gets spammed/vandalized
  1005     // If not, the admin's probably deleting a trash page
  1029     // If not, the admin's probably deleting a trash page
  1006     if ( isPage($paths->get_pathskey($page_id, $namespace)) )
  1030     if ( isPage($paths->get_pathskey($page_id, $namespace)) )
  1007     {
  1031     {
  1008       $e = $db->sql_query('SELECT page_text,char_tag FROM ' . table_prefix.'page_text WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';');
  1032       $q = $db->sql_query('SELECT page_text,char_tag FROM ' . table_prefix . "page_text WHERE page_id='$page_id_db' AND namespace='$namespace_db';");
  1009       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.');
  1033       if ( !$q )
       
  1034         $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.');
  1010       $row = $db->fetchrow();
  1035       $row = $db->fetchrow();
  1011       $db->free_result();
  1036       $db->free_result();
  1012       $minor_edit = ( ENANO_DBLAYER == 'MYSQL' ) ? 'false' : '0';
  1037       $minor_edit = ( ENANO_DBLAYER == 'MYSQL' ) ? 'false' : '0';
  1013       $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().', \''.enano_date(ED_DATE | ED_TIME).'\', \'' . $page_id . '\', \'' . $namespace . '\', \'' . $db->escape($row['page_text']) . '\', \'' . $row['char_tag'] . '\', \'' . $session->username . '\', \''."Automatic backup created when logs were purged".'\', '.$minor_edit.');';
  1038       $username = $db->escape($session->username);
  1014       if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.');
  1039       $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\n"
  1015     }
  1040          . "  ('page', 'edit', " . time() . ", 'DEPRECATED', '$page_id', '$namespace', '" . $db->escape($row['page_text']) . "', '', '{$username}', '" . $lang->get('page_flushlogs_backup_summary') . "', $minor_edit);";
       
  1041       if ( !$db->sql_query($q) )
       
  1042         $db->_die('The history (log) entry could not be inserted into the logs table.');
       
  1043     }
       
  1044     
  1016     return $lang->get('ajax_clearlogs_success');
  1045     return $lang->get('ajax_clearlogs_success');
  1017   }
  1046   }
  1018   
  1047   
  1019   /**
  1048   /**
  1020    * Deletes a page.
  1049    * Deletes a page.