• R/O
  • HTTP
  • SSH
  • HTTPS

pukiwiki: Commit


Commit MetaInfo

Revision5afab1c5261cd0d7a57af80fe0a3d895b82f0c40 (tree)
Time2016-12-03 06:12:44
Authorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2403 bugtrack plugin - new numbering spec

* New: New page number is (largest exisging page number) + 1.
* Prev: It has local numbering logic (1 -> 51 -> 101 -> 151 -> 102,...)

Change Summary

Incremental Difference

--- a/lib/func.php
+++ b/lib/func.php
@@ -26,6 +26,23 @@ function pkwk_log($message)
2626 error_log($timestamp . ' ' . $message . "\n", 3, $log_filepath);
2727 }
2828
29+/**
30+ * ctype_digit that supports PHP4+.
31+ *
32+ * PHP official document says PHP4 has ctype_digit() function.
33+ * But sometimes it doen't exists on PHP 4.1.
34+ */
35+function pkwk_ctype_digit($s) {
36+ static $ctype_digit_exists;
37+ if (!isset($ctype_digit_exists)) {
38+ $ctype_digit_exists = function_exists('ctype_digit');
39+ }
40+ if ($ctype_digit_exists) {
41+ return ctype_digit($s);
42+ }
43+ return preg_match('/^[0-9]+$/', $s) ? true : false;
44+}
45+
2946 function is_interwiki($str)
3047 {
3148 global $InterWikiName;
--- a/plugin/bugtrack.inc.php
+++ b/plugin/bugtrack.inc.php
@@ -191,16 +191,15 @@ function plugin_bugtrack_write($base, $pagename, $summary, $name, $priority, $st
191191 $postdata = plugin_bugtrack_template($base, $summary, $name, $priority,
192192 $state, $category, $version, $body);
193193
194- $id = $jump = 1;
195- $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
196- while (is_page($page)) {
197- $id = $jump;
198- $jump += 50;
199- $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $jump);
194+ $page_list = plugin_bugtrack_get_page_list($base, false);
195+ usort($page_list, '_plugin_bugtrack_list_paganame_compare');
196+ if (count($page_list) == 0) {
197+ $id = 1;
198+ } else {
199+ $latest_page = $page_list[count($page_list) - 1]['name'];
200+ $id = intval(substr($latest_page, strlen($base) + 1)) + 1;
200201 }
201202 $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
202- while (is_page($page))
203- $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, ++$id);
204203
205204 if ($pagename == '') {
206205 page_write($page, $postdata);
@@ -255,15 +254,24 @@ function _plugin_bugtrack_list_paganame_compare($a, $b)
255254 return strnatcmp($a['name'], $b['name']);
256255 }
257256
258-function __pkwk_ctype_digit($s) {
259- static $ctype_digits_exists;
260- if (!isset($ctype_digits_exists)) {
261- $ctype_digits_exists = function_exists('ctype_digit');
262- }
263- if ($ctype_digits_exists) {
264- return ctype_digit($s);
257+
258+/**
259+ * Get page list for "$page/"
260+ */
261+function plugin_bugtrack_get_page_list($page, $needs_filetime) {
262+ $page_list = array();
263+ $pattern = $page . '/';
264+ $pattern_len = strlen($pattern);
265+ foreach (get_existpages() as $p) {
266+ if (strncmp($p, $pattern, $pattern_len) === 0 && pkwk_ctype_digit(substr($p, $pattern_len))) {
267+ if ($needs_filetime) {
268+ $page_list[] = array('name'=>$p,'filetime'=>get_filetime($p));
269+ } else {
270+ $page_list[] = array('name'=>$p);
271+ }
272+ }
265273 }
266- return preg_match('/^[0-9]+$/', $s) ? true : false;
274+ return $page_list;
267275 }
268276
269277 /**
@@ -291,14 +299,7 @@ function plugin_bugtrack_list_convert()
291299 if (is_pagename($_page)) $page = $_page;
292300 }
293301 $data = array();
294- $page_list = array();
295- $pattern = $page . '/';
296- $pattern_len = strlen($pattern);
297- foreach (get_existpages() as $p) {
298- if (strncmp($p, $pattern, $pattern_len) === 0 && __pkwk_ctype_digit(substr($p, $pattern_len))) {
299- $page_list[] = array('name'=>$p,'filetime'=>get_filetime($p));
300- }
301- }
302+ $page_list = plugin_bugtrack_get_page_list($page, true);
302303 usort($page_list, '_plugin_bugtrack_list_paganame_compare');
303304 $count_list = count($_plugin_bugtrack['state_list']);
304305 $data_map = array();
Show on old repository browser