• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

Commit MetaInfo

修訂859194b577b129f55c5ece61e36a5c09579ac141 (tree)
時間2007-10-13 01:00:27
作者henoheno <henoheno>
Commiterhenoheno

Log Message

Simplify:
* Tracker_form: Sort functions as functional order
* Tracker_list: $this->list seems to be just one of private resources of toString(). Speaking words of wisdom: let it be.

Change Summary

差異

--- a/plugin/tracker.inc.php
+++ b/plugin/tracker.inc.php
@@ -1,6 +1,6 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone
3-// $Id: tracker.inc.php,v 1.107 2007/10/08 14:44:56 henoheno Exp $
3+// $Id: tracker.inc.php,v 1.108 2007/10/12 16:00:27 henoheno Exp $
44 // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team
55 // License: GPL v2 or (at your option) any later version
66 //
@@ -249,33 +249,8 @@ class Tracker_form
249249 $this->config = & $config;
250250 }
251251
252- function addField($fieldname, $displayname, $type = 'text', $options = '20', $default = '')
253- {
254- if (isset($this->fields[$fieldname])) {
255- $this->error = "No such field: " . $fieldname;
256- return FALSE;
257- }
258-
259- $class = 'Tracker_field_' . $type;
260- if (! class_exists($class)) {
261- $this->error = "No such type: " . $type;
262- return FALSE;
263- }
264-
265- $this->fields[$fieldname] = & new $class(
266- $this, // Reference
267- array(
268- $fieldname,
269- $displayname,
270- NULL, // $type
271- $options,
272- $default
273- )
274- );
275-
276- return TRUE;
277- }
278-
252+ // Init $this->raw_fields and $this->fields
253+ // TODO: Using func_get_args() to shrink the code?
279254 function initFields($requests = NULL)
280255 {
281256 if (! isset($this->raw_fields)) {
@@ -362,6 +337,35 @@ class Tracker_form
362337
363338 $this->initFields($fields);
364339 }
340+
341+ // Called from InitFields()
342+ function addField($fieldname, $displayname, $type = 'text', $options = '20', $default = '')
343+ {
344+ // Not Init
345+ if (isset($this->fields[$fieldname])) {
346+ $this->error = "No such field: " . $fieldname;
347+ return FALSE;
348+ }
349+
350+ $class = 'Tracker_field_' . $type;
351+ if (! class_exists($class)) {
352+ $this->error = "No such type: " . $type;
353+ return FALSE;
354+ }
355+
356+ $this->fields[$fieldname] = & new $class(
357+ $this, // Reference
358+ array(
359+ $fieldname,
360+ $displayname,
361+ NULL, // $type
362+ $options,
363+ $default
364+ )
365+ );
366+
367+ return TRUE;
368+ }
365369 }
366370
367371 // TODO: Why a filter sometimes created so many?
@@ -870,15 +874,15 @@ function plugin_tracker_list_render($base, $refer, $config_name, $list, $order_c
870874 return '#tracker_list: List not found: ' . make_pagelink($config->page . '/' . $list) . '<br />';
871875 }
872876
873- $list = & new Tracker_list($base, $refer, $config, $list);
874- if ($list->setSortOrder($order_commands) === FALSE) {
877+ $tracker_list = & new Tracker_list($base, $refer, $config);
878+ if ($tracker_list->setSortOrder($order_commands) === FALSE) {
875879 return '#tracker_list: ' . htmlspecialchars($list->error) . '<br />';
876880 }
877- $result = $list->toString($limit);
881+ $result = $tracker_list->toString($list, $limit);
878882 if ($result === FALSE) {
879883 return '#tracker_list: ' . htmlspecialchars($list->error) . '<br />';
880884 }
881- unset($list);
885+ unset($tracker_list);
882886
883887 return convert_html($result);
884888 }
@@ -888,29 +892,28 @@ class Tracker_list
888892 {
889893 var $form; // class Tracker_form
890894
891- var $list;
892-
893- var $pattern;
894- var $pattern_fields;
895-
896895 var $rows = array();
897896 var $orders = array();
898897 var $error = ''; // Error message
899898
899+ // _generate_regex()
900+ var $pattern;
901+ var $pattern_fields;
902+
900903 // add()
901904 var $_added = array();
902905
903906 // toString()
907+ var $_list;
904908 var $_row;
905909 var $_the_first_character_of_the_line;
906910
907- function Tracker_list($base, $refer, & $config, $list)
911+ function Tracker_list($base, $refer, & $config)
908912 {
909- $form = & new Tracker_form($base, $refer, $config);
910- $this->form = $form;
911- $this->list = $list;
913+ $this->form = & new Tracker_form($base, $refer, $config);
912914 }
913915
916+ // Adding $this->rows
914917 // Add multiple pages at a time
915918 function loadRows()
916919 {
@@ -918,7 +921,6 @@ class Tracker_list
918921 $len = strlen($base);
919922 $regex = '#^' . preg_quote($base, '#') . '#';
920923
921- // Adding $this->rows
922924 foreach (preg_grep($regex, array_values(get_existpages())) as $pagename) {
923925 if (preg_match(PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN, substr($pagename, $len))) {
924926 continue;
@@ -1195,8 +1197,8 @@ class Tracker_list
11951197 $fields = $form->fields;
11961198 $config_name = $form->config->config_name;
11971199
1198- $list = $this->list;
11991200 $orders = $this->orders;
1201+ $list = $this->_list;
12001202
12011203 $fieldname = isset($matches[1]) ? $matches[1] : '';
12021204 if (! isset($fields[$fieldname])) {
@@ -1294,10 +1296,11 @@ class Tracker_list
12941296 }
12951297
12961298 // Output a part of Wiki text
1297- function toString($limit = 0)
1299+ function toString($list, $limit = 0)
12981300 {
12991301 $form = & $this->form;
1300- $list = $form->config->page . '/' . $this->list;
1302+ $list = $form->config->page . '/' . $list;
1303+
13011304 $source = array();
13021305 $regex = '/\[([^\[\]]+)\]/';
13031306
@@ -1308,22 +1311,26 @@ class Tracker_list
13081311 return FALSE;
13091312 }
13101313
1311- // Creating $form->fields just you need
1312- if ($form->initFields('_real') === FALSE ||
1314+ // Try to create $form->fields just you need
1315+ if ($form->initFields('_real') === FALSE ||
13131316 $form->initFields(plugin_tracker_field_pickup($template)) === FALSE ||
13141317 $form->initFields(array_keys($this->orders)) === FALSE) {
13151318 $this->error = $form->error;
13161319 return FALSE;
13171320 }
13181321
1322+ // TODO: Check isset($this->rows) or something
13191323 // Generate regex for $form->fields
13201324 if ($this->_generate_regex() === FALSE) return FALSE;
13211325
1326+ // TODO: Check isset($this->rows) or something
13221327 // Load and sort $this->rows
13231328 if ($this->loadRows() === FALSE || $this->sortRows() === FALSE) return FALSE;
13241329 $rows = $this->rows;
13251330
1331+
13261332 // toString()
1333+ $this->_list = $list; // For _replace_title() only
13271334 $count = count($this->rows);
13281335 $limit = intval($limit);
13291336 if ($limit != 0) $limit = max(1, $limit);