555 if ( !$q ) |
570 if ( !$q ) |
556 $db->_die('PageProcessor page creation - logging stage'); |
571 $db->_die('PageProcessor page creation - logging stage'); |
557 |
572 |
558 // Page created. We're good! |
573 // Page created. We're good! |
559 return true; |
574 return true; |
|
575 } |
|
576 |
|
577 /** |
|
578 * Rolls back a non-edit action in the logs |
|
579 * @param int Log entry (log_id) to roll back |
|
580 * @return array Standard Enano error/success protocol |
|
581 */ |
|
582 |
|
583 function rollback_log_entry($log_id) |
|
584 { |
|
585 global $db, $session, $paths, $template, $plugins; // Common objects |
|
586 |
|
587 // Verify permissions |
|
588 if ( !$this->perms->get_permissions('history_rollback') ) |
|
589 { |
|
590 return array( |
|
591 'success' => false, |
|
592 'error' => 'access_denied' |
|
593 ); |
|
594 } |
|
595 |
|
596 // Check input |
|
597 $log_id = intval($log_id); |
|
598 if ( empty($log_id) ) |
|
599 { |
|
600 return array( |
|
601 'success' => false, |
|
602 'error' => 'invalid_parameter' |
|
603 ); |
|
604 } |
|
605 |
|
606 // Fetch the log entry |
|
607 $q = $db->sql_query('SELECT * FROM ' . table_prefix . "logs WHERE log_type = 'page' AND page_id='{$this->page_id}' AND namespace='{$this->namespace}' AND log_id = $log_id;"); |
|
608 if ( !$q ) |
|
609 $db->_die(); |
|
610 |
|
611 // Is this even a valid log entry for this context? |
|
612 if ( $db->numrows() < 1 ) |
|
613 { |
|
614 return array( |
|
615 'success' => false, |
|
616 'error' => 'entry_not_found' |
|
617 ); |
|
618 } |
|
619 |
|
620 // All good, fetch and free the result |
|
621 $log_entry = $db->fetchrow(); |
|
622 $db->free_result(); |
|
623 |
|
624 // Let's see, what do we have here... |
|
625 switch ( $log_entry['action'] ) |
|
626 { |
|
627 case 'rename': |
|
628 // Page was renamed, let the rename method handle this |
|
629 return $this->rename($log_entry['edit_summary']); |
|
630 break; |
|
631 case 'prot': |
|
632 case 'unprot': |
|
633 case 'semiprot': |
|
634 return $this->protect_page(intval($log_entry['page_text']), '__REVERSION__'); |
|
635 break; |
|
636 default: |
|
637 break; |
|
638 } |
|
639 } |
|
640 |
|
641 /** |
|
642 * Renames the page |
|
643 * @param string New name |
|
644 * @return array Standard Enano error/success protocol |
|
645 */ |
|
646 |
|
647 function rename_page($new_name) |
|
648 { |
|
649 global $db, $session, $paths, $template, $plugins; // Common objects |
|
650 |
|
651 // Check permissions |
|
652 if ( !$this->perms->get_permissions('rename') ) |
|
653 { |
|
654 return array( |
|
655 'success' => false, |
|
656 'error' => 'access_denied' |
|
657 ); |
|
658 } |
|
659 |
|
660 // If this is the same as the current name, return success |
|
661 $page_name = get_page_title_ns($this->page_id, $this->namespace); |
|
662 if ( $page_name === $new_name ) |
|
663 { |
|
664 return array( |
|
665 'success' => true |
|
666 ); |
|
667 } |
|
668 |
|
669 // Make sure the name is valid |
|
670 $new_name = trim($new_name); |
|
671 if ( empty($new_name) ) |
|
672 { |
|
673 return array( |
|
674 'success' => false, |
|
675 'error' => 'invalid_parameter' |
|
676 ); |
|
677 } |
|
678 |
|
679 // Log the action |
|
680 $username = $db->escape($session->username); |
|
681 $page_name = $db->escape($page_name); |
|
682 $time = time(); |
|
683 |
|
684 $q = $db->sql_query('INSERT INTO ' . table_prefix . "logs ( log_type, action, page_id, namespace, author, edit_summary, time_id, date_string ) VALUES\n" |
|
685 . " ( 'page', 'rename', '{$this->page_id}', '{$this->namespace}', '$username', '$page_name', '$time', 'DATE_STRING COLUMN OBSOLETE, USE time_id' );"); |
|
686 if ( !$q ) |
|
687 $db->_die(); |
|
688 |
|
689 // Not much to do but to rename it now |
|
690 $new_name = $db->escape($new_name); |
|
691 $q = $db->sql_query('UPDATE ' . table_prefix . "pages SET name = '$new_name' WHERE urlname = '{$this->page_id}' AND namespace = '{$this->namespace}';"); |
|
692 if ( !$q ) |
|
693 $db->_die(); |
|
694 |
|
695 return array( |
|
696 'success' => true |
|
697 ); |
|
698 } |
|
699 |
|
700 /** |
|
701 * Sets the protection level of the page |
|
702 * @param int Protection level, one of PROTECT_{FULL,SEMI,NONE} |
|
703 * @param string Reason for protection - required |
|
704 */ |
|
705 |
|
706 function protect_page($protection_level, $reason) |
|
707 { |
|
708 global $db, $session, $paths, $template, $plugins; // Common objects |
|
709 |
|
710 // Validate permissions |
|
711 if ( !$this->perms->get_permissions('protect') ) |
|
712 { |
|
713 return array( |
|
714 'success' => false, |
|
715 'error' => 'access_denied' |
|
716 ); |
|
717 } |
|
718 |
|
719 // Validate input |
|
720 $reason = trim($reason); |
|
721 if ( !in_array($protection_level, array(PROTECT_NONE, PROTECT_FULL, PROTECT_SEMI)) || empty($reason) ) |
|
722 { |
|
723 return array( |
|
724 'success' => false, |
|
725 'error' => 'invalid_parameter' |
|
726 ); |
|
727 } |
|
728 |
|
729 // Retrieve page metadata |
|
730 $pathskey = $paths->nslist[ $this->namespace ] . $this->page_id; |
|
731 if ( !isset($paths->pages[$pathskey]) ) |
|
732 { |
|
733 return array( |
|
734 'success' => false, |
|
735 'error' => 'page_metadata_not_found' |
|
736 ); |
|
737 } |
|
738 $metadata =& $paths->pages[$pathskey]; |
|
739 |
|
740 // Log the action |
|
741 $username = $db->escape($session->username); |
|
742 $time = time(); |
|
743 $existing_protection = intval($metadata['protected']); |
|
744 $reason = $db->escape($reason); |
|
745 |
|
746 $action = '[ insanity ]'; |
|
747 switch($protection_level) |
|
748 { |
|
749 case PROTECT_FULL: $action = 'prot'; break; |
|
750 case PROTECT_NONE: $action = 'unprot'; break; |
|
751 case PROTECT_SEMI: $action = 'semiprot'; break; |
|
752 } |
|
753 |
|
754 $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' );"; |
|
756 if ( !$db->sql_query($sql) ) |
|
757 { |
|
758 $db->_die(); |
|
759 } |
|
760 |
|
761 // 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}';"); |
|
763 if ( !$q ) |
|
764 $db->_die(); |
|
765 |
|
766 return array( |
|
767 'success' => true |
|
768 ); |
560 } |
769 } |
561 |
770 |
562 /** |
771 /** |
563 * Sets internal variables. |
772 * Sets internal variables. |
564 * @access private |
773 * @access private |
708 if ( $this->revision_id ) |
917 if ( $this->revision_id ) |
709 { |
918 { |
710 echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;"> |
919 echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;"> |
711 <b>' . $lang->get('page_msg_archived_title') . '</b><br /> |
920 <b>' . $lang->get('page_msg_archived_title') . '</b><br /> |
712 ' . $lang->get('page_msg_archived_body', array( |
921 ' . $lang->get('page_msg_archived_body', array( |
713 'archive_date' => enano_date('F d, Y', $this->revision_id), |
922 'archive_date' => enano_date('F d, Y', $this->revision_time), |
714 'archive_time' => enano_date('h:i a', $this->revision_id), |
923 'archive_time' => enano_date('h:i a', $this->revision_time), |
715 'current_link' => makeUrlNS($this->namespace, $this->page_id), |
924 'current_link' => makeUrlNS($this->namespace, $this->page_id), |
716 'restore_link' => makeUrlNS($this->namespace, $this->page_id, 'do=rollback&id='.$this->revision_id), |
925 'restore_link' => makeUrlNS($this->namespace, $this->page_id, 'do=edit&revid='.$this->revision_id), |
717 'restore_onclick' => 'ajaxRollback(\''.$this->revision_id.'\'); return false;', |
926 'restore_onclick' => 'ajaxEditor(\''.$this->revision_id.'\'); return false;', |
718 )) . ' |
927 )) . ' |
719 </div> |
928 </div>'; |
720 <br />'; |
|
721 } |
929 } |
722 |
930 |
723 if ( $redir_enabled ) |
931 if ( $redir_enabled ) |
724 { |
932 { |
725 echo $redir_html; |
933 echo $redir_html; |