496 elseif($r['action']=='unprot') echo $lang->get('history_log_unprotect') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . ( $r['edit_summary'] === '__REVERSION__' ? $lang->get('history_extra_protection_reversion') : htmlspecialchars($r['edit_summary']) ); |
496 elseif($r['action']=='unprot') echo $lang->get('history_log_unprotect') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . ( $r['edit_summary'] === '__REVERSION__' ? $lang->get('history_extra_protection_reversion') : htmlspecialchars($r['edit_summary']) ); |
497 elseif($r['action']=='semiprot') echo $lang->get('history_log_semiprotect') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . ( $r['edit_summary'] === '__REVERSION__' ? $lang->get('history_extra_protection_reversion') : htmlspecialchars($r['edit_summary']) ); |
497 elseif($r['action']=='semiprot') echo $lang->get('history_log_semiprotect') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . ( $r['edit_summary'] === '__REVERSION__' ? $lang->get('history_extra_protection_reversion') : htmlspecialchars($r['edit_summary']) ); |
498 elseif($r['action']=='rename') echo $lang->get('history_log_rename') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_oldtitle') . ' '.htmlspecialchars($r['edit_summary']); |
498 elseif($r['action']=='rename') echo $lang->get('history_log_rename') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_oldtitle') . ' '.htmlspecialchars($r['edit_summary']); |
499 elseif($r['action']=='create') echo $lang->get('history_log_create') . '</td><td class="' . $cls . '">'; |
499 elseif($r['action']=='create') echo $lang->get('history_log_create') . '</td><td class="' . $cls . '">'; |
500 elseif($r['action']=='delete') echo $lang->get('history_log_delete') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . $r['edit_summary']; |
500 elseif($r['action']=='delete') echo $lang->get('history_log_delete') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . $r['edit_summary']; |
501 elseif($r['action']=='reupload') echo $lang->get('history_log_uploadnew') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' '.htmlspecialchars($r['edit_summary']); |
501 elseif($r['action']=='reupload') echo $lang->get('history_log_uploadnew') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . ( $r['edit_summary'] === '__ROLLBACK__' ? $lang->get('history_extra_upload_reversion') : htmlspecialchars($r['edit_summary']) ); |
502 echo '</td>'; |
502 echo '</td>'; |
503 |
503 |
504 // Actions! |
504 // Actions! |
505 echo '<td class="' . $cls . '" style="text-align: center;"><a rel="nofollow" href="'.makeUrl($paths->nslist['Special'].'Contributions/' . $r['author']) . '">' . $lang->get('history_action_contrib') . '</a></td>'; |
505 echo '<td class="' . $cls . '" style="text-align: center;"><a rel="nofollow" href="'.makeUrl($paths->nslist['Special'].'Contributions/' . $r['author']) . '">' . $lang->get('history_action_contrib') . '</a></td>'; |
506 echo '<td class="' . $cls . '" style="text-align: center;"><a rel="nofollow" href="'.makeUrlNS($namespace, $page_id, 'do=rollback&id=' . $r['log_id']) . '" onclick="ajaxRollback(\'' . $r['log_id'] . '\'); return false;">' . $lang->get('history_action_revert') . '</a></td>'; |
506 echo '<td class="' . $cls . '" style="text-align: center;"><a rel="nofollow" href="'.makeUrlNS($namespace, $page_id, 'do=rollback&id=' . $r['log_id']) . '" onclick="ajaxRollback(\'' . $r['log_id'] . '\'); return false;">' . $lang->get('history_action_revert') . '</a></td>'; |
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; |
527 global $lang; |
528 |
528 |
529 // FIXME: l10n |
529 // placeholder |
530 |
530 return 'PageUtils->rollback() is deprecated - use PageProcessor instead.'; |
531 if ( !$session->get_permissions('history_rollback') ) |
|
532 { |
|
533 return('You are not authorized to perform rollbacks.'); |
|
534 } |
|
535 if ( !preg_match('#^([0-9]+)$#', (string)$id) ) |
|
536 { |
|
537 return('The value "id" on the query string must be an integer.'); |
|
538 } |
|
539 $e = $db->sql_query('SELECT time_id,log_type,action,date_string,page_id,namespace,page_text,char_tag,author,edit_summary FROM ' . table_prefix.'logs WHERE log_id=' . $id . ';'); |
|
540 if ( !$e ) |
|
541 { |
|
542 $db->_die('The rollback data could not be selected.'); |
|
543 } |
|
544 $rb = $db->fetchrow(); |
|
545 $db->free_result(); |
|
546 |
|
547 if ( $rb['log_type'] == 'page' && $rb['action'] != 'delete' ) |
|
548 { |
|
549 $pagekey = $paths->nslist[$rb['namespace']] . $rb['page_id']; |
|
550 if ( !isset($paths->pages[$pagekey]) ) |
|
551 { |
|
552 return "Page doesn't exist"; |
|
553 } |
|
554 $pagedata =& $paths->pages[$pagekey]; |
|
555 $protected = false; |
|
556 // Special case: is the page protected? if so, check for even_when_protected permissions |
|
557 if($pagedata['protected'] == 2) |
|
558 { |
|
559 // The page is semi-protected, determine permissions |
|
560 if($session->user_logged_in && $session->reg_time + 60*60*24*4 < time()) |
|
561 { |
|
562 $protected = false; |
|
563 } |
|
564 else |
|
565 { |
|
566 $protected = true; |
|
567 } |
|
568 } |
|
569 else |
|
570 { |
|
571 $protected = ( $pagedata['protected'] == 1 ); |
|
572 } |
|
573 |
|
574 $perms = $session->fetch_page_acl($rb['page_id'], $rb['namespace']); |
|
575 |
|
576 if ( $protected && !$perms->get_permissions('even_when_protected') ) |
|
577 { |
|
578 return "Because this page is protected, you need moderator rights to roll back changes."; |
|
579 } |
|
580 } |
|
581 else |
|
582 { |
|
583 $perms =& $session; |
|
584 } |
|
585 |
|
586 switch($rb['log_type']) |
|
587 { |
|
588 case "page": |
|
589 switch($rb['action']) |
|
590 { |
|
591 // Support for rolling back edits removed in 1.1.2 - moved to page editor system |
|
592 case "rename": |
|
593 if ( !$perms->get_permissions('rename') ) |
|
594 return "You don't have permission to rename pages, so rolling back renames can't be allowed either."; |
|
595 |
|
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 |
|
607 if ( !$e ) |
|
608 { |
|
609 return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace(); |
|
610 } |
|
611 else |
|
612 { |
|
613 return 'The page "' . htmlspecialchars($paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name']) . '" has been rolled back to the name it had ("' . htmlspecialchars($rb['edit_summary']) . '") before ' . enano_date('d M Y h:i a', intval($rb['time_id'])) . '.'; |
|
614 } |
|
615 break; |
|
616 case "prot": |
|
617 if ( !$perms->get_permissions('protect') ) |
|
618 return "You don't have permission to protect pages, so rolling back protection can't be allowed either."; |
|
619 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=0 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\''); |
|
620 if ( !$e ) |
|
621 return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace(); |
|
622 else |
|
623 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'])) . '.'; |
|
624 break; |
|
625 case "semiprot": |
|
626 if ( !$perms->get_permissions('protect') ) |
|
627 return "You don't have permission to protect pages, so rolling back protection can't be allowed either."; |
|
628 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=0 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\''); |
|
629 if ( !$e ) |
|
630 return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace(); |
|
631 else |
|
632 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'])) . '.'; |
|
633 break; |
|
634 case "unprot": |
|
635 if ( !$perms->get_permissions('protect') ) |
|
636 return "You don't have permission to protect pages, so rolling back protection can't be allowed either."; |
|
637 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=1 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\''); |
|
638 if ( !$e ) |
|
639 return "An error occurred during the rollback operation.\nMySQL said: ".$db->get_error()."\n\nSQL backtrace:\n".$db->sql_backtrace(); |
|
640 else |
|
641 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'])) . '.'; |
|
642 break; |
|
643 case "delete": |
|
644 if ( !$perms->get_permissions('history_rollback_extra') ) |
|
645 return 'Administrative privileges are required for page undeletion.'; |
|
646 if ( isset($paths->pages[$paths->cpage['urlname']]) ) |
|
647 return 'You cannot raise a dead page that is alive.'; |
|
648 $name = str_replace('_', ' ', $rb['page_id']); |
|
649 $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()); |
|
650 $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()); |
|
651 $r = $db->fetchrow(); |
|
652 $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()); |
|
653 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'])) . '.'; |
|
654 break; |
|
655 case "reupload": |
|
656 if ( !$session->get_permissions('history_rollback_extra') ) |
|
657 { |
|
658 return 'Administrative privileges are required for file rollbacks.'; |
|
659 } |
|
660 $newtime = time(); |
|
661 $newdate = enano_date('d M Y h:i a'); |
|
662 if(!$db->sql_query('UPDATE ' . table_prefix.'logs SET time_id=' . $newtime . ',date_string=\'' . $newdate . '\' WHERE time_id=' . $id)) |
|
663 return 'Error during query: '.$db->get_error(); |
|
664 if(!$db->sql_query('UPDATE ' . table_prefix.'files SET time_id=' . $newtime . ' WHERE time_id=' . $id)) |
|
665 return 'Error during query: '.$db->get_error(); |
|
666 return 'The file has been rolled back to the version uploaded on '.enano_date('d M Y h:i a', (int)$id).'.'; |
|
667 break; |
|
668 default: |
|
669 return('Rollback of the action "' . $rb['action'] . '" is not yet supported.'); |
|
670 break; |
|
671 } |
|
672 break; |
|
673 case "security": |
|
674 case "login": |
|
675 return('A ' . $rb['log_type'] . '-related log entry cannot be rolled back.'); |
|
676 break; |
|
677 default: |
|
678 return('Unknown log entry type: "' . $rb['log_type'] . '"'); |
|
679 } |
|
680 } |
531 } |
681 |
532 |
682 /** |
533 /** |
683 * Posts a comment. |
534 * Posts a comment. |
684 * @param $page_id the page ID |
535 * @param $page_id the page ID |