OSDN Git Service

BugTrack/2403 bugtrack plugin - new numbering spec
authorumorigu <umorigu@gmail.com>
Fri, 2 Dec 2016 21:05:38 +0000 (06:05 +0900)
committerumorigu <umorigu@gmail.com>
Fri, 2 Dec 2016 21:12:44 +0000 (06:12 +0900)
* New: New page number is (largest exisging page number) + 1.
* Prev: It has local numbering logic (1 -> 51 -> 101 -> 151 -> 102,...)

lib/func.php
plugin/bugtrack.inc.php

index ad61c16..c1e38bc 100644 (file)
@@ -26,6 +26,23 @@ function pkwk_log($message)
        error_log($timestamp . ' ' . $message . "\n", 3, $log_filepath);
 }
 
+/**
+ * ctype_digit that supports PHP4+.
+ *
+ * PHP official document says PHP4 has ctype_digit() function.
+ * But sometimes it doen't exists on PHP 4.1.
+ */
+function pkwk_ctype_digit($s) {
+       static $ctype_digit_exists;
+       if (!isset($ctype_digit_exists)) {
+               $ctype_digit_exists = function_exists('ctype_digit');
+       }
+       if ($ctype_digit_exists) {
+               return ctype_digit($s);
+       }
+       return preg_match('/^[0-9]+$/', $s) ? true : false;
+}
+
 function is_interwiki($str)
 {
        global $InterWikiName;
index 7dc99ca..cd1ae78 100644 (file)
@@ -191,16 +191,15 @@ function plugin_bugtrack_write($base, $pagename, $summary, $name, $priority, $st
        $postdata = plugin_bugtrack_template($base, $summary, $name, $priority,
                $state, $category, $version, $body);
 
-       $id = $jump = 1;
-       $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
-       while (is_page($page)) {
-               $id   = $jump;
-               $jump += 50;
-               $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $jump);
+       $page_list = plugin_bugtrack_get_page_list($base, false);
+       usort($page_list, '_plugin_bugtrack_list_paganame_compare');
+       if (count($page_list) == 0) {
+               $id = 1;
+       } else {
+               $latest_page = $page_list[count($page_list) - 1]['name'];
+               $id = intval(substr($latest_page, strlen($base) + 1)) + 1;
        }
        $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
-       while (is_page($page))
-               $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, ++$id);
 
        if ($pagename == '') {
                page_write($page, $postdata);
@@ -255,15 +254,24 @@ function _plugin_bugtrack_list_paganame_compare($a, $b)
        return strnatcmp($a['name'], $b['name']);
 }
 
-function __pkwk_ctype_digit($s) {
-       static $ctype_digits_exists;
-       if (!isset($ctype_digits_exists)) {
-               $ctype_digits_exists = function_exists('ctype_digit');
-       }
-       if ($ctype_digits_exists) {
-               return ctype_digit($s);
+
+/**
+ * Get page list for "$page/"
+ */
+function plugin_bugtrack_get_page_list($page, $needs_filetime) {
+       $page_list = array();
+       $pattern = $page . '/';
+       $pattern_len = strlen($pattern);
+       foreach (get_existpages() as $p) {
+               if (strncmp($p, $pattern, $pattern_len) === 0 && pkwk_ctype_digit(substr($p, $pattern_len))) {
+                       if ($needs_filetime) {
+                               $page_list[] = array('name'=>$p,'filetime'=>get_filetime($p));
+                       } else {
+                               $page_list[] = array('name'=>$p);
+                       }
+               }
        }
-       return preg_match('/^[0-9]+$/', $s) ? true : false;
+       return $page_list;
 }
 
 /**
@@ -291,14 +299,7 @@ function plugin_bugtrack_list_convert()
                if (is_pagename($_page)) $page = $_page;
        }
        $data = array();
-       $page_list = array();
-       $pattern = $page . '/';
-       $pattern_len = strlen($pattern);
-       foreach (get_existpages() as $p) {
-               if (strncmp($p, $pattern, $pattern_len) === 0 && __pkwk_ctype_digit(substr($p, $pattern_len))) {
-                       $page_list[] = array('name'=>$p,'filetime'=>get_filetime($p));
-               }
-       }
+       $page_list = plugin_bugtrack_get_page_list($page, true);
        usort($page_list, '_plugin_bugtrack_list_paganame_compare');
        $count_list = count($_plugin_bugtrack['state_list']);
        $data_map = array();