/[pub]/suikawiki/script/wiki.cgi
Suika

Contents of /suikawiki/script/wiki.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.61 - (hide annotations) (download)
Mon Nov 10 15:05:30 2008 UTC (16 years ago) by wakaba
Branch: MAIN
CVS Tags: suikawiki3-redirect
Changes since 1.60: +4 -3 lines
2008-11-10  Wakaba  <wakaba@suika.fam.cx>

        * wiki.cgi: Support for the _charset_=utf-8 parameter, which is
        necessary for <http://suika.fam.cx/gate/2005/sw/>.

1 wakaba 1.60 #!/usr/bin/perl
2 wakaba 1.16 use strict;
3 wakaba 1.60 use lib qw[/home/httpd/html/www/markup/html/whatpm
4     /home/wakaba/work/manakai2/lib
5     /home/httpd/html/swe/lib/];
6    
7     use CGI::Carp qw[fatalsToBrowser];
8     require Message::CGI::Carp;
9    
10     my $sw4_url = q<http://suika.fam.cx/~wakaba/wiki/sw/>;
11    
12     require Message::CGI::HTTP;
13     require Encode::EUCJPSW;
14     my $cgi = Message::CGI::HTTP->new;
15    
16     my $page = $ENV{QUERY_STRING};
17     if ($page =~ /[&;]/) {
18     $page = $cgi->get_parameter ('mypage') // '';
19 wakaba 1.61
20     my $charset = $cgi->get_parameter ('_charset_') // 'euc-jp-sw';
21     $charset = 'euc-jp-sw' unless $charset eq 'utf-8';
22     $page = Encode::decode ($charset, $page);
23 wakaba 1.60 } else {
24     $page = Encode::decode ('euc-jp-sw', percent_decode_byte ($page));
25     }
26    
27     my $url = get_page_url ($page);
28    
29     print qq[Status: 301 Moved
30     Location: $url
31     Content-Type: text/html; charset=utf-8
32    
33     <!DOCTYPE HTML>
34     <html lang=en>
35     <title>301 Moved</title>
36     <h1>Moved</h1>
37     <p>See <a href="@{[htescape ($url)]}">other page</a>.];
38     exit;
39    
40     sub get_page_url ($) {
41     my $wiki_name = shift;
42     $wiki_name = percent_encode ($wiki_name);
43     $wiki_name =~ s/%2F/+/g;
44     $wiki_name = $sw4_url . 'n/' . $wiki_name;
45     return $wiki_name;
46     } # get_page_url
47    
48     sub percent_encode ($) {
49     my $s = Encode::encode ('utf8', $_[0]);
50     $s =~ s/([^A-Za-z0-9_~-])/sprintf '%%%02X', ord $1/ges;
51     return $s;
52     } # percent_encode
53    
54     sub percent_decode ($) { # input should be a byte string.
55     my $s = shift;
56     $s =~ s/%([0-9A-Fa-f]{2})/pack 'C', hex $1/ge;
57     return Encode::decode ('utf-8', $s); # non-UTF-8 octet converted to \xHH
58     } # percent_decode
59    
60     sub percent_decode_byte ($) { # input should be a byte string.
61     my $s = shift;
62     $s =~ s/%([0-9A-Fa-f]{2})/pack 'C', hex $1/ge;
63     return $s;
64     } # percent_decode_byte
65    
66     sub htescape ($) {
67     my $s = shift;
68     $s =~ s/&/&amp;/g;
69     $s =~ s/</&lt;/g;
70     $s =~ s/"/&quot;/g;
71     return $s;
72     } # htescape

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24