Revision | e60426e07050026cd8848d92ccea0f9bb98011b1 (tree) |
---|---|
Zeit | 2015-01-13 05:54:10 |
Autor | umorigu <umorigu@gmai...> |
Commiter | umorigu |
Simplify URL. Keep slash '/' and colon (:) in page name URL
See: RFC 3986 http://www.ietf.org/rfc/rfc3986.txt - Section 3.4 Query
We don't need to percent encode for slash and colon.
@@ -265,7 +265,7 @@ function file_write($dir, $page, $str, $notimestamp = FALSE) | ||
265 | 265 | if ($notify_diff_only) $str = preg_replace('/^[^-+].*\n/m', '', $str); |
266 | 266 | $footer['ACTION'] = 'Page update'; |
267 | 267 | $footer['PAGE'] = & $page; |
268 | - $footer['URI'] = get_script_uri() . '?' . rawurlencode($page); | |
268 | + $footer['URI'] = get_script_uri() . '?' . pagename_urlencode($page); | |
269 | 269 | $footer['USER_AGENT'] = TRUE; |
270 | 270 | $footer['REMOTE_ADDR'] = TRUE; |
271 | 271 | pkwk_mail_notify($notify_subject, $str, $footer) or |
@@ -293,6 +293,16 @@ function arg_check($str) | ||
293 | 293 | return isset($vars['cmd']) && (strpos($vars['cmd'], $str) === 0); |
294 | 294 | } |
295 | 295 | |
296 | +function _pagename_urlencode_callback($matches) | |
297 | +{ | |
298 | + return rawurlencode($matches[0]); | |
299 | +} | |
300 | + | |
301 | +function pagename_urlencode($page) | |
302 | +{ | |
303 | + return preg_replace_callback('|[^/:]+|', '_pagename_urlencode_callback', $page); | |
304 | +} | |
305 | + | |
296 | 306 | // Encode page-name |
297 | 307 | function encode($str) |
298 | 308 | { |
@@ -356,7 +366,7 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE) | ||
356 | 366 | } |
357 | 367 | |
358 | 368 | foreach($pages as $file=>$page) { |
359 | - $r_page = rawurlencode($page); | |
369 | + $r_page = pagename_urlencode($page); | |
360 | 370 | $s_page = htmlsc($page, ENT_QUOTES); |
361 | 371 | $passage = get_pg_passage($page); |
362 | 372 |
@@ -32,7 +32,7 @@ function catbody($title, $page, $body) | ||
32 | 32 | if (! PKWK_ALLOW_JAVASCRIPT) unset($javascript); |
33 | 33 | |
34 | 34 | $_page = isset($vars['page']) ? $vars['page'] : ''; |
35 | - $r_page = rawurlencode($_page); | |
35 | + $r_page = pagename_urlencode($_page); | |
36 | 36 | |
37 | 37 | // Set $_LINK for skin |
38 | 38 | $_LINK['add'] = "$script?cmd=add&page=$r_page"; |
@@ -42,18 +42,18 @@ function catbody($title, $page, $body) | ||
42 | 42 | $_LINK['edit'] = "$script?cmd=edit&page=$r_page"; |
43 | 43 | $_LINK['filelist'] = "$script?cmd=filelist"; |
44 | 44 | $_LINK['freeze'] = "$script?cmd=freeze&page=$r_page"; |
45 | - $_LINK['help'] = "$script?" . rawurlencode($help_page); | |
45 | + $_LINK['help'] = "$script?" . pagename_urlencode($help_page); | |
46 | 46 | $_LINK['list'] = "$script?cmd=list"; |
47 | 47 | $_LINK['new'] = "$script?plugin=newpage&refer=$r_page"; |
48 | 48 | $_LINK['rdf'] = "$script?cmd=rss&ver=1.0"; |
49 | - $_LINK['recent'] = "$script?" . rawurlencode($whatsnew); | |
49 | + $_LINK['recent'] = "$script?" . pagename_urlencode($whatsnew); | |
50 | 50 | $_LINK['reload'] = "$script?$r_page"; |
51 | 51 | $_LINK['rename'] = "$script?plugin=rename&refer=$r_page"; |
52 | 52 | $_LINK['rss'] = "$script?cmd=rss"; |
53 | 53 | $_LINK['rss10'] = "$script?cmd=rss&ver=1.0"; // Same as 'rdf' |
54 | 54 | $_LINK['rss20'] = "$script?cmd=rss&ver=2.0"; |
55 | 55 | $_LINK['search'] = "$script?cmd=search"; |
56 | - $_LINK['top'] = "$script?" . rawurlencode($defaultpage); | |
56 | + $_LINK['top'] = "$script?" . pagename_urlencode($defaultpage); | |
57 | 57 | $_LINK['unfreeze'] = "$script?cmd=unfreeze&page=$r_page"; |
58 | 58 | $_LINK['upload'] = "$script?plugin=attach&pcmd=upload&page=$r_page"; |
59 | 59 |
@@ -307,7 +307,7 @@ EOD; | ||
307 | 307 | if (PKWK_ALLOW_RELATIVE_FOOTNOTE_ANCHOR) { |
308 | 308 | $script = ''; |
309 | 309 | } else { |
310 | - $script = get_script_uri() . '?' . rawurlencode($page); | |
310 | + $script = get_script_uri() . '?' . pagename_urlencode($page); | |
311 | 311 | } |
312 | 312 | |
313 | 313 | $id = ++$note_id; |
@@ -519,7 +519,7 @@ EOD; | ||
519 | 519 | |
520 | 520 | $url = get_interwiki_url($name, $this->param); |
521 | 521 | $this->url = ($url === FALSE) ? |
522 | - $script . '?' . rawurlencode('[[' . $name . ':' . $this->param . ']]') : | |
522 | + $script . '?' . pagename_urlencode('[[' . $name . ':' . $this->param . ']]') : | |
523 | 523 | htmlsc($url); |
524 | 524 | |
525 | 525 | return parent::setParam( |
@@ -217,7 +217,7 @@ function plugin_amazon_action() | ||
217 | 217 | $title = plugin_amazon_get_asin_title(); |
218 | 218 | if ($title == '' || preg_match('#^/#', $s_page)) { |
219 | 219 | // Invalid page name |
220 | - header('Location: ' . get_script_uri() . '?' . rawurlencode($s_page)); | |
220 | + header('Location: ' . get_script_uri() . '?' . pagename_urlencode($s_page)); | |
221 | 221 | } else { |
222 | 222 | $body = '#amazon(' . $asin_all . ',,image)' . "\n" . |
223 | 223 | '*' . $title . "\n" . $amazon_body; |
@@ -102,7 +102,7 @@ function plugin_aname_tag($args = array(), $convert = TRUE) | ||
102 | 102 | $id = htmlsc($id); // Insurance |
103 | 103 | $class = $f_super ? 'anchor_super' : 'anchor'; |
104 | 104 | $attr_id = $f_noid ? '' : ' id="' . $id . '"'; |
105 | - $url = $f_full ? get_script_uri() . '?' . rawurlencode($vars['page']) : ''; | |
105 | + $url = $f_full ? get_script_uri() . '?' . pagename_urlencode($vars['page']) : ''; | |
106 | 106 | if ($body != '') { |
107 | 107 | $href = ' href="' . $url . '#' . $id . '"'; |
108 | 108 | $title = ' title="' . $id . '"'; |
@@ -121,7 +121,7 @@ EOD; | ||
121 | 121 | $mailbody .= "\n\n" . '---' . "\n"; |
122 | 122 | $mailbody .= $_msg_article_mail_sender . $post['name'] . ' (' . $now . ')' . "\n"; |
123 | 123 | $mailbody .= $_msg_article_mail_page . $post['refer'] . "\n"; |
124 | - $mailbody .= ' URL: ' . $script . '?' . rawurlencode($post['refer']) . "\n"; | |
124 | + $mailbody .= ' URL: ' . $script . '?' . pagename_urlencode($post['refer']) . "\n"; | |
125 | 125 | $mailbody = mb_convert_encoding($mailbody, 'JIS'); |
126 | 126 | |
127 | 127 | $mailaddheader = 'From: ' . PLUGIN_ARTICLE_MAIL_FROM; |
@@ -208,7 +208,7 @@ function attach_upload($file, $page, $pass = NULL) | ||
208 | 208 | $footer['PAGE'] = & $page; |
209 | 209 | |
210 | 210 | $footer['URI'] = get_script_uri() . |
211 | - //'?' . rawurlencode($page); | |
211 | + //'?' . pagename_urlencode($page); | |
212 | 212 | |
213 | 213 | // MD5 may heavy |
214 | 214 | '?plugin=attach' . |
@@ -649,7 +649,7 @@ EOD; | ||
649 | 649 | $footer['FILENAME'] = & $this->file; |
650 | 650 | $footer['PAGE'] = & $this->page; |
651 | 651 | $footer['URI'] = get_script_uri() . |
652 | - '?' . rawurlencode($this->page); | |
652 | + '?' . pagename_urlencode($this->page); | |
653 | 653 | $footer['USER_AGENT'] = TRUE; |
654 | 654 | $footer['REMOTE_ADDR'] = TRUE; |
655 | 655 | pkwk_mail_notify($notify_subject, "\n", $footer) or |
@@ -177,7 +177,7 @@ function plugin_bugtrack_action() | ||
177 | 177 | $post['version'], $post['body']); |
178 | 178 | |
179 | 179 | pkwk_headers_sent(); |
180 | - header('Location: ' . get_script_uri() . '?' . rawurlencode($page)); | |
180 | + header('Location: ' . get_script_uri() . '?' . pagename_urlencode($page)); | |
181 | 181 | exit; |
182 | 182 | } |
183 | 183 |
@@ -105,7 +105,7 @@ EOD; | ||
105 | 105 | while (checkdate($m_num, $day, $year)) { |
106 | 106 | $dt = sprintf('%4d-%02d-%02d', $year, $m_num, $day); |
107 | 107 | $page = $prefix . $dt; |
108 | - $r_page = rawurlencode($page); | |
108 | + $r_page = pagename_urlencode($page); | |
109 | 109 | $s_page = htmlsc($page); |
110 | 110 | |
111 | 111 | if ($wday == 0 && $day > 1) |
@@ -173,7 +173,7 @@ function plugin_calendar_viewer_convert() | ||
173 | 173 | $body = str_replace('$1', $page, $_msg_calendar_viewer_restrict); |
174 | 174 | } |
175 | 175 | |
176 | - $r_page = rawurlencode($page); | |
176 | + $r_page = pagename_urlencode($page); | |
177 | 177 | |
178 | 178 | if (PLUGIN_CALENDAR_VIEWER_DATE_FORMAT !== FALSE) { |
179 | 179 | $time = strtotime(basename($page)); // $date_sep must be assumed '-' or ''! |
@@ -29,7 +29,7 @@ function plugin_diff_view($page) | ||
29 | 29 | global $_msg_notfound, $_msg_goto, $_msg_deleted, $_msg_addline, $_msg_delline, $_title_diff; |
30 | 30 | global $_title_diff_delete; |
31 | 31 | |
32 | - $r_page = rawurlencode($page); | |
32 | + $r_page = pagename_urlencode($page); | |
33 | 33 | $s_page = htmlsc($page); |
34 | 34 | |
35 | 35 | $menu = array( |
@@ -236,7 +236,7 @@ function plugin_edit_write() | ||
236 | 236 | |
237 | 237 | page_write($page, $postdata, $notimeupdate != 0 && $notimestamp); |
238 | 238 | pkwk_headers_sent(); |
239 | - header('Location: ' . get_script_uri() . '?' . rawurlencode($page)); | |
239 | + header('Location: ' . get_script_uri() . '?' . pagename_urlencode($page)); | |
240 | 240 | exit; |
241 | 241 | } |
242 | 242 |
@@ -245,7 +245,7 @@ function plugin_edit_cancel() | ||
245 | 245 | { |
246 | 246 | global $vars; |
247 | 247 | pkwk_headers_sent(); |
248 | - header('Location: ' . get_script_uri() . '?' . rawurlencode($vars['page'])); | |
248 | + header('Location: ' . get_script_uri() . '?' . pagename_urlencode($vars['page'])); | |
249 | 249 | exit; |
250 | 250 | } |
251 | 251 |
@@ -78,7 +78,7 @@ function plugin_include_convert() | ||
78 | 78 | } |
79 | 79 | |
80 | 80 | $s_page = htmlsc($page); |
81 | - $r_page = rawurlencode($page); | |
81 | + $r_page = pagename_urlencode($page); | |
82 | 82 | $link = '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>'; // Read link |
83 | 83 | |
84 | 84 | // I'm stuffed |
@@ -129,7 +129,7 @@ function plugin_navi_convert() | ||
129 | 129 | 'prev'=>$prev, 'up'=>$up) as $rel=>$_page) { |
130 | 130 | if ($_page != '') { |
131 | 131 | $s_page = htmlsc($_page); |
132 | - $r_page = rawurlencode($_page); | |
132 | + $r_page = pagename_urlencode($_page); | |
133 | 133 | $head_tags[] = ' <link rel="' . |
134 | 134 | $rel . '" href="' . $script . |
135 | 135 | '?' . $r_page . '" title="' . |
@@ -84,7 +84,7 @@ function plugin_paint_action() | ||
84 | 84 | $r_refer = $s_refer = ''; |
85 | 85 | if (array_key_exists('refer',$vars)) |
86 | 86 | { |
87 | - $r_refer = rawurlencode($vars['refer']); | |
87 | + $r_refer = pagename_urlencode($vars['refer']); | |
88 | 88 | $s_refer = htmlsc($vars['refer']); |
89 | 89 | } |
90 | 90 | $link = "<p><a href=\"$script?$r_refer\">$s_refer</a></p>";; |
@@ -58,7 +58,7 @@ function plugin_pcomment_action() | ||
58 | 58 | } |
59 | 59 | |
60 | 60 | pkwk_headers_sent(); |
61 | - header('Location: ' . get_script_uri() . '?' . rawurlencode($refer)); | |
61 | + header('Location: ' . get_script_uri() . '?' . pagename_urlencode($refer)); | |
62 | 62 | exit; |
63 | 63 | } |
64 | 64 |
@@ -29,7 +29,7 @@ function plugin_random_convert() | ||
29 | 29 | } |
30 | 30 | |
31 | 31 | return "<p><a href=\"$script?plugin=random&refer=" . |
32 | - rawurlencode($vars['page']) . '">' . | |
32 | + pagename_urlencode($vars['page']) . '">' . | |
33 | 33 | htmlsc($title) . '</a></p>'; |
34 | 34 | } |
35 | 35 |
@@ -73,7 +73,7 @@ function plugin_recent_convert() | ||
73 | 73 | // No need to link to the page you just read, or notify where you just read |
74 | 74 | $items .= ' <li>' . $s_page . '</li>' . "\n"; |
75 | 75 | } else { |
76 | - $r_page = rawurlencode($page); | |
76 | + $r_page = pagename_urlencode($page); | |
77 | 77 | $passage = $show_passage ? ' ' . get_passage($time) : ''; |
78 | 78 | $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . |
79 | 79 | ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n"; |
@@ -32,7 +32,7 @@ function plugin_related_action() | ||
32 | 32 | } |
33 | 33 | |
34 | 34 | // Result |
35 | - $r_word = rawurlencode($_page); | |
35 | + $r_word = pagename_urlencode($_page); | |
36 | 36 | $s_word = htmlsc($_page); |
37 | 37 | $msg = 'Backlinks for: ' . $s_word; |
38 | 38 | $retval = '<a href="' . $script . '?' . $r_word . '">' . |
@@ -45,7 +45,7 @@ function plugin_related_action() | ||
45 | 45 | ksort($data, SORT_STRING); |
46 | 46 | $retval .= '<ul>' . "\n"; |
47 | 47 | foreach ($data as $page=>$time) { |
48 | - $r_page = rawurlencode($page); | |
48 | + $r_page = pagename_urlencode($page); | |
49 | 49 | $s_page = htmlsc($page); |
50 | 50 | $passage = get_passage($time); |
51 | 51 | $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page . |
@@ -383,7 +383,7 @@ function plugin_rename_proceed($pages, $files, $exists) | ||
383 | 383 | if ($page == '') $page = PLUGIN_RENAME_LOGPAGE; |
384 | 384 | |
385 | 385 | pkwk_headers_sent(); |
386 | - header('Location: ' . get_script_uri() . '?' . rawurlencode($page)); | |
386 | + header('Location: ' . get_script_uri() . '?' . pagename_urlencode($page)); | |
387 | 387 | exit; |
388 | 388 | } |
389 | 389 |
@@ -38,7 +38,7 @@ function plugin_rss_action() | ||
38 | 38 | |
39 | 39 | foreach (file_head($recent, $rss_max) as $line) { |
40 | 40 | list($time, $page) = explode("\t", rtrim($line)); |
41 | - $r_page = rawurlencode($page); | |
41 | + $r_page = pagename_urlencode($page); | |
42 | 42 | $title = mb_convert_encoding($page, 'UTF-8', SOURCE_ENCODING); |
43 | 43 | |
44 | 44 | switch ($version) { |
@@ -82,7 +82,7 @@ EOD; | ||
82 | 82 | header('Content-type: application/xml'); |
83 | 83 | print '<?xml version="1.0" encoding="UTF-8"?>' . "\n\n"; |
84 | 84 | |
85 | - $r_whatsnew = rawurlencode($whatsnew); | |
85 | + $r_whatsnew = pagename_urlencode($whatsnew); | |
86 | 86 | switch ($version) { |
87 | 87 | case '0.91': |
88 | 88 | print '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"' . |
@@ -49,7 +49,7 @@ function plugin_topicpath_inline() | ||
49 | 49 | $topic_path = array(); |
50 | 50 | while (! empty($parts)) { |
51 | 51 | $_landing = join('/', $parts); |
52 | - $landing = rawurlencode($_landing); | |
52 | + $landing = pagename_urlencode($_landing); | |
53 | 53 | $element = htmlsc(array_pop($parts)); |
54 | 54 | if (! $b_link) { |
55 | 55 | // This page ($_landing == $page) |
@@ -174,7 +174,7 @@ function plugin_tracker_action() | ||
174 | 174 | // Writing page data, without touch |
175 | 175 | page_write($page, join('', $postdata)); |
176 | 176 | |
177 | - $r_page = rawurlencode($page); | |
177 | + $r_page = pagename_urlencode($page); | |
178 | 178 | |
179 | 179 | pkwk_headers_sent(); |
180 | 180 | header('Location: ' . get_script_uri() . '?' . $r_page); |
@@ -42,7 +42,7 @@ function plugin_yetlist_action() | ||
42 | 42 | $r_refer = ''; |
43 | 43 | $link_refs = array(); |
44 | 44 | foreach ($refer as $_refer) { |
45 | - $r_refer = rawurlencode($_refer); | |
45 | + $r_refer = pagename_urlencode($_refer); | |
46 | 46 | $link_refs[] = '<a href="' . $script . '?' . $r_refer . '">' . |
47 | 47 | htmlsc($_refer) . '</a>'; |
48 | 48 | } |
@@ -59,7 +59,7 @@ if ($rw) { | ||
59 | 59 | } |
60 | 60 | } |
61 | 61 | } |
62 | -$navi[] = '<a href="' . $script . '?' . rawurlencode($menubar) . '" ' . $accesskey . '="4">4.Menu</a>'; | |
62 | +$navi[] = '<a href="' . $script . '?' . pagename_urlencode($menubar) . '" ' . $accesskey . '="4">4.Menu</a>'; | |
63 | 63 | $navi[] = '<a href="' . $link['recent'] . '" ' . $accesskey . '="5">5.Recent</a>'; |
64 | 64 | |
65 | 65 | // Previous / Next block |