Revisão | 2d9a46989678b15d288a94512d61178a42081062 (tree) |
---|---|
Hora | 2007-09-23 00:08:44 |
Autor | henoheno <henoheno> |
Commiter | henoheno |
BugTrack2/125: Tracker_list: refer=page-name_that_has_tracker-list
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.65 2007/09/22 11:27:42 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.66 2007/09/22 15:08:44 henoheno Exp $ | |
4 | 4 | // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team |
5 | 5 | // License: GPL v2 or (at your option) any later version |
6 | 6 | // |
@@ -659,21 +659,20 @@ function plugin_tracker_list_action() | ||
659 | 659 | { |
660 | 660 | global $get, $vars; |
661 | 661 | |
662 | - $base = isset($get['base']) ? $get['base'] : ''; | |
662 | + $base = isset($get['base']) ? $get['base'] : ''; // Base directory to load | |
663 | + $refer = isset($get['refer']) ? $get['refer'] : $base; // Where to #tracker_list | |
664 | + if ($base == '') $base = $refer; // Compat before 1.4.8 | |
665 | + | |
663 | 666 | $config = isset($get['config']) ? $get['config'] : ''; |
664 | 667 | $list = isset($get['list']) ? $get['list'] : 'list'; |
665 | - | |
666 | 668 | $order = isset($vars['order']) ? $vars['order'] : PLUGIN_TRACKER_DEFAULT_ORDER; |
667 | 669 | $limit = isset($vars['limit']) ? $vars['limit'] : 0; |
668 | 670 | |
669 | - // Compat before 1.4.8 | |
670 | - if ($base == '') $base = isset($get['refer']) ? $get['refer'] : ''; | |
671 | - | |
672 | - $s_base = make_pagelink(trim($base)); | |
671 | + $s_refer = make_pagelink(trim($refer)); | |
673 | 672 | return array( |
674 | 673 | 'msg' => plugin_tracker_message('msg_list'), |
675 | - 'body'=> str_replace('$1', $s_base, plugin_tracker_message('msg_back')) . | |
676 | - plugin_tracker_list_render($base, $base, $config, $list, $order, $limit) | |
674 | + 'body'=> str_replace('$1', $s_refer, plugin_tracker_message('msg_back')) . | |
675 | + plugin_tracker_list_render($base, $refer, $config, $list, $order, $limit) | |
677 | 676 | ); |
678 | 677 | } |
679 | 678 |
@@ -682,7 +681,11 @@ function plugin_tracker_list_render($base, $refer, $config_name, $list, $order_c | ||
682 | 681 | $base = trim($base); |
683 | 682 | if ($base == '') return '#tracker_list: Base not specified' . '<br />'; |
684 | 683 | |
684 | + // TODO: is_page | |
685 | 685 | $refer = trim($refer); |
686 | + if (! is_page($refer)) { | |
687 | + return '#tracker_list: Refer page not found: ' . htmlspecialchars($refer) . '<br />'; | |
688 | + } | |
686 | 689 | |
687 | 690 | $config_name = trim($config_name); |
688 | 691 | if ($config_name == '') $config_name = PLUGIN_TRACKER_DEFAULT_CONFIG; |
@@ -691,7 +694,6 @@ function plugin_tracker_list_render($base, $refer, $config_name, $list, $order_c | ||
691 | 694 | if (! is_numeric($limit)) return PLUGIN_TRACKER_LIST_USAGE . '<br />'; |
692 | 695 | $limit = intval($limit); |
693 | 696 | |
694 | - | |
695 | 697 | $config = new Config('plugin/tracker/' . $config_name); |
696 | 698 | if (! $config->read()) { |
697 | 699 | return '#tracker_list: Config not found: ' . htmlspecialchars($config_name) . '<br />'; |
@@ -729,9 +731,10 @@ class Tracker_list | ||
729 | 731 | var $orders = array(); |
730 | 732 | var $error = ''; // Error message |
731 | 733 | |
734 | + // add() | |
732 | 735 | var $_added = array(); |
733 | 736 | |
734 | - // Used by toString() only | |
737 | + // toString() | |
735 | 738 | var $_itmes; |
736 | 739 | var $_the_first_character_of_the_line; |
737 | 740 |
@@ -744,7 +747,30 @@ class Tracker_list | ||
744 | 747 | $this->fields = plugin_tracker_get_fields($base, $refer, $config); |
745 | 748 | } |
746 | 749 | |
747 | - // Generate regexes | |
750 | + // Load pages | |
751 | + function _load() | |
752 | + { | |
753 | + $pattern = $this->base . '/'; | |
754 | + $pattern_len = strlen($pattern); | |
755 | + | |
756 | + foreach (get_existpages() as $_page) { | |
757 | + if (strpos($_page, $pattern) === 0) { | |
758 | + $name = substr($_page, $pattern_len); | |
759 | + if (preg_match(PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN, $name)) continue; | |
760 | + | |
761 | + // Adding $this->rows | |
762 | + if ($this->add($_page, $name) === FALSE) return FALSE; | |
763 | + } | |
764 | + } | |
765 | + if (empty($this->rows)) { | |
766 | + $this->error = 'Pages not found under: ' . $pattern; | |
767 | + return FALSE; | |
768 | + } | |
769 | + | |
770 | + return TRUE; | |
771 | + } | |
772 | + | |
773 | + // add(): Generate regexes | |
748 | 774 | function _generate_regex() |
749 | 775 | { |
750 | 776 | $config_page = $this->config->page; |
@@ -784,29 +810,6 @@ class Tracker_list | ||
784 | 810 | $this->pattern_fields = $pattern_fields; |
785 | 811 | } |
786 | 812 | |
787 | - // Load pages | |
788 | - function _load() | |
789 | - { | |
790 | - $pattern = $this->base . '/'; | |
791 | - $pattern_len = strlen($pattern); | |
792 | - | |
793 | - foreach (get_existpages() as $_page) { | |
794 | - if (strpos($_page, $pattern) === 0) { | |
795 | - $name = substr($_page, $pattern_len); | |
796 | - if (preg_match(PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN, $name)) continue; | |
797 | - | |
798 | - // Adding $this->rows | |
799 | - if ($this->add($_page, $name) === FALSE) return FALSE; | |
800 | - } | |
801 | - } | |
802 | - if (empty($this->rows)) { | |
803 | - $this->error = 'Pages not found under: ' . $pattern; | |
804 | - return FALSE; | |
805 | - } | |
806 | - | |
807 | - return TRUE; | |
808 | - } | |
809 | - | |
810 | 813 | function add($page, $name) |
811 | 814 | { |
812 | 815 | if (isset($this->_added[$page])) return TRUE; |
@@ -899,7 +902,7 @@ class Tracker_list | ||
899 | 902 | } |
900 | 903 | |
901 | 904 | $this->orders = $orders; |
902 | - return $orders; | |
905 | + return TRUE; | |
903 | 906 | } |
904 | 907 | |
905 | 908 | // Sort $this->rows by $this->orders |
@@ -992,10 +995,14 @@ class Tracker_list | ||
992 | 995 | // toString(): Called within preg_replace_callback() |
993 | 996 | function _replace_title($matches = array()) |
994 | 997 | { |
998 | + static $script; | |
999 | + | |
995 | 1000 | $fields = $this->fields; |
996 | 1001 | $orders = $this->orders; |
997 | - $list = $this->list; | |
1002 | + $base = $this->base; | |
1003 | + $refer = $this->refer; | |
998 | 1004 | $config_name = $this->config->config_name; |
1005 | + $list = $this->list; | |
999 | 1006 | |
1000 | 1007 | $fieldname = isset($matches[1]) ? $matches[1] : ''; |
1001 | 1008 | if (! isset($fields[$fieldname])) { |
@@ -1034,21 +1041,23 @@ class Tracker_list | ||
1034 | 1041 | $_order[] = $key . ':' . $this->_sortkey_define2string($value); |
1035 | 1042 | } |
1036 | 1043 | |
1044 | + if (! isset($script)) $script = get_script_uri(); | |
1045 | + $r_refer = ($refer != $base) ? | |
1046 | + '&refer=' . rawurlencode($refer) : ''; | |
1037 | 1047 | $r_config = ($config_name != PLUGIN_TRACKER_DEFAULT_CONFIG) ? |
1038 | 1048 | '&config=' . rawurlencode($config_name) : ''; |
1039 | 1049 | $r_list = ($list != PLUGIN_TRACKER_DEFAULT_LIST) ? |
1040 | 1050 | '&list=' . rawurlencode($list) : ''; |
1051 | + $r_order = ! empty($_order) ? | |
1052 | + '&order=' . rawurlencode(join(';', $_order)) : ''; | |
1041 | 1053 | |
1042 | 1054 | return |
1043 | 1055 | '[[' . |
1044 | 1056 | $fields[$fieldname]->title . $arrow . |
1045 | 1057 | '>' . |
1046 | - get_script_uri() . | |
1047 | - '?plugin=tracker_list' . | |
1048 | - '&base=' . rawurlencode($this->base) . | |
1049 | - $r_config . | |
1050 | - $r_list . | |
1051 | - '&order=' . rawurlencode(join(';', $_order)) . | |
1058 | + $script . '?plugin=tracker_list' . | |
1059 | + '&base=' . rawurlencode($base) . | |
1060 | + $r_refer . $r_config . $r_list . $r_order . | |
1052 | 1061 | ']]'; |
1053 | 1062 | } |
1054 | 1063 |
@@ -1096,7 +1105,8 @@ class Tracker_list | ||
1096 | 1105 | // Loading template: Roughly checking listed fields |
1097 | 1106 | $matches = array(); |
1098 | 1107 | $used_fieldname = array('_real' => TRUE); |
1099 | - preg_match_all($regex, plugin_tracker_get_source($list, TRUE), $matches); | |
1108 | + $template = plugin_tracker_get_source($list, TRUE); | |
1109 | + preg_match_all($regex, $template, $matches); | |
1100 | 1110 | unset($matches[0]); |
1101 | 1111 | foreach ($matches[1] as $match) { |
1102 | 1112 | $params = explode(',', $match); |
@@ -1131,6 +1141,7 @@ class Tracker_list | ||
1131 | 1141 | if ($this->_sort() === FALSE) return FALSE; |
1132 | 1142 | $rows = $this->rows; |
1133 | 1143 | |
1144 | + // toString() | |
1134 | 1145 | $count = count($this->rows); |
1135 | 1146 | $limit = intval($limit); |
1136 | 1147 | if ($limit != 0) $limit = max(1, $limit); |