リビジョン | 75279a82c775637ed854b799d259d4014f39497b (tree) |
---|---|
日時 | 2021-11-28 20:18:18 |
作者 | umorigu <umorigu@gmai...> |
コミッター | umorigu |
BugTrack/2525 Page-URI customize mechanism
Introduce PukiWikiStandardPageURIHandler class
* URI fragment: '?' + pagename_encode($Page)
@@ -524,20 +524,17 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE) | ||
524 | 524 | mb_regex_encoding(SOURCE_ENCODING); |
525 | 525 | $readings = get_readings($pages); |
526 | 526 | } |
527 | - | |
528 | 527 | $list = $matches = array(); |
529 | - | |
530 | - // Shrink URI for read | |
531 | - if ($cmd == 'read') { | |
532 | - $href = $script . '?'; | |
533 | - } else { | |
534 | - $href = $script . '?cmd=' . $cmd . '&page='; | |
535 | - } | |
536 | 528 | uasort($pages, 'strnatcmp'); |
537 | 529 | foreach($pages as $file=>$page) { |
538 | - $r_page = pagename_urlencode($page); | |
539 | 530 | $s_page = htmlsc($page, ENT_QUOTES); |
540 | - $str = ' <li><a href="' . $href . $r_page . '">' . | |
531 | + // Shrink URI for read | |
532 | + if ($cmd == 'read') { | |
533 | + $href = get_page_uri($page); | |
534 | + } else { | |
535 | + $href = $script . '?cmd=' . $cmd . '&page=' . rawurlencode($page); | |
536 | + } | |
537 | + $str = ' <li><a href="' . $href . '">' . | |
541 | 538 | $s_page . '</a> ' . get_pg_passage($page); |
542 | 539 | if ($withfilename) { |
543 | 540 | $s_file = htmlsc($file); |
@@ -861,11 +858,11 @@ function get_base_uri($uri_type = PKWK_URI_RELATIVE) | ||
861 | 858 | */ |
862 | 859 | function get_page_uri($page, $uri_type = PKWK_URI_RELATIVE) |
863 | 860 | { |
864 | - global $defaultpage; | |
861 | + global $defaultpage, $pkwk_page_uri_handler; | |
865 | 862 | if ($page === $defaultpage) { |
866 | 863 | return get_base_uri($uri_type); |
867 | 864 | } |
868 | - return get_base_uri($uri_type) . '?' . pagename_urlencode($page); | |
865 | + return get_base_uri($uri_type) . $pkwk_page_uri_handler->get_page_uri_fragment($page); | |
869 | 866 | } |
870 | 867 | |
871 | 868 | // Get absolute-URI of this script |
@@ -1180,6 +1177,28 @@ function get_preg_u() { | ||
1180 | 1177 | return $utf8u; |
1181 | 1178 | } |
1182 | 1179 | |
1180 | +class PukiWikiStandardPageURIHandler { | |
1181 | + function get_page_uri_fragment($page) { | |
1182 | + return '?' . pagename_urlencode($page); | |
1183 | + } | |
1184 | + | |
1185 | + function get_page_from_query_string($query_string) { | |
1186 | + $arg = $query_string; | |
1187 | + $arg = preg_replace("#^([^&]*)&.*$#", "$1", $arg); | |
1188 | + if ($arg == '') { | |
1189 | + return null; | |
1190 | + } | |
1191 | + if (strpos($arg, '=') !== false) { | |
1192 | + // Found '/?key=value' | |
1193 | + return null; | |
1194 | + } | |
1195 | + $arg = urldecode($arg); | |
1196 | + $arg = strip_bracket($arg); | |
1197 | + $arg = input_filter($arg); | |
1198 | + return $arg; | |
1199 | + } | |
1200 | +} | |
1201 | + | |
1183 | 1202 | //// Compat //// |
1184 | 1203 | |
1185 | 1204 | // is_a -- Returns TRUE if the object is of this class or has this class as one of its parents |
@@ -398,13 +398,10 @@ if (isset($get['md5']) && $get['md5'] != '' && | ||
398 | 398 | if (! isset($vars['cmd']) && ! isset($vars['plugin'])) { |
399 | 399 | |
400 | 400 | $get['cmd'] = $post['cmd'] = $vars['cmd'] = 'read'; |
401 | - | |
402 | - $arg = preg_replace("#^([^&]*)&.*$#", "$1", $arg); | |
403 | - if ($arg == '') $arg = $defaultpage; | |
404 | - if (strpos($arg, '=') !== false) $arg = $defaultpage; // Found '/?key=value' | |
405 | - $arg = urldecode($arg); | |
406 | - $arg = strip_bracket($arg); | |
407 | - $arg = input_filter($arg); | |
401 | + $arg = $pkwk_page_uri_handler->get_page_from_query_string($arg); | |
402 | + if (!$arg) { | |
403 | + $arg = $defaultpage; | |
404 | + } | |
408 | 405 | $get['page'] = $post['page'] = $vars['page'] = $arg; |
409 | 406 | } |
410 | 407 |
@@ -543,6 +543,10 @@ $logging_updates = 0; | ||
543 | 543 | $logging_updates_log_dir = '/var/log/pukiwiki'; |
544 | 544 | |
545 | 545 | ///////////////////////////////////////////////// |
546 | +// Page-URI mapping handler | |
547 | +$pkwk_page_uri_handler = new PukiWikiStandardPageURIHandler(); | |
548 | + | |
549 | +///////////////////////////////////////////////// | |
546 | 550 | // User-Agent settings |
547 | 551 | // |
548 | 552 | // If you want to ignore embedded browsers for rich-content-wikisite, |