Commit MetaInfo

修订版b851101ac5625aadc7fee98fd7e7c6e7c605e2b9 (tree)
时间2018-03-07 03:15:10
作者umorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2460 Sublist of tracker_list with range(start-last)

Now tracker_list supports range format as limit parameter.
ex: limit:"101-200" means that name numbers are (101 <= x and x <=200)

更改概述

差异

--- a/plugin/tracker.inc.php
+++ b/plugin/tracker.inc.php
@@ -602,20 +602,29 @@ class Tracker_field_past extends Tracker_field
602602 function plugin_tracker_list_convert()
603603 {
604604 global $vars, $_title_cannotread;
605-
606605 $config = 'default';
607606 $page = $refer = $vars['page'];
608607 $field = '_page';
609608 $order = '';
610609 $list = 'list';
611610 $limit = NULL;
611+ $start_n = NULL;
612+ $last_n = NULL;
612613 if (func_num_args())
613614 {
614615 $args = func_get_args();
615616 switch (count($args))
616617 {
617618 case 4:
618- $limit = is_numeric($args[3]) ? $args[3] : $limit;
619+ $range_m = null;
620+ if (is_numeric($args[3])) {
621+ $limit = $args[3];
622+ } else {
623+ if (preg_match('#^(\d+)-(\d+)$#', $args[3], $range_m)) {
624+ $start_n = intval($range_m[1]);
625+ $last_n = intval($range_m[2]);
626+ }
627+ }
619628 case 3:
620629 $order = $args[2];
621630 case 2:
@@ -630,7 +639,7 @@ function plugin_tracker_list_convert()
630639 $body = str_replace('$1', htmlsc($page), $_title_cannotread);
631640 return $body;
632641 }
633- return plugin_tracker_getlist($page,$refer,$config,$list,$order,$limit);
642+ return plugin_tracker_getlist($page,$refer,$config,$list,$order,$limit,$start_n,$last_n);
634643 }
635644 function plugin_tracker_list_action()
636645 {
@@ -655,10 +664,9 @@ function plugin_tracker_list_action()
655664 plugin_tracker_getlist($page,$refer,$config,$list,$order)
656665 );
657666 }
658-function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit=NULL)
667+function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit=NULL,$start_n=NULL,$last_n=NULL)
659668 {
660669 global $whatsdeleted;
661-
662670 $config = new Config('plugin/tracker/'.$config_name);
663671 if (!$config->read())
664672 {
@@ -670,13 +678,14 @@ function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit
670678 {
671679 return "<p>config file '".make_pagelink($config->page.'/'.$list)."' not found.</p>";
672680 }
673-
674681 $cache_enabled = defined('TRACKER_LIST_USE_CACHE') && TRACKER_LIST_USE_CACHE &&
675682 defined('JSON_UNESCAPED_UNICODE') && defined('PKWK_UTF8_ENABLE');
676- if (is_null($limit)) {
683+ if (is_null($limit) && is_null($start_n)) {
677684 $cache_filepath = CACHE_DIR . encode($page) . '.tracker';
678685 } else if (pkwk_ctype_digit($limit) && 0 < $limit && $limit <= 1000) {
679686 $cache_filepath = CACHE_DIR . encode($page) . '.' . $limit . '.tracker';
687+ } else if (!is_null($start_n) && !is_null($last_n)) {
688+ $cache_filepath = CACHE_DIR . encode($page) . '.' . $start_n . '-' . $last_n . '.tracker';
680689 } else {
681690 $cache_enabled = false;
682691 }
@@ -728,11 +737,12 @@ function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit
728737 if ($order === $cache_holder['order'] &&
729738 empty($tracker_list->newly_deleted_pages) &&
730739 empty($tracker_list->newly_updated_pages) &&
731- !$tracker_list->link_update_required) {
740+ !$tracker_list->link_update_required &&
741+ is_null($start_n) && is_null($last_n)) {
732742 $result = $cache_holder['html'];
733743 } else {
734744 $tracker_list->sort($order);
735- $result = $tracker_list->toString($limit);
745+ $result = $tracker_list->toString($limit,$start_n,$last_n);
736746 }
737747 if ($cache_enabled) {
738748 $refreshed_at = time();
@@ -1172,7 +1182,7 @@ class Tracker_list
11721182 $script = get_base_uri(PKWK_URI_ABSOLUTE);
11731183 return "[[$title$arrow>$script?plugin=tracker_list&refer=$r_page&config=$r_config&list=$r_list&order=$r_order]]";
11741184 }
1175- function toString($limit=NULL)
1185+ function toString($limit=NULL,$start_n=NULL,$last_n=NULL)
11761186 {
11771187 global $_tracker_messages;
11781188
@@ -1186,6 +1196,15 @@ class Tracker_list
11861196 array(count($this->rows),$limit),
11871197 $_tracker_messages['msg_limit'])."\n";
11881198 $this->rows = array_splice($this->rows,0,$limit);
1199+ } else if (!is_null($start_n) && !is_null($last_n)) {
1200+ // sublist (range "start-last")
1201+ $sublist = array();
1202+ foreach ($this->rows as $row) {
1203+ if ($start_n <= $row['_real'] && $row['_real'] <= $last_n) {
1204+ $sublist[] = $row;
1205+ }
1206+ }
1207+ $this->rows = $sublist;
11891208 }
11901209 if (count($this->rows) == 0)
11911210 {
Show on old repository browser