OSDN Git Service

BugTrack/2525 Page-URI customize mechanism
authorumorigu <umorigu@gmail.com>
Sun, 28 Nov 2021 11:18:18 +0000 (20:18 +0900)
committerumorigu <umorigu@gmail.com>
Sun, 28 Nov 2021 11:18:18 +0000 (20:18 +0900)
Introduce PukiWikiStandardPageURIHandler class

* URI fragment: '?' + pagename_encode($Page)

lib/func.php
lib/init.php
pukiwiki.ini.php

index 22c7c75..8c01c9b 100644 (file)
@@ -524,20 +524,17 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
                mb_regex_encoding(SOURCE_ENCODING);
                $readings = get_readings($pages);
        }
-
        $list = $matches = array();
-
-       // Shrink URI for read
-       if ($cmd == 'read') {
-               $href = $script . '?';
-       } else {
-               $href = $script . '?cmd=' . $cmd . '&amp;page=';
-       }
        uasort($pages, 'strnatcmp');
        foreach($pages as $file=>$page) {
-               $r_page  = pagename_urlencode($page);
                $s_page  = htmlsc($page, ENT_QUOTES);
-               $str = '   <li><a href="' . $href . $r_page . '">' .
+               // Shrink URI for read
+               if ($cmd == 'read') {
+                       $href = get_page_uri($page);
+               } else {
+                       $href = $script . '?cmd=' . $cmd . '&amp;page=' . rawurlencode($page);
+               }
+               $str = '   <li><a href="' . $href . '">' .
                        $s_page . '</a> ' . get_pg_passage($page);
                if ($withfilename) {
                        $s_file = htmlsc($file);
@@ -861,11 +858,11 @@ function get_base_uri($uri_type = PKWK_URI_RELATIVE)
  */
 function get_page_uri($page, $uri_type = PKWK_URI_RELATIVE)
 {
-       global $defaultpage;
+       global $defaultpage, $pkwk_page_uri_handler;
        if ($page === $defaultpage) {
                return get_base_uri($uri_type);
        }
-       return get_base_uri($uri_type) . '?' . pagename_urlencode($page);
+       return get_base_uri($uri_type) . $pkwk_page_uri_handler->get_page_uri_fragment($page);
 }
 
 // Get absolute-URI of this script
@@ -1180,6 +1177,28 @@ function get_preg_u() {
        return $utf8u;
 }
 
+class PukiWikiStandardPageURIHandler {
+       function get_page_uri_fragment($page) {
+               return '?' . pagename_urlencode($page);
+       }
+
+       function get_page_from_query_string($query_string) {
+               $arg = $query_string;
+               $arg = preg_replace("#^([^&]*)&.*$#", "$1", $arg);
+               if ($arg == '') {
+                       return null;
+               }
+               if (strpos($arg, '=') !== false) {
+                       // Found '/?key=value'
+                       return null;
+               }
+               $arg = urldecode($arg);
+               $arg = strip_bracket($arg);
+               $arg = input_filter($arg);
+               return $arg;
+       }
+}
+
 //// Compat ////
 
 // is_a --  Returns TRUE if the object is of this class or has this class as one of its parents
index da56c41..859b36b 100644 (file)
@@ -398,13 +398,10 @@ if (isset($get['md5']) && $get['md5'] != '' &&
 if (! isset($vars['cmd']) && ! isset($vars['plugin'])) {
 
        $get['cmd']  = $post['cmd']  = $vars['cmd']  = 'read';
-
-       $arg = preg_replace("#^([^&]*)&.*$#", "$1", $arg);
-       if ($arg == '') $arg = $defaultpage;
-       if (strpos($arg, '=') !== false) $arg = $defaultpage; // Found '/?key=value'
-       $arg = urldecode($arg);
-       $arg = strip_bracket($arg);
-       $arg = input_filter($arg);
+       $arg = $pkwk_page_uri_handler->get_page_from_query_string($arg);
+       if (!$arg) {
+               $arg = $defaultpage;
+       }
        $get['page'] = $post['page'] = $vars['page'] = $arg;
 }
 
index a602248..7942eb2 100644 (file)
@@ -543,6 +543,10 @@ $logging_updates = 0;
 $logging_updates_log_dir = '/var/log/pukiwiki';
 
 /////////////////////////////////////////////////
+// Page-URI mapping handler
+$pkwk_page_uri_handler = new PukiWikiStandardPageURIHandler();
+
+/////////////////////////////////////////////////
 // User-Agent settings
 //
 // If you want to ignore embedded browsers for rich-content-wikisite,