619 |
620 |
620 // All good, fetch and free the result |
621 // All good, fetch and free the result |
621 $log_entry = $db->fetchrow(); |
622 $log_entry = $db->fetchrow(); |
622 $db->free_result(); |
623 $db->free_result(); |
623 |
624 |
|
625 $dateline = enano_date('d M Y h:i a', $log_entry['time_id']); |
|
626 |
624 // Let's see, what do we have here... |
627 // Let's see, what do we have here... |
625 switch ( $log_entry['action'] ) |
628 switch ( $log_entry['action'] ) |
626 { |
629 { |
627 case 'rename': |
630 case 'rename': |
628 // Page was renamed, let the rename method handle this |
631 // Page was renamed, let the rename method handle this |
629 return $this->rename($log_entry['edit_summary']); |
632 return array_merge($this->rename($log_entry['edit_summary']), array('dateline' => $dateline, 'action' => $log_entry['action'])); |
630 break; |
633 break; |
631 case 'prot': |
634 case 'prot': |
632 case 'unprot': |
635 case 'unprot': |
633 case 'semiprot': |
636 case 'semiprot': |
634 return $this->protect_page(intval($log_entry['page_text']), '__REVERSION__'); |
637 return array_merge($this->protect_page(intval($log_entry['page_text']), '__REVERSION__'), array('dateline' => $dateline, 'action' => $log_entry['action'])); |
|
638 break; |
|
639 case 'delete': |
|
640 |
|
641 // Raising a previously dead page has implications... |
|
642 |
|
643 // FIXME: l10n |
|
644 // rollback_extra is required because usually only moderators can undo page deletion AND restore the content. |
|
645 if ( !$this->perms->get_permissions('history_rollback_extra') ) |
|
646 return 'Administrative privileges are required for page undeletion.'; |
|
647 |
|
648 // Rolling back the deletion of a page that was since created? |
|
649 $pathskey = $paths->nslist[ $this->namespace ] . $this->page_id; |
|
650 if ( isset($paths->pages[$pathskey]) ) |
|
651 return array( |
|
652 'success' => false, |
|
653 // This is a clean Christian in-joke. |
|
654 'error' => 'seeking_living_among_dead' |
|
655 ); |
|
656 |
|
657 // Generate a crappy page name |
|
658 $name = $db->escape( str_replace('_', ' ', dirtify_page_id($this->page_id)) ); |
|
659 |
|
660 // Stage 1 - re-insert page |
|
661 $e = $db->sql_query('INSERT INTO ' . table_prefix.'pages(name,urlname,namespace) VALUES( \'' . $name . '\', \'' . $this->page_id . '\',\'' . $this->namespace . '\' )'); |
|
662 if ( !$e ) |
|
663 $db->die_json(); |
|
664 |
|
665 // Select the latest published revision |
|
666 $q = $db->sql_query('SELECT page_text FROM ' . table_prefix . "logs WHERE\n" |
|
667 . " log_type = 'page'\n" |
|
668 . " AND action = 'edit'\n" |
|
669 . " AND page_id = '$this->page_id'\n" |
|
670 . " AND namespace = '$this->namespace'\n" |
|
671 . " AND is_draft != 1\n" |
|
672 . "ORDER BY time_id DESC LIMIT 1;"); |
|
673 if ( !$q ) |
|
674 $db->die_json(); |
|
675 list($page_text) = $db->fetchrow_num(); |
|
676 $db->free_result($q); |
|
677 |
|
678 // Apply the latest revision as the current page text |
|
679 $page_text = $db->escape($page_text); |
|
680 $e = $db->sql_query('INSERT INTO ' . table_prefix."page_text(page_id, namespace, page_text) VALUES\n" |
|
681 . " ( '$this->page_id', '$this->namespace', '$page_text' );"); |
|
682 if ( !$e ) |
|
683 $db->die_json(); |
|
684 |
|
685 return array( |
|
686 'success' => true, |
|
687 'dateline' => $dateline, |
|
688 'action' => $log_entry['action'] |
|
689 ); |
|
690 |
|
691 break; |
|
692 case 'reupload': |
|
693 |
|
694 // given a log id and some revision info, restore the old file. |
|
695 // get the timestamp of the file before this one |
|
696 $q = $db->sql_query('SELECT time_id, file_key, file_extension, filename, size, mimetype FROM ' . table_prefix . "files WHERE time_id < {$log_entry['time_id']} ORDER BY time_id DESC LIMIT 1;"); |
|
697 if ( !$q ) |
|
698 $db->_die(); |
|
699 |
|
700 $row = $db->fetchrow(); |
|
701 $db->free_result(); |
|
702 |
|
703 // If the file hasn't been renamed to the new format (omitting timestamp), do that now. |
|
704 $fname = ENANO_ROOT . "/files/{$row['file_key']}_{$row['time_id']}{$row['file_extension']}"; |
|
705 if ( @file_exists($fname) ) |
|
706 { |
|
707 // it's stored in the old format - rename |
|
708 $fname_new = ENANO_ROOT . "/files/{$row['file_key']}{$row['file_extension']}"; |
|
709 if ( !@rename($fname, $fname_new) ) |
|
710 { |
|
711 return array( |
|
712 'success' => false, |
|
713 'error' => 'rb_file_rename_failed', |
|
714 'action' => $log_entry['action'] |
|
715 ); |
|
716 } |
|
717 } |
|
718 |
|
719 // Insert a new file entry |
|
720 $time = time(); |
|
721 $filename = $db->escape($row['filename']); |
|
722 $mimetype = $db->escape($row['mimetype']); |
|
723 $ext = $db->escape($row['file_extension']); |
|
724 $key = $db->escape($row['file_key']); |
|
725 |
|
726 $q = $db->sql_query('INSERT INTO ' . table_prefix . "files ( time_id, page_id, filename, size, mimetype, file_extension, file_key ) VALUES\n" |
|
727 . " ( $time, '$this->page_id', '$filename', {$row['size']}, '$mimetype', '$ext', '$key' );"); |
|
728 if ( !$q ) |
|
729 $db->die_json(); |
|
730 |
|
731 // add reupload log entry |
|
732 $username = $db->escape($session->username); |
|
733 $q = $db->sql_query('INSERT INTO ' . table_prefix . "logs ( log_type, action, time_id, page_id, namespace, author, edit_summary ) VALUES\n" |
|
734 . " ( 'page', 'reupload', $time, '$this->page_id', '$this->namespace', '$username', '__ROLLBACK__' )"); |
|
735 if ( !$q ) |
|
736 $db->die_json(); |
|
737 |
|
738 return array( |
|
739 'success' => true, |
|
740 'dateline' => $dateline, |
|
741 'action' => $log_entry['action'] |
|
742 ); |
|
743 |
635 break; |
744 break; |
636 default: |
745 default: |
|
746 |
|
747 return array( |
|
748 'success' => false, |
|
749 'error' => 'rb_action_not_supported', |
|
750 'action' => $log_entry['action'] |
|
751 ); |
|
752 |
637 break; |
753 break; |
638 } |
754 } |
639 } |
755 } |
640 |
756 |
641 /** |
757 /** |
753 |
877 |
754 $sql = 'INSERT INTO ' . table_prefix . "logs ( log_type, action, page_id, namespace, author, edit_summary, time_id, page_text, date_string ) VALUES\n" |
878 $sql = 'INSERT INTO ' . table_prefix . "logs ( log_type, action, page_id, namespace, author, edit_summary, time_id, page_text, date_string ) VALUES\n" |
755 . " ( 'page', '$action', '{$this->page_id}', '{$this->namespace}', '$username', '$reason', '$time', '$existing_protection', 'DATE_STRING COLUMN OBSOLETE, USE time_id' );"; |
879 . " ( 'page', '$action', '{$this->page_id}', '{$this->namespace}', '$username', '$reason', '$time', '$existing_protection', 'DATE_STRING COLUMN OBSOLETE, USE time_id' );"; |
756 if ( !$db->sql_query($sql) ) |
880 if ( !$db->sql_query($sql) ) |
757 { |
881 { |
758 $db->_die(); |
882 $db->die_json(); |
759 } |
883 } |
760 |
884 |
761 // Perform the actual protection |
885 // Perform the actual protection |
762 $q = $db->sql_query('UPDATE ' . table_prefix . "pages SET protected = $protection_level WHERE urlname = '{$this->page_id}' AND namespace = '{$this->namespace}';"); |
886 $q = $db->sql_query('UPDATE ' . table_prefix . "pages SET protected = $protection_level WHERE urlname = '{$this->page_id}' AND namespace = '{$this->namespace}';"); |
763 if ( !$q ) |
887 if ( !$q ) |
764 $db->_die(); |
888 $db->die_json(); |
765 |
889 |
766 return array( |
890 return array( |
767 'success' => true |
891 'success' => true |
768 ); |
892 ); |
769 } |
893 } |
1664 { |
1788 { |
1665 $r = $db->fetchrow(); |
1789 $r = $db->fetchrow(); |
1666 echo '<p>' . $lang->get('page_msg_404_was_deleted', array( |
1790 echo '<p>' . $lang->get('page_msg_404_was_deleted', array( |
1667 'delete_time' => enano_date('d M Y h:i a', $r['time_id']), |
1791 'delete_time' => enano_date('d M Y h:i a', $r['time_id']), |
1668 'delete_reason' => htmlspecialchars($r['edit_summary']), |
1792 'delete_reason' => htmlspecialchars($r['edit_summary']), |
1669 'rollback_flags' => 'href="'.makeUrl($paths->page, 'do=rollback&id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;"' |
1793 'rollback_flags' => 'href="'.makeUrl($paths->page, 'do=rollback&id='.$r['log_id']).'" onclick="ajaxRollback(\''.$r['log_id'].'\'); return false;"' |
1670 )) |
1794 )) |
1671 . '</p>'; |
1795 . '</p>'; |
1672 if ( $session->user_level >= USER_LEVEL_ADMIN ) |
1796 if ( $session->user_level >= USER_LEVEL_ADMIN ) |
1673 { |
1797 { |
1674 echo '<p>' . $lang->get('page_msg_404_admin_opts', array( |
1798 echo '<p>' . $lang->get('page_msg_404_admin_opts', array( |