includes/pageutils.php
changeset 351 8978cb3541ca
parent 345 4ccdfeee9a11
child 360 fad9bb5c094b
equal deleted inserted replaced
349:fdaf9070566c 351:8978cb3541ca
   209             $db->_die('The deletion log could not be selected.');
   209             $db->_die('The deletion log could not be selected.');
   210           }
   210           }
   211           if ($db->numrows() > 0 )
   211           if ($db->numrows() > 0 )
   212           {
   212           {
   213             $r = $db->fetchrow();
   213             $r = $db->fetchrow();
   214             echo '<p>This page also appears to have some log entries in the database - it seems that it was deleted on ' . $r['date_string'] . '. You can probably <a href="'.makeUrl($paths->page, 'do=rollback&amp;id=' . $r['time_id']) . '" onclick="ajaxRollback(\'' . $r['time_id'] . '\'); return false;">roll back</a> the deletion.</p>';
   214             echo '<p>This page also appears to have some log entries in the database - it seems that it was deleted on ' . enano_date('d M Y h:i a', intval($r['time_id'])) . '. You can probably <a href="'.makeUrl($paths->page, 'do=rollback&amp;id=' . $r['time_id']) . '" onclick="ajaxRollback(\'' . $r['time_id'] . '\'); return false;">roll back</a> the deletion.</p>';
   215           }
   215           }
   216           $db->free_result();
   216           $db->free_result();
   217         }
   217         }
   218         echo '<p>
   218         echo '<p>
   219                 HTTP Error: 404 Not Found
   219                 HTTP Error: 404 Not Found
   256         {
   256         {
   257           $db->_die('There were no rows in the text table that matched the page text query.');
   257           $db->_die('There were no rows in the text table that matched the page text query.');
   258         }
   258         }
   259         $r = $db->fetchrow();
   259         $r = $db->fetchrow();
   260         $db->free_result();
   260         $db->free_result();
   261         $message = '<div class="info-box" style="margin-left: 0; margin-top: 5px;"><b>Notice:</b><br />The page you are viewing was archived on ' . $r['date_string'] . '.<br /><a href="'.makeUrl($page).'" onclick="ajaxReset(); return false;">View current version</a>  |  <a href="'.makeUrl($page, 'do=rollback&amp;id=' . $hist_id) . '" onclick="ajaxRollback(\'' . $hist_id . '\')">Restore this version</a></div><br />'.RenderMan::render($r['page_text']);
   261         $message = '<div class="info-box" style="margin-left: 0; margin-top: 5px;"><b>Notice:</b><br />The page you are viewing was archived on ' . enano_date('d M Y h:i a', intval($r['time_id'])) . '.<br /><a href="'.makeUrl($page).'" onclick="ajaxReset(); return false;">View current version</a>  |  <a href="'.makeUrl($page, 'do=rollback&amp;id=' . $hist_id) . '" onclick="ajaxRollback(\'' . $hist_id . '\')">Restore this version</a></div><br />'.RenderMan::render($r['page_text']);
   262         
   262         
   263         if( !$paths->pages[$page]['special'] )
   263         if( !$paths->pages[$page]['special'] )
   264         {
   264         {
   265           if($send_headers)
   265           if($send_headers)
   266           {
   266           {
   616         }
   616         }
   617         if($ticker > 1)        echo '<td class="' . $cls . '" style="padding: 0;"><input ' . $s1 . 'name="diff1" type="radio" value="' . $r['time_id'] . '" id="diff1_' . $r['time_id'] . '" class="clsDiff1Radio" onclick="selectDiff1Button(this);" /></td>'."\n"; else echo '<td class="' . $cls . '"></td>';
   617         if($ticker > 1)        echo '<td class="' . $cls . '" style="padding: 0;"><input ' . $s1 . 'name="diff1" type="radio" value="' . $r['time_id'] . '" id="diff1_' . $r['time_id'] . '" class="clsDiff1Radio" onclick="selectDiff1Button(this);" /></td>'."\n"; else echo '<td class="' . $cls . '"></td>';
   618         if($ticker < $numrows) echo '<td class="' . $cls . '" style="padding: 0;"><input ' . $s2 . 'name="diff2" type="radio" value="' . $r['time_id'] . '" id="diff2_' . $r['time_id'] . '" class="clsDiff2Radio" onclick="selectDiff2Button(this);" /></td>'."\n"; else echo '<td class="' . $cls . '"></td>';
   618         if($ticker < $numrows) echo '<td class="' . $cls . '" style="padding: 0;"><input ' . $s2 . 'name="diff2" type="radio" value="' . $r['time_id'] . '" id="diff2_' . $r['time_id'] . '" class="clsDiff2Radio" onclick="selectDiff2Button(this);" /></td>'."\n"; else echo '<td class="' . $cls . '"></td>';
   619         
   619         
   620         // Date and time
   620         // Date and time
   621         echo '<td class="' . $cls . '">' . $r['date_string'] . '</td class="' . $cls . '">'."\n";
   621         echo '<td class="' . $cls . '">' . enano_date('d M Y h:i a', intval($r['time_id'])) . '</td class="' . $cls . '">'."\n";
   622         
   622         
   623         // User
   623         // User
   624         if ( $session->get_permissions('mod_misc') && is_valid_ip($r['author']) )
   624         if ( $session->get_permissions('mod_misc') && is_valid_ip($r['author']) )
   625         {
   625         {
   626           $rc = ' style="cursor: pointer;" title="' . $lang->get('history_tip_rdns') . '" onclick="ajaxReverseDNS(this, \'' . $r['author'] . '\');"';
   626           $rc = ' style="cursor: pointer;" title="' . $lang->get('history_tip_rdns') . '" onclick="ajaxReverseDNS(this, \'' . $r['author'] . '\');"';
   692         else $cls = 'row2';
   692         else $cls = 'row2';
   693         
   693         
   694         echo '<tr>';
   694         echo '<tr>';
   695         
   695         
   696         // Date and time
   696         // Date and time
   697         echo '<td class="' . $cls . '">' . $r['date_string'] . '</td class="' . $cls . '">';
   697         echo '<td class="' . $cls . '">' . enano_date('d M Y h:i a', intval($r['time_id'])) . '</td class="' . $cls . '">';
   698         
   698         
   699         // User
   699         // User
   700         echo '<td class="' . $cls . '"><a href="'.makeUrlNS('User', sanitize_page_id($r['author'])).'" ';
   700         echo '<td class="' . $cls . '"><a href="'.makeUrlNS('User', sanitize_page_id($r['author'])).'" ';
   701         if(!isPage($paths->nslist['User'] . sanitize_page_id($r['author']))) echo 'class="wikilink-nonexistent"';
   701         if(!isPage($paths->nslist['User'] . sanitize_page_id($r['author']))) echo 'class="wikilink-nonexistent"';
   702         echo '>' . $r['author'] . '</a></td class="' . $cls . '">';
   702         echo '>' . $r['author'] . '</a></td class="' . $cls . '">';
   809             {
   809             {
   810               return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
   810               return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
   811             }
   811             }
   812             else
   812             else
   813             {
   813             {
   814               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the state it was in on ' . $rb['date_string'] . '.';
   814               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the state it was in on ' . enano_date('d M Y h:i a', intval($rb['time_id'])) . '.';
   815             }
   815             }
   816             break;
   816             break;
   817           case "rename":
   817           case "rename":
   818             if ( !$perms->get_permissions('rename') )
   818             if ( !$perms->get_permissions('rename') )
   819               return "You don't have permission to rename pages, so rolling back renames can't be allowed either.";
   819               return "You don't have permission to rename pages, so rolling back renames can't be allowed either.";
   823             {
   823             {
   824               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   824               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   825             }
   825             }
   826             else
   826             else
   827             {
   827             {
   828               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the name it had ("' . $rb['edit_summary'] . '") before ' . $rb['date_string'] . '.';
   828               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the name it had ("' . $rb['edit_summary'] . '") before ' . enano_date('d M Y h:i a', intval($rb['time_id'])) . '.';
   829             }
   829             }
   830             break;
   830             break;
   831           case "prot":
   831           case "prot":
   832             if ( !$perms->get_permissions('protect') )
   832             if ( !$perms->get_permissions('protect') )
   833               return "You don't have permission to protect pages, so rolling back protection can't be allowed either.";
   833               return "You don't have permission to protect pages, so rolling back protection can't be allowed either.";
   834             $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=0 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\'');
   834             $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=0 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\'');
   835             if ( !$e )
   835             if ( !$e )
   836               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   836               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   837             else
   837             else
   838               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at ' . $rb['date_string'] . '.';
   838               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at ' . enano_date('d M Y h:i a', intval($rb['time_id'])) . '.';
   839             break;
   839             break;
   840           case "semiprot":
   840           case "semiprot":
   841             if ( !$perms->get_permissions('protect') )
   841             if ( !$perms->get_permissions('protect') )
   842               return "You don't have permission to protect pages, so rolling back protection can't be allowed either.";
   842               return "You don't have permission to protect pages, so rolling back protection can't be allowed either.";
   843             $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=0 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\'');
   843             $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=0 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\'');
   844             if ( !$e )
   844             if ( !$e )
   845               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   845               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   846             else
   846             else
   847               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at ' . $rb['date_string'] . '.';
   847               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at ' . enano_date('d M Y h:i a', intval($rb['time_id'])) . '.';
   848             break;
   848             break;
   849           case "unprot":
   849           case "unprot":
   850             if ( !$perms->get_permissions('protect') )
   850             if ( !$perms->get_permissions('protect') )
   851               return "You don't have permission to protect pages, so rolling back protection can't be allowed either.";
   851               return "You don't have permission to protect pages, so rolling back protection can't be allowed either.";
   852             $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=1 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\'');
   852             $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=1 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\'');
   853             if ( !$e )
   853             if ( !$e )
   854               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   854               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   855             else
   855             else
   856               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been protected according to the log created at ' . $rb['date_string'] . '.';
   856               return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been protected according to the log created at ' . enano_date('d M Y h:i a', intval($rb['time_id'])) . '.';
   857             break;
   857             break;
   858           case "delete":
   858           case "delete":
   859             if ( !$perms->get_permissions('history_rollback_extra') )
   859             if ( !$perms->get_permissions('history_rollback_extra') )
   860               return 'Administrative privileges are required for page undeletion.';
   860               return 'Administrative privileges are required for page undeletion.';
   861             if ( isset($paths->pages[$paths->cpage['urlname']]) )
   861             if ( isset($paths->pages[$paths->cpage['urlname']]) )
   863             $name = str_replace('_', ' ', $rb['page_id']);
   863             $name = str_replace('_', ' ', $rb['page_id']);
   864             $e = $db->sql_query('INSERT INTO ' . table_prefix.'pages(name,urlname,namespace) VALUES( \'' . $name . '\', \'' . $rb['page_id'] . '\',\'' . $rb['namespace'] . '\' )');if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
   864             $e = $db->sql_query('INSERT INTO ' . table_prefix.'pages(name,urlname,namespace) VALUES( \'' . $name . '\', \'' . $rb['page_id'] . '\',\'' . $rb['namespace'] . '\' )');if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
   865             $e = $db->sql_query('SELECT page_text,char_tag FROM ' . table_prefix.'logs WHERE page_id=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\' AND log_type=\'page\' AND action=\'edit\' ORDER BY time_id DESC;'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
   865             $e = $db->sql_query('SELECT page_text,char_tag FROM ' . table_prefix.'logs WHERE page_id=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\' AND log_type=\'page\' AND action=\'edit\' ORDER BY time_id DESC;'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
   866             $r = $db->fetchrow();
   866             $r = $db->fetchrow();
   867             $e = $db->sql_query('INSERT INTO ' . table_prefix.'page_text(page_id,namespace,page_text,char_tag) VALUES(\'' . $rb['page_id'] . '\',\'' . $rb['namespace'] . '\',\'' . $db->escape($r['page_text']) . '\',\'' . $r['char_tag'] . '\')'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
   867             $e = $db->sql_query('INSERT INTO ' . table_prefix.'page_text(page_id,namespace,page_text,char_tag) VALUES(\'' . $rb['page_id'] . '\',\'' . $rb['namespace'] . '\',\'' . $db->escape($r['page_text']) . '\',\'' . $r['char_tag'] . '\')'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
   868             return 'The page "' . $name . '" has been undeleted according to the log created at ' . $rb['date_string'] . '.';
   868             return 'The page "' . $name . '" has been undeleted according to the log created at ' . enano_date('d M Y h:i a', intval($rb['time_id'])) . '.';
   869             break;
   869             break;
   870           case "reupload":
   870           case "reupload":
   871             if ( !$session->get_permissions('history_rollback_extra') )
   871             if ( !$session->get_permissions('history_rollback_extra') )
   872             {
   872             {
   873               return 'Administrative privileges are required for file rollbacks.';
   873               return 'Administrative privileges are required for file rollbacks.';
  1451     if ( !is_object($lang) && defined('IN_ENANO_INSTALL') )
  1451     if ( !is_object($lang) && defined('IN_ENANO_INSTALL') )
  1452     {
  1452     {
  1453       // This is a special exception for the Enano installer, which doesn't init languages yet.
  1453       // This is a special exception for the Enano installer, which doesn't init languages yet.
  1454       $lang = new Language('eng');
  1454       $lang = new Language('eng');
  1455     }
  1455     }
  1456     if(!$session->get_permissions('clear_logs'))
  1456     if(!$session->get_permissions('clear_logs') && !defined('IN_ENANO_INSTALL'))
  1457     {
  1457     {
  1458       return $lang->get('etc_access_denied');
  1458       return $lang->get('etc_access_denied');
  1459     }
  1459     }
  1460     $e = $db->sql_query('DELETE FROM ' . table_prefix.'logs WHERE page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $db->escape($namespace) . '\';');
  1460     $e = $db->sql_query('DELETE FROM ' . table_prefix.'logs WHERE page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $db->escape($namespace) . '\';');
  1461     if(!$e) $db->_die('The log entries could not be deleted.');
  1461     if(!$e) $db->_die('The log entries could not be deleted.');