includes/pageutils.php
changeset 898 c75754f5b1da
parent 832 7152ca0a0ce9
child 907 44851d7e9bda
equal deleted inserted replaced
897:f31c252c52c1 898:c75754f5b1da
  1166     $cache->purge('page_meta');
  1166     $cache->purge('page_meta');
  1167     return $lang->get('ajax_delete_success');
  1167     return $lang->get('ajax_delete_success');
  1168   }
  1168   }
  1169   
  1169   
  1170   /**
  1170   /**
       
  1171    * Deletes files associated with a File page.
       
  1172    * @param string Page ID
       
  1173    */
       
  1174   
       
  1175   public static function delete_page_files($page_id)
       
  1176   {
       
  1177     global $db, $session, $paths, $template, $plugins; // Common objects
       
  1178     
       
  1179     $q = $db->sql_query('SELECT file_id, filename, file_key, time_id, file_extension FROM ' . table_prefix . "files WHERE page_id = '{$db->escape($page_id)}';");
       
  1180     if ( !$q )
       
  1181       $db->_die();
       
  1182     
       
  1183     while ( $row = $db->fetchrow() )
       
  1184     {
       
  1185       // wipe original file
       
  1186       foreach ( array(
       
  1187           ENANO_ROOT . "/files/{$row['file_key']}_{$row['time_id']}{$row['file_extension']}",
       
  1188           ENANO_ROOT . "/files/{$row['file_key']}{$row['file_extension']}"
       
  1189         ) as $orig_file )
       
  1190       {
       
  1191         if ( file_exists($orig_file) )
       
  1192           @unlink($orig_file);
       
  1193       }
       
  1194       
       
  1195       // wipe cached files
       
  1196       if ( $dr = @opendir(ENANO_ROOT . '/cache/') )
       
  1197       {
       
  1198         // lol404.jpg-1217958283-200x320.jpg
       
  1199         while ( $dh = @readdir($dr) )
       
  1200         {
       
  1201           $regexp = ':^' . preg_quote("{$row['filename']}-{$row['time_id']}-") . '[0-9]+x[0-9]+\.' . ltrim($row['file_extension'], '.') . '$:';
       
  1202           if ( preg_match($regexp, $dh) )
       
  1203           {
       
  1204             @unlink(ENANO_ROOT . "/cache/$dh");
       
  1205           }
       
  1206         }
       
  1207         @closedir($dr);
       
  1208       }
       
  1209     }
       
  1210     
       
  1211     $q = $db->sql_query('DELETE FROM ' . table_prefix . "files WHERE page_id = '{$db->escape($page_id)}';");
       
  1212     if ( !$q )
       
  1213       $db->die();
       
  1214     
       
  1215     return true;
       
  1216   }
       
  1217   
       
  1218   /**
  1171    * Increments the deletion votes for a page by 1, and adds the current username/IP to the list of users that have voted for the page to prevent dual-voting
  1219    * Increments the deletion votes for a page by 1, and adds the current username/IP to the list of users that have voted for the page to prevent dual-voting
  1172    * @param $page_id the page ID
  1220    * @param $page_id the page ID
  1173    * @param $namespace the namespace
  1221    * @param $namespace the namespace
  1174    * @return string
  1222    * @return string
  1175    */
  1223    */
  1584    
  1632    
  1585   public static function pagediff($page_id, $namespace, $id1, $id2)
  1633   public static function pagediff($page_id, $namespace, $id1, $id2)
  1586   {
  1634   {
  1587     global $db, $session, $paths, $template, $plugins; // Common objects
  1635     global $db, $session, $paths, $template, $plugins; // Common objects
  1588     global $lang;
  1636     global $lang;
  1589     if(!$session->get_permissions('history_view'))
  1637     
       
  1638     if ( !$session->get_permissions('history_view') )
  1590       return $lang->get('etc_access_denied');
  1639       return $lang->get('etc_access_denied');
       
  1640     
  1591     if(!preg_match('#^([0-9]+)$#', (string)$id1) ||
  1641     if(!preg_match('#^([0-9]+)$#', (string)$id1) ||
  1592        !preg_match('#^([0-9]+)$#', (string)$id2  )) return 'SQL injection attempt';
  1642        !preg_match('#^([0-9]+)$#', (string)$id2  )) return 'SQL injection attempt';
  1593     // OK we made it through security
  1643     // OK we made it through security
  1594     // Safest way to make sure we don't end up with the revisions in wrong columns is to make 2 queries
  1644     // Safest way to make sure we don't end up with the revisions in wrong columns is to make 2 queries
  1595     if(!$q1 = $db->sql_query('SELECT page_text,char_tag,author,edit_summary FROM ' . table_prefix.'logs WHERE time_id=' . $id1 . ' AND log_type=\'page\' AND action=\'edit\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';')) return 'MySQL error: '.$db->get_error();
  1645     if ( !$q1 = $db->sql_query('SELECT time_id,page_text,char_tag,author,edit_summary FROM ' . table_prefix.'logs WHERE log_id = ' . $id1 . ' AND log_type=\'page\' AND action=\'edit\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';')) return 'MySQL error: ' . $db->get_error();
  1596     if(!$q2 = $db->sql_query('SELECT page_text,char_tag,author,edit_summary FROM ' . table_prefix.'logs WHERE time_id=' . $id2 . ' AND log_type=\'page\' AND action=\'edit\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';')) return 'MySQL error: '.$db->get_error();
  1646     if ( !$q2 = $db->sql_query('SELECT time_id,page_text,char_tag,author,edit_summary FROM ' . table_prefix.'logs WHERE log_id = ' . $id2 . ' AND log_type=\'page\' AND action=\'edit\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';')) return 'MySQL error: ' . $db->get_error();
  1597     $row1 = $db->fetchrow($q1);
  1647     $row1 = $db->fetchrow($q1);
  1598     $db->free_result($q1);
  1648     $db->free_result($q1);
  1599     $row2 = $db->fetchrow($q2);
  1649     $row2 = $db->fetchrow($q2);
  1600     $db->free_result($q2);
  1650     $db->free_result($q2);
  1601     if(sizeof($row1) < 1 || sizeof($row2) < 2) return 'Couldn\'t find any rows that matched the query. The time ID probably doesn\'t exist in the logs table.';
  1651     if(sizeof($row1) < 1 || sizeof($row2) < 2) return 'Couldn\'t find any rows that matched the query. The time ID probably doesn\'t exist in the logs table.';
  1602     $text1 = $row1['page_text'];
  1652     $text1 = $row1['page_text'];
  1603     $text2 = $row2['page_text'];
  1653     $text2 = $row2['page_text'];
  1604     $time1 = enano_date('F d, Y h:i a', $id1);
  1654     $time1 = enano_date('F d, Y h:i a', $row1['time_id']);
  1605     $time2 = enano_date('F d, Y h:i a', $id2);
  1655     $time2 = enano_date('F d, Y h:i a', $row2['time_id']);
  1606     $_ob = "
  1656     $_ob = "
  1607     <p>" . $lang->get('history_lbl_comparingrevisions') . " {$time1} &rarr; {$time2}</p>
  1657     <p>" . $lang->get('history_lbl_comparingrevisions') . " {$time1} &rarr; {$time2}</p>
  1608     ";
  1658     ";
  1609     // Free some memory
  1659     // Free some memory
  1610     unset($row1, $row2, $q1, $q2);
  1660     unset($row1, $row2, $q1, $q2);