includes/pageutils.php
changeset 408 7ecbe721217c
parent 402 d907601ccad2
child 413 6607cd646d6d
equal deleted inserted replaced
407:35d94240a197 408:7ecbe721217c
   431         echo '<td class="' . $cls . '" style="text-align: center;">'. (( $r['minor_edit'] ) ? 'M' : '' ) .'</td>'."\n";
   431         echo '<td class="' . $cls . '" style="text-align: center;">'. (( $r['minor_edit'] ) ? 'M' : '' ) .'</td>'."\n";
   432         
   432         
   433         // Actions!
   433         // Actions!
   434         echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'oldid=' . $r['time_id']) . '" onclick="ajaxHistView(\'' . $r['time_id'] . '\'); return false;">' . $lang->get('history_action_view') . '</a></td>'."\n";
   434         echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'oldid=' . $r['time_id']) . '" onclick="ajaxHistView(\'' . $r['time_id'] . '\'); return false;">' . $lang->get('history_action_view') . '</a></td>'."\n";
   435         echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrl($paths->nslist['Special'].'Contributions/' . $r['author']) . '">' . $lang->get('history_action_contrib') . '</a></td>'."\n";
   435         echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrl($paths->nslist['Special'].'Contributions/' . $r['author']) . '">' . $lang->get('history_action_contrib') . '</a></td>'."\n";
   436         echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'do=rollback&amp;id=' . $r['time_id']) . '" onclick="ajaxRollback(\'' . $r['time_id'] . '\'); return false;">' . $lang->get('history_action_restore') . '</a></td>'."\n";
   436         echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'do=edit&amp;revid=' . $r['time_id']) . '" onclick="ajaxEditor(\'' . $r['time_id'] . '\'); return false;">' . $lang->get('history_action_restore') . '</a></td>'."\n";
   437         
   437         
   438         echo '</tr>'."\n"."\n";
   438         echo '</tr>'."\n"."\n";
   439         
   439         
   440       }
   440       }
   441       echo '</table>
   441       echo '</table>
   522    */
   522    */
   523    
   523    
   524   public static function rollback($id)
   524   public static function rollback($id)
   525   {
   525   {
   526     global $db, $session, $paths, $template, $plugins; // Common objects
   526     global $db, $session, $paths, $template, $plugins; // Common objects
       
   527     global $lang;
       
   528     
       
   529     // FIXME: l10n
       
   530     
   527     if ( !$session->get_permissions('history_rollback') )
   531     if ( !$session->get_permissions('history_rollback') )
   528     {
   532     {
   529       return('You are not authorized to perform rollbacks.');
   533       return('You are not authorized to perform rollbacks.');
   530     }
   534     }
   531     if ( !preg_match('#^([0-9]+)$#', (string)$id) )
   535     if ( !preg_match('#^([0-9]+)$#', (string)$id) )
   582     switch($rb['log_type'])
   586     switch($rb['log_type'])
   583     {
   587     {
   584       case "page":
   588       case "page":
   585         switch($rb['action'])
   589         switch($rb['action'])
   586         {
   590         {
   587           case "edit":
   591           // Support for rolling back edits removed in 1.1.2 - moved to page editor system
   588             if ( !$perms->get_permissions('edit_page') )
       
   589               return "You don't have permission to edit pages, so rolling back edits can't be allowed either.";
       
   590             $t = $db->escape($rb['page_text']);
       
   591             $e = $db->sql_query('UPDATE ' . table_prefix.'page_text SET page_text=\'' . $t . '\',char_tag=\'' . $rb['char_tag'] . '\' WHERE page_id=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\'');
       
   592             if ( !$e )
       
   593             {
       
   594               return("An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace());
       
   595             }
       
   596             else
       
   597             {
       
   598               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'])) . '.';
       
   599             }
       
   600             break;
       
   601           case "rename":
   592           case "rename":
   602             if ( !$perms->get_permissions('rename') )
   593             if ( !$perms->get_permissions('rename') )
   603               return "You don't have permission to rename pages, so rolling back renames can't be allowed either.";
   594               return "You don't have permission to rename pages, so rolling back renames can't be allowed either.";
   604             $t = $db->escape($rb['edit_summary']);
   595             
   605             $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET name=\'' . $t . '\' WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\'');
   596             $t = $rb['edit_summary'];
       
   597             // result prediction
       
   598             $subst = array(
       
   599               'page_name_old' => get_page_title_ns($rb['page_id'], $rb['namespace']),
       
   600               'page_name_new' => $t
       
   601               );
       
   602             
       
   603             $e = PageUtils::rename($rb['page_id'], $rb['namespace'], $t);
       
   604             
       
   605             $e = ( $e == $lang->get('ajax_rename_success', $subst) );
       
   606             
   606             if ( !$e )
   607             if ( !$e )
   607             {
   608             {
   608               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   609               return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace();
   609             }
   610             }
   610             else
   611             else