• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisão58602f80d335066bea0f1ada03dc429f6d196b99 (tree)
Hora2007-09-09 01:30:25
Autorhenoheno <henoheno>
Commiterhenoheno

Mensagem de Log

Cleanup/Simplify/Todo
* Tracker_field, Tracker_list: Added dispose() to clear some static variables. -- When you create-and-destroy some instances of a class serially without dispose, they will use the same static variable causing side-effects. Note you should not use static variables if you can. When you create multiple instances of a class simultaneously, they will use the same static variables causing terrible side-effects.
* Remove unused arguments
* Less grobal variables

Mudança Sumário

Diff

--- a/plugin/tracker.inc.php
+++ b/plugin/tracker.inc.php
@@ -1,12 +1,13 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone
3-// $Id: tracker.inc.php,v 1.44 2007/09/05 15:17:39 henoheno Exp $
3+// $Id: tracker.inc.php,v 1.45 2007/09/08 16:30:25 henoheno Exp $
44 // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team
55 // License: GPL v2 or (at your option) any later version
66 //
77 // Issue tracker plugin (See Also bugtrack plugin)
88
9-define('PLUGIN_TRACKER_USAGE', '#tracker([config[/form][,basepage]])');
9+define('PLUGIN_TRACKER_USAGE', '#tracker([config[/form][,basepage]])');
10+define('PLUGIN_TRACKER_LIST_USAGE', '#tracker_list([config][[,base][,field:sort[;field:sort ...][,limit]]])');
1011
1112 define('PLUGIN_TRACKER_DEFAULT_CONFIG', 'default');
1213 define('PLUGIN_TRACKER_DEFAULT_FORM', 'form');
@@ -58,17 +59,19 @@ function plugin_tracker_convert()
5859 return '#tracker: Form \'' . make_pagelink($form) . '\' not found<br />';
5960 }
6061
61- $from = $to = $hidden = array();
62+ $from = $to = $hidden = array();
6263 $fields = plugin_tracker_get_fields($base, $refer, $config);
6364 foreach (array_keys($fields) as $field) {
6465 $from[] = '[' . $field . ']';
6566 $_to = $fields[$field]->get_tag();
6667 if (is_a($fields[$field], 'Tracker_field_hidden')) {
67- $hidden[] = $_to;
6868 $to[] = '';
69+ $hidden[] = $_to;
6970 } else {
7071 $to[] = $_to;
7172 }
73+ $fields[$field]->dispose();
74+ unset($fields[$field]);
7275 }
7376
7477 $script = get_script_uri();
@@ -141,14 +144,14 @@ function plugin_tracker_action()
141144 // Creating an empty page, before attaching files
142145 pkwk_touch_file(get_filename($page));
143146
144- // Load $fields
145- $fields = plugin_tracker_get_fields($page, $refer, $config);
146147 $from = $to = array();
148+ $fields = plugin_tracker_get_fields($page, $refer, $config);
147149 foreach (array_keys($fields) as $field) {
148150 $from[] = '[' . $field . ']';
149151 $to[] = isset($_post[$field]) ? $fields[$field]->format_value($_post[$field]) : '';
152+ $fields[$field]->dispose();
153+ unset($fields[$field]);
150154 }
151- unset($fields);
152155
153156 // Load $template
154157 $template = plugin_tracker_get_source($template_page);
@@ -195,7 +198,7 @@ function plugin_tracker_action()
195198 // Construct $fields (an array of Tracker_field objects)
196199 function plugin_tracker_get_fields($base, $refer, & $config)
197200 {
198- global $now, $_tracker_messages;
201+ global $now;
199202
200203 $fields = array();
201204
@@ -205,7 +208,7 @@ function plugin_tracker_get_fields($base, $refer, & $config)
205208 // $field[2]: Field type
206209 // $field[3]: Option ("size", "cols", "rows", etc)
207210 // $field[4]: Default value
208- $class = 'Tracker_field_' . $field[2];
211+ $class = 'Tracker_field_' . $field[2];
209212 if (! class_exists($class)) {
210213 // Default
211214 $field[2] = 'text';
@@ -231,7 +234,7 @@ function plugin_tracker_get_fields($base, $refer, & $config)
231234 ) as $fieldname => $type)
232235 {
233236 if (isset($fields[$fieldname])) continue;
234- $field = array($fieldname, $_tracker_messages['btn' . $fieldname], '', '20', '');
237+ $field = array($fieldname, plugin_tracker_message('btn' . $fieldname), '', '20', '');
235238 $class = 'Tracker_field_' . $type;
236239 $fields[$fieldname] = & new $class($field, $base, $refer, $config);
237240 }
@@ -256,7 +259,7 @@ class Tracker_field
256259 function Tracker_field($field, $page, $refer, & $config)
257260 {
258261 global $post;
259- static $id = 0;
262+ static $id = 0; // Unique id per instance
260263
261264 $this->id = ++$id;
262265 $this->name = $field[0];
@@ -269,12 +272,13 @@ class Tracker_field
269272 $this->data = isset($post[$this->name]) ? $post[$this->name] : '';
270273 }
271274
275+ // XHTML part inside a form
272276 function get_tag()
273277 {
274278 return '';
275279 }
276280
277- function get_style($str)
281+ function get_style()
278282 {
279283 return '%s';
280284 }
@@ -289,9 +293,15 @@ class Tracker_field
289293 return $str;
290294 }
291295
296+ // Compare key for Tracker_list->sort()
292297 function get_value($value)
293298 {
294- return $value;
299+ return $value; // Default: $value itself
300+ }
301+
302+ // Release the resources
303+ function dispose()
304+ {
295305 }
296306 }
297307
@@ -418,7 +428,7 @@ class Tracker_field_file extends Tracker_field_format
418428 ' size="' . htmlspecialchars($this->values[0]) . '" />';
419429 }
420430
421- function format_value($str)
431+ function format_value()
422432 {
423433 if (isset($_FILES[$this->name])) {
424434
@@ -471,16 +481,29 @@ class Tracker_field_radio extends Tracker_field_format
471481 function get_value($value)
472482 {
473483 static $options = array();
484+
485+ if ($value === NULL) {
486+ $options = array();
487+ return NULL;
488+ }
489+
474490 if (! isset($options[$this->name])) {
475- $options[$this->name] =
476- array_flip(
477- array_map(create_function('$arr', 'return $arr[0];'),
491+ $options[$this->name] = array_flip(
492+ array_map(
493+ create_function('$arr', 'return $arr[0];'),
478494 $this->config->get($this->name)
479495 )
480496 );
481497 }
498+
499+ // Int or $value
482500 return isset($options[$this->name][$value]) ? $options[$this->name][$value] : $value;
483501 }
502+
503+ function dispose()
504+ {
505+ $this->get_value(NULL);
506+ }
484507 }
485508
486509 class Tracker_field_select extends Tracker_field_radio
@@ -498,9 +521,7 @@ class Tracker_field_select extends Tracker_field_radio
498521 '';
499522
500523 $retval = '<select name="' . $s_name . '[]"' . $s_size . $s_multiple . '>' . "\n";
501- if ($empty){
502- $retval .= ' <option value=""></option>' . "\n";
503- }
524+ if ($empty) $retval .= ' <option value=""></option>' . "\n";
504525 $defaults = array_flip(preg_split('/\s*,\s*/', $this->default_value, -1, PREG_SPLIT_NO_EMPTY));
505526 foreach ($this->config->get($this->name) as $option) {
506527 $s_option = htmlspecialchars($option[0]);
@@ -517,7 +538,7 @@ class Tracker_field_checkbox extends Tracker_field_radio
517538 {
518539 var $sort_type = SORT_NUMERIC;
519540
520- function get_tag($empty=FALSE)
541+ function get_tag()
521542 {
522543 $retval = '';
523544
@@ -547,7 +568,7 @@ class Tracker_field_hidden extends Tracker_field_radio
547568 {
548569 var $sort_type = SORT_NUMERIC;
549570
550- function get_tag($empty=FALSE)
571+ function get_tag()
551572 {
552573 return '<input type="hidden"' .
553574 ' name="' . htmlspecialchars($this->name) . '"' .
@@ -608,7 +629,6 @@ function plugin_tracker_list_convert()
608629
609630 $config = PLUGIN_TRACKER_DEFAULT_CONFIG;
610631 $page = $refer = isset($vars['page']) ? $vars['page'] : '';
611- $field = '_page';
612632 $order = '';
613633 $list = 'list';
614634 $limit = NULL;
@@ -618,14 +638,15 @@ function plugin_tracker_list_convert()
618638 $args = func_get_args();
619639 switch (count($args)) {
620640 case 4:
621- $limit = is_numeric($args[3]) ? $args[3] : $limit;
641+ if (! is_numeric($args[3])) return PLUGIN_TRACKER_LIST_USAGE . '<br />';
642+ $limit = intval($args[3]);
622643 case 3:
623644 $order = $args[2];
624645 case 2:
625- $args[1] = get_fullname($args[1], $page);
626- $page = is_pagename($args[1]) ? $args[1] : $page;
646+ $arg = get_fullname($args[1], $page);
647+ if (is_pagename($arg)) $page = $arg;
627648 case 1:
628- $config = ($args[0] != '') ? $args[0] : $config;
649+ if ($args[0] != '') $config = $args[0];
629650 list($config, $list) = array_pad(explode('/', $config, 2), 2, $list);
630651 }
631652 }
@@ -634,7 +655,7 @@ function plugin_tracker_list_convert()
634655
635656 function plugin_tracker_list_action()
636657 {
637- global $script, $vars, $_tracker_messages;
658+ global $vars;
638659
639660 $page = $refer = isset($vars['refer']) ? $vars['refer'] : '';
640661 $config = isset($vars['config']) ? $vars['config'] : '';
@@ -643,8 +664,8 @@ function plugin_tracker_list_action()
643664
644665 $s_page = make_pagelink($page);
645666 return array(
646- 'msg' => $_tracker_messages['msg_list'],
647- 'body'=> str_replace('$1', $s_page, $_tracker_messages['msg_back']) .
667+ 'msg' => plugin_tracker_message('msg_list'),
668+ 'body'=> str_replace('$1', $s_page, plugin_tracker_message('msg_back')) .
648669 plugin_tracker_list_render($page, $refer, $config, $list, $order)
649670 );
650671 }
@@ -662,7 +683,13 @@ function plugin_tracker_list_render($page, $refer, $config_name, $list, $order_c
662683
663684 $list = & new Tracker_list($page, $refer, $config, $list);
664685 $list->sort($order_commands);
665- return $list->toString($limit);
686+ $result = $list->toString($limit);
687+ if ($result == FALSE) {
688+ $result = '#tracker_list: Pages under \'' . htmlspecialchars($page) . '/\' not found' . '<br />';
689+ }
690+ $list->dispose();
691+
692+ return $result;
666693 }
667694
668695 // Listing class
@@ -724,6 +751,11 @@ class Tracker_list
724751
725752 if (isset($done[$page])) return;
726753
754+ if ($page === NULL) {
755+ $done = array();
756+ return;
757+ }
758+
727759 $done[$page] = TRUE;
728760
729761 $source = plugin_tracker_get_source($page);
@@ -732,35 +764,38 @@ class Tracker_list
732764 $matches = array();
733765 if (! empty($source) && preg_match('/move\sto\s(.+)/', $source[0], $matches)) {
734766 $to_page = strip_bracket(trim($matches[1]));
735- if (! is_page($to_page)) {
736- return; // Invalid
767+ if (is_page($to_page)) {
768+ unset($source); // Release
769+ $this->add($to_page, $name); // Recurse(Rescan)
770+ return;
737771 } else {
738- return $this->add($to_page, $name); // Rescan
772+ return; // Invalid
739773 }
740774 }
741775
742776 // Default
743- $this->rows[$name] = array(
777+ $filetime = get_filetime($page);
778+ $row = array(
744779 '_page' => '[[' . $page . ']]',
745780 '_refer' => $this->page,
746781 '_real' => $name,
747- '_update' => get_filetime($page),
748- '_past' => get_filetime($page),
782+ '_update' => $filetime,
783+ '_past' => $filetime,
749784 '_match' => FALSE,
750785 );
751786
752787 // Redefine
753788 $matches = array();
754- $this->rows[$name]['_match'] =
755- preg_match('/' . $this->pattern . '/s', implode('', $source), $matches);
789+ $row['_match'] = preg_match('/' . $this->pattern . '/s', implode('', $source), $matches);
756790 unset($source);
757-
758- if ($this->rows[$name]['_match']) {
791+ if ($row['_match']) {
759792 array_shift($matches);
760793 foreach ($this->pattern_fields as $key => $field) {
761- $this->rows[$name][$field] = trim($matches[$key]);
794+ $row[$field] = trim($matches[$key]);
762795 }
763796 }
797+
798+ $this->rows[$name] = $row;
764799 }
765800
766801 // Sort $this->rows with $order_commands
@@ -822,10 +857,10 @@ class Tracker_list
822857 call_user_func_array('array_multisort', $params);
823858 $this->order = $orders;
824859
825- return TRUE;
860+ return TRUE;
826861 }
827862
828- // Used with preg_replace_callback() at toString()
863+ // Used with preg_replace_callback() at toString()
829864 function replace_item($arr)
830865 {
831866 $params = explode(',', $arr[1]);
@@ -852,8 +887,6 @@ class Tracker_list
852887 // Used with preg_replace_callback() at toString()
853888 function replace_title($arr)
854889 {
855- global $script;
856-
857890 $field = $sort = $arr[1];
858891 if (! isset($this->fields[$field])) return $arr[0];
859892
@@ -887,36 +920,48 @@ class Tracker_list
887920 }
888921 $r_order = rawurlencode(join(';', $_order));
889922
923+ $script = get_script_uri();
890924 return '[[' . $title . $arrow . '>' .
891925 $script . '?plugin=tracker_list&refer=' . $r_page .
892926 '&config=' . $r_config .
893927 '&list=' . $r_list . '&order=' . $r_order . ']]';
894928 }
895929
896- function toString($limit = NULL)
930+ function toString($limit = 10)
897931 {
898- global $_tracker_messages;
932+ if (empty($this->rows)) return FALSE;
933+
934+ $limit = max(1, intval($limit));
935+
936+ $count = $_count = count($this->rows);
937+ if ($limit != 0 && $count > $limit) {
938+ $rows = array_slice($this->rows, 0, $limit);
939+ $_count = count($rows);
940+ } else {
941+ $rows = $this->rows;
942+ }
899943
900944 $source = array();
901- $count = count($this->rows);
902- if ($limit !== NULL && $count > $limit) {
945+
946+ if ($count > $_count) {
947+ // Message
903948 $source[] = str_replace(
904- array('$1', '$2'),
905- array($count, $limit),
906- $_tracker_messages['msg_limit']) . "\n";
907- $this->rows = array_splice($this->rows, 0, $limit);
949+ array('$1', '$2' ),
950+ array($count, $_count),
951+ plugin_tracker_message('msg_limit')
952+ ) . "\n";
908953 }
909- if (empty($this->rows)) return '';
910954
911955 $body = array();
912956 foreach (plugin_tracker_get_source($this->config->page . '/' . $this->list) as $line) {
913- if (preg_match('/^\|(.+)\|[hHfFcC]$/', $line)) {
957+ if (preg_match('/^\|(.+)\|[hfc]$/i', $line)) {
958+ // Table decolations
914959 $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, 'replace_title'), $line);
915960 } else {
916961 $body[] = $line;
917962 }
918963 }
919- foreach ($this->rows as $row) {
964+ foreach ($rows as $row) {
920965 if (! PLUGIN_TRACKER_LIST_SHOW_ERROR_PAGE && ! $row['_match']) continue;
921966
922967 $this->items = $row;
@@ -932,6 +977,12 @@ class Tracker_list
932977
933978 return convert_html(implode('', $source));
934979 }
980+
981+ function dispose()
982+ {
983+ $this->add(NULL, NULL);
984+ return;
985+ }
935986 }
936987
937988 function plugin_tracker_get_source($page, $join = FALSE)
@@ -944,4 +995,11 @@ function plugin_tracker_get_source($page, $join = FALSE)
944995 // Remove #freeze-es
945996 return preg_replace('/^#freeze\s*$/im', '', $source);
946997 }
998+
999+function plugin_tracker_message($key)
1000+{
1001+ global $_tracker_messages;
1002+ return isset($_tracker_messages[$key]) ? $_tracker_messages[$key] : 'NOMESSAGE';
1003+}
1004+
9471005 ?>