OSDN Git Service

BugTrack2/361 Simplify URL. Keep slash / and colon : in page name URL
authorumorigu <umorigu@gmail.com>
Mon, 12 Jan 2015 20:54:10 +0000 (05:54 +0900)
committerumorigu <umorigu@gmail.com>
Mon, 12 Jan 2015 20:54:10 +0000 (05:54 +0900)
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.

26 files changed:
lib/file.php
lib/func.php
lib/html.php
lib/make_link.php
plugin/amazon.inc.php
plugin/aname.inc.php
plugin/article.inc.php
plugin/attach.inc.php
plugin/bugtrack.inc.php
plugin/calendar2.inc.php
plugin/calendar_viewer.inc.php
plugin/diff.inc.php
plugin/edit.inc.php
plugin/include.inc.php
plugin/navi.inc.php
plugin/paint.inc.php
plugin/pcomment.inc.php
plugin/random.inc.php
plugin/recent.inc.php
plugin/related.inc.php
plugin/rename.inc.php
plugin/rss.inc.php
plugin/topicpath.inc.php
plugin/tracker.inc.php
plugin/yetlist.inc.php
skin/keitai.skin.php

index 979cb5c..03c872d 100644 (file)
@@ -265,7 +265,7 @@ function file_write($dir, $page, $str, $notimestamp = FALSE)
                if ($notify_diff_only) $str = preg_replace('/^[^-+].*\n/m', '', $str);
                $footer['ACTION'] = 'Page update';
                $footer['PAGE']   = & $page;
-               $footer['URI']    = get_script_uri() . '?' . rawurlencode($page);
+               $footer['URI']    = get_script_uri() . '?' . pagename_urlencode($page);
                $footer['USER_AGENT']  = TRUE;
                $footer['REMOTE_ADDR'] = TRUE;
                pkwk_mail_notify($notify_subject, $str, $footer) or
@@ -800,4 +800,4 @@ function pkwk_touch_file($filename, $time = FALSE, $atime = FALSE)
                        htmlsc(basename($filename)));
        }
 }
-?>
+
index 5638174..217c29e 100644 (file)
@@ -293,6 +293,16 @@ function arg_check($str)
        return isset($vars['cmd']) && (strpos($vars['cmd'], $str) === 0);
 }
 
+function _pagename_urlencode_callback($matches)
+{
+       return rawurlencode($matches[0]);
+}
+
+function pagename_urlencode($page)
+{
+       return preg_replace_callback('|[^/:]+|', '_pagename_urlencode_callback', $page);
+}
+
 // Encode page-name
 function encode($str)
 {
@@ -356,7 +366,7 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
        }
 
        foreach($pages as $file=>$page) {
-               $r_page  = rawurlencode($page);
+               $r_page  = pagename_urlencode($page);
                $s_page  = htmlsc($page, ENT_QUOTES);
                $passage = get_pg_passage($page);
 
@@ -774,4 +784,4 @@ if (! function_exists('sha1')) {
                }
        }
 }
-?>
+
index 46420c6..f41e97a 100644 (file)
@@ -32,7 +32,7 @@ function catbody($title, $page, $body)
        if (! PKWK_ALLOW_JAVASCRIPT) unset($javascript);
 
        $_page  = isset($vars['page']) ? $vars['page'] : '';
-       $r_page = rawurlencode($_page);
+       $r_page = pagename_urlencode($_page);
 
        // Set $_LINK for skin
        $_LINK['add']      = "$script?cmd=add&amp;page=$r_page";
@@ -42,18 +42,18 @@ function catbody($title, $page, $body)
        $_LINK['edit']     = "$script?cmd=edit&amp;page=$r_page";
        $_LINK['filelist'] = "$script?cmd=filelist";
        $_LINK['freeze']   = "$script?cmd=freeze&amp;page=$r_page";
-       $_LINK['help']     = "$script?" . rawurlencode($help_page);
+       $_LINK['help']     = "$script?" . pagename_urlencode($help_page);
        $_LINK['list']     = "$script?cmd=list";
        $_LINK['new']      = "$script?plugin=newpage&amp;refer=$r_page";
        $_LINK['rdf']      = "$script?cmd=rss&amp;ver=1.0";
-       $_LINK['recent']   = "$script?" . rawurlencode($whatsnew);
+       $_LINK['recent']   = "$script?" . pagename_urlencode($whatsnew);
        $_LINK['reload']   = "$script?$r_page";
        $_LINK['rename']   = "$script?plugin=rename&amp;refer=$r_page";
        $_LINK['rss']      = "$script?cmd=rss";
        $_LINK['rss10']    = "$script?cmd=rss&amp;ver=1.0"; // Same as 'rdf'
        $_LINK['rss20']    = "$script?cmd=rss&amp;ver=2.0";
        $_LINK['search']   = "$script?cmd=search";
-       $_LINK['top']      = "$script?" . rawurlencode($defaultpage);
+       $_LINK['top']      = "$script?" . pagename_urlencode($defaultpage);
        $_LINK['unfreeze'] = "$script?cmd=unfreeze&amp;page=$r_page";
        $_LINK['upload']   = "$script?plugin=attach&amp;pcmd=upload&amp;page=$r_page";
 
@@ -285,7 +285,7 @@ function make_related($page, $tag = '')
        foreach ($links as $page=>$lastmod) {
                if (check_non_list($page)) continue;
 
-               $r_page   = rawurlencode($page);
+               $r_page   = pagename_urlencode($page);
                $s_page   = htmlsc($page);
                $passage  = get_passage($lastmod);
                $_links[] = $tag ?
@@ -535,4 +535,4 @@ function pkwk_output_dtd($pkwk_dtd = PKWK_DTD_XHTML_1_1, $charset = CONTENT_CHAR
                return '<meta http-equiv="content-type" content="text/html; charset=' . $charset . '" />' . "\n";
        }
 }
-?>
+
index df7048e..39040af 100644 (file)
@@ -307,7 +307,7 @@ EOD;
                if (PKWK_ALLOW_RELATIVE_FOOTNOTE_ANCHOR) {
                        $script = '';
                } else {
-                       $script = get_script_uri() . '?' . rawurlencode($page);
+                       $script = get_script_uri() . '?' . pagename_urlencode($page);
                }
 
                $id   = ++$note_id;
@@ -519,7 +519,7 @@ EOD;
 
                $url = get_interwiki_url($name, $this->param);
                $this->url = ($url === FALSE) ?
-                       $script . '?' . rawurlencode('[[' . $name . ':' . $this->param . ']]') :
+                       $script . '?' . pagename_urlencode('[[' . $name . ':' . $this->param . ']]') :
                        htmlsc($url);
 
                return parent::setParam(
@@ -713,7 +713,7 @@ function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolin
 
        if ($page == '') return '<a href="' . $anchor . '">' . $s_alias . '</a>';
 
-       $r_page  = rawurlencode($page);
+       $r_page  = pagename_urlencode($page);
        $r_refer = ($refer == '') ? '' : '&amp;refer=' . rawurlencode($refer);
 
        if (! isset($related[$page]) && $page !== $vars['page'] && is_page($page))
@@ -851,4 +851,4 @@ function get_interwiki_url($name, $param)
 
        return $url;
 }
-?>
+
index 028340c..3e2d2d7 100644 (file)
@@ -217,7 +217,7 @@ function plugin_amazon_action()
                        $title = plugin_amazon_get_asin_title();
                        if ($title == '' || preg_match('#^/#', $s_page)) {
                                // Invalid page name
-                               header('Location: ' . get_script_uri() . '?' . rawurlencode($s_page));
+                               header('Location: ' . get_script_uri() . '?' . pagename_urlencode($s_page));
                        } else {
                                $body = '#amazon(' . $asin_all . ',,image)' . "\n" .
                                        '*' . $title . "\n" . $amazon_body;
@@ -461,4 +461,4 @@ function is_asin()
                return TRUE;
        }
 }
-?>
+
index 0aa4394..3d62f37 100644 (file)
@@ -102,7 +102,7 @@ function plugin_aname_tag($args = array(), $convert = TRUE)
        $id = htmlsc($id); // Insurance
        $class   = $f_super ? 'anchor_super' : 'anchor';
        $attr_id = $f_noid  ? '' : ' id="' . $id . '"';
-       $url     = $f_full  ? get_script_uri() . '?' . rawurlencode($vars['page']) : '';
+       $url     = $f_full  ? get_script_uri() . '?' . pagename_urlencode($vars['page']) : '';
        if ($body != '') {
                $href  = ' href="' . $url . '#' . $id . '"';
                $title = ' title="' . $id . '"';
@@ -113,4 +113,4 @@ function plugin_aname_tag($args = array(), $convert = TRUE)
        return '<a class="' . $class . '"' . $attr_id . $href . $title . '>' .
                $body . '</a>';
 }
-?>
+
index 6e286a7..bfcdb22 100644 (file)
@@ -121,7 +121,7 @@ EOD;
                        $mailbody .= "\n\n" . '---' . "\n";
                        $mailbody .= $_msg_article_mail_sender . $post['name'] . ' (' . $now . ')' . "\n";
                        $mailbody .= $_msg_article_mail_page . $post['refer'] . "\n";
-                       $mailbody .= '  URL: ' . $script . '?' . rawurlencode($post['refer']) . "\n";
+                       $mailbody .= '   URL: ' . $script . '?' . pagename_urlencode($post['refer']) . "\n";
                        $mailbody = mb_convert_encoding($mailbody, 'JIS');
 
                        $mailaddheader = 'From: ' . PLUGIN_ARTICLE_MAIL_FROM;
@@ -177,4 +177,4 @@ EOD;
 
        return $string;
 }
-?>
+
index 6ec2eb0..a40899b 100644 (file)
@@ -208,7 +208,7 @@ function attach_upload($file, $page, $pass = NULL)
                $footer['PAGE']     = & $page;
 
                $footer['URI']      = get_script_uri() .
-                       //'?' . rawurlencode($page);
+                       //'?' . pagename_urlencode($page);
 
                        // MD5 may heavy
                        '?plugin=attach' .
@@ -649,7 +649,7 @@ EOD;
                        $footer['FILENAME'] = & $this->file;
                        $footer['PAGE']     = & $this->page;
                        $footer['URI']      = get_script_uri() .
-                               '?' . rawurlencode($this->page);
+                               '?' . pagename_urlencode($this->page);
                        $footer['USER_AGENT']  = TRUE;
                        $footer['REMOTE_ADDR'] = TRUE;
                        pkwk_mail_notify($notify_subject, "\n", $footer) or
@@ -853,4 +853,4 @@ class AttachPages
                return "\n" . '<ul>' . "\n" . $ret . '</ul>' . "\n";
        }
 }
-?>
+
index 5451813..62679f7 100644 (file)
@@ -177,7 +177,7 @@ function plugin_bugtrack_action()
                $post['version'], $post['body']);
 
        pkwk_headers_sent();
-       header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
+       header('Location: ' . get_script_uri() . '?' . pagename_urlencode($page));
        exit;
 }
 
@@ -351,4 +351,4 @@ function plugin_bugtrack_list_pageinfo($page, $no = NULL, $recurse = TRUE)
 
        return array($page, $no, $summary, $name, $priority, $state, $category);
 }
-?>
+
index d89958c..c566361 100644 (file)
@@ -105,7 +105,7 @@ EOD;
        while (checkdate($m_num, $day, $year)) {
                $dt     = sprintf('%4d-%02d-%02d', $year, $m_num, $day);
                $page   = $prefix . $dt;
-               $r_page = rawurlencode($page);
+               $r_page = pagename_urlencode($page);
                $s_page = htmlsc($page);
 
                if ($wday == 0 && $day > 1)
@@ -197,4 +197,4 @@ function plugin_calendar2_action()
 
        return $ret;
 }
-?>
+
index 3b82823..fe91002 100644 (file)
@@ -173,7 +173,7 @@ function plugin_calendar_viewer_convert()
                        $body = str_replace('$1', $page, $_msg_calendar_viewer_restrict);
                }
 
-               $r_page = rawurlencode($page);
+               $r_page = pagename_urlencode($page);
 
                if (PLUGIN_CALENDAR_VIEWER_DATE_FORMAT !== FALSE) {
                        $time = strtotime(basename($page)); // $date_sep must be assumed '-' or ''!
@@ -330,4 +330,4 @@ function plugin_calendar_viewer_isValidDate($aStr, $aSepList = '-/ .')
                return FALSE;
        }
 }
-?>
+
index 577756f..c9fd509 100644 (file)
@@ -29,7 +29,7 @@ function plugin_diff_view($page)
        global $_msg_notfound, $_msg_goto, $_msg_deleted, $_msg_addline, $_msg_delline, $_title_diff;
        global $_title_diff_delete;
 
-       $r_page = rawurlencode($page);
+       $r_page = pagename_urlencode($page);
        $s_page = htmlsc($page);
 
        $menu = array(
@@ -110,4 +110,4 @@ EOD;
 
        return array('msg'=>$_title_diff_delete, 'body'=>$body);
 }
-?>
+
index a35df73..07a473e 100644 (file)
@@ -236,7 +236,7 @@ function plugin_edit_write()
 
        page_write($page, $postdata, $notimeupdate != 0 && $notimestamp);
        pkwk_headers_sent();
-       header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
+       header('Location: ' . get_script_uri() . '?' . pagename_urlencode($page));
        exit;
 }
 
@@ -245,8 +245,7 @@ function plugin_edit_cancel()
 {
        global $vars;
        pkwk_headers_sent();
-       header('Location: ' . get_script_uri() . '?' . rawurlencode($vars['page']));
+       header('Location: ' . get_script_uri() . '?' . pagename_urlencode($vars['page']));
        exit;
 }
 
-?>
index d8cc731..b8b08f2 100644 (file)
@@ -78,7 +78,7 @@ function plugin_include_convert()
        }
 
        $s_page = htmlsc($page);
-       $r_page = rawurlencode($page);
+       $r_page = pagename_urlencode($page);
        $link = '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>'; // Read link
 
        // I'm stuffed
@@ -118,4 +118,4 @@ function plugin_include_convert()
 
        return $body;
 }
-?>
+
index 36a9dbb..57a2ae0 100644 (file)
@@ -129,7 +129,7 @@ function plugin_navi_convert()
                            'prev'=>$prev, 'up'=>$up) as $rel=>$_page) {
                                if ($_page != '') {
                                        $s_page = htmlsc($_page);
-                                       $r_page = rawurlencode($_page);
+                                       $r_page = pagename_urlencode($_page);
                                        $head_tags[] = ' <link rel="' .
                                                $rel . '" href="' . $script .
                                                '?' . $r_page . '" title="' .
@@ -183,4 +183,4 @@ EOD;
        }
        return $ret;
 }
-?>
+
index d72af35..5b96786 100644 (file)
@@ -84,7 +84,7 @@ function plugin_paint_action()
                $r_refer = $s_refer = '';
                if (array_key_exists('refer',$vars))
                {
-                       $r_refer = rawurlencode($vars['refer']);
+                       $r_refer = pagename_urlencode($vars['refer']);
                        $s_refer = htmlsc($vars['refer']);
                }
                $link = "<p><a href=\"$script?$r_refer\">$s_refer</a></p>";;
@@ -266,4 +266,4 @@ function paint_insert_ref($filename)
 
        return $ret;
 }
-?>
+
index 42d6303..036a14f 100644 (file)
@@ -58,7 +58,7 @@ function plugin_pcomment_action()
        }
 
        pkwk_headers_sent();
-       header('Location: ' . get_script_uri() . '?' . rawurlencode($refer));
+       header('Location: ' . get_script_uri() . '?' . pagename_urlencode($refer));
        exit;
 }
 
@@ -368,4 +368,4 @@ function plugin_pcomment_get_comments($page, $count, $dir, $reply)
 
        return array($comments, $digest);
 }
-?>
+
index 58c153e..899d12c 100644 (file)
@@ -29,7 +29,7 @@ function plugin_random_convert()
        }
 
        return "<p><a href=\"$script?plugin=random&amp;refer=" .
-               rawurlencode($vars['page']) . '">' .
+               pagename_urlencode($vars['page']) . '">' .
                htmlsc($title) . '</a></p>';
 }
 
@@ -51,4 +51,4 @@ function plugin_random_action()
 
        return array('body'=>'','msg'=>'');
 }
-?>
+
index 3f0c991..5936879 100644 (file)
@@ -77,7 +77,7 @@ function plugin_recent_convert()
                        // No need to link to the page you just read, or notify where you just read
                        $items .= ' <li>' . $s_page . '</li>' . "\n";
                } else {
-                       $r_page = rawurlencode($page);
+                       $r_page = pagename_urlencode($page);
                        $passage = $show_passage ? ' ' . get_passage($time) : '';
                        $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . 
                                ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
@@ -88,4 +88,4 @@ function plugin_recent_convert()
 
        return sprintf($_recent_plugin_frame, count($lines), $items);
 }
-?>
+
index 66cd03d..9b56ca4 100644 (file)
@@ -32,7 +32,7 @@ function plugin_related_action()
        }
 
        // Result
-       $r_word = rawurlencode($_page);
+       $r_word = pagename_urlencode($_page);
        $s_word = htmlsc($_page);
        $msg = 'Backlinks for: ' . $s_word;
        $retval  = '<a href="' . $script . '?' . $r_word . '">' .
@@ -45,7 +45,7 @@ function plugin_related_action()
                ksort($data, SORT_STRING);
                $retval .= '<ul>' . "\n";
                foreach ($data as $page=>$time) {
-                       $r_page  = rawurlencode($page);
+                       $r_page  = pagename_urlencode($page);
                        $s_page  = htmlsc($page);
                        $passage = get_passage($time);
                        $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page .
@@ -55,4 +55,4 @@ function plugin_related_action()
        }
        return array('msg'=>$msg, 'body'=>$retval);
 }
-?>
+
index 867f0a7..857957a 100644 (file)
@@ -383,7 +383,7 @@ function plugin_rename_proceed($pages, $files, $exists)
        if ($page == '') $page = PLUGIN_RENAME_LOGPAGE;
 
        pkwk_headers_sent();
-       header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
+       header('Location: ' . get_script_uri() . '?' . pagename_urlencode($page));
        exit;
 }
 
@@ -423,4 +423,4 @@ function plugin_rename_getselecttag($page)
 EOD;
 
 }
-?>
+
index e78f03d..19faf42 100644 (file)
@@ -38,7 +38,7 @@ function plugin_rss_action()
 
        foreach (file_head($recent, $rss_max) as $line) {
                list($time, $page) = explode("\t", rtrim($line));
-               $r_page = rawurlencode($page);
+               $r_page = pagename_urlencode($page);
                $title  = mb_convert_encoding($page, 'UTF-8', SOURCE_ENCODING);
 
                switch ($version) {
@@ -82,7 +82,7 @@ EOD;
        header('Content-type: application/xml');
        print '<?xml version="1.0" encoding="UTF-8"?>' . "\n\n";
 
-       $r_whatsnew = rawurlencode($whatsnew);
+       $r_whatsnew = pagename_urlencode($whatsnew);
        switch ($version) {
        case '0.91':
                print '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"' .
@@ -129,4 +129,4 @@ EOD;
        }
        exit;
 }
-?>
+
index 66e1bbd..6b408cf 100644 (file)
@@ -49,7 +49,7 @@ function plugin_topicpath_inline()
        $topic_path = array();
        while (! empty($parts)) {
                $_landing = join('/', $parts);
-               $landing  = rawurlencode($_landing);
+               $landing  = pagename_urlencode($_landing);
                $element  = htmlsc(array_pop($parts));
                if (! $b_link)  {
                        // This page ($_landing == $page)
@@ -70,4 +70,4 @@ function plugin_topicpath_inline()
 
        return join(PLUGIN_TOPICPATH_TOP_SEPARATOR, array_reverse($topic_path));
 }
-?>
+
index 6f7ee9c..fa56ea7 100644 (file)
@@ -174,7 +174,7 @@ function plugin_tracker_action()
        // Writing page data, without touch
        page_write($page, join('', $postdata));
 
-       $r_page = rawurlencode($page);
+       $r_page = pagename_urlencode($page);
 
        pkwk_headers_sent();
        header('Location: ' . get_script_uri() . '?' . $r_page);
index 8743600..559aed4 100644 (file)
@@ -42,7 +42,7 @@ function plugin_yetlist_action()
                        $r_refer = '';
                        $link_refs = array();
                        foreach ($refer as $_refer) {
-                               $r_refer = rawurlencode($_refer);
+                               $r_refer = pagename_urlencode($_refer);
                                $link_refs[] = '<a href="' . $script . '?' . $r_refer . '">' .
                                        htmlsc($_refer) . '</a>';
                        }
@@ -73,4 +73,4 @@ function plugin_yetlist_action()
 
        return $retval;
 }
-?>
+
index 786d1f7..fe6de67 100644 (file)
@@ -59,7 +59,7 @@ if ($rw) {
                }
        }
 }
-$navi[] = '<a href="' . $script . '?' . rawurlencode($menubar) . '" ' . $accesskey . '="4">4.Menu</a>';
+$navi[] = '<a href="' . $script . '?' . pagename_urlencode($menubar) . '" ' . $accesskey . '="4">4.Menu</a>';
 $navi[] = '<a href="' . $link['recent'] . '" ' . $accesskey . '="5">5.Recent</a>';
 
 // Previous / Next block