/[suikacvs]/markup/html/html5/spec-ja/edit2.cgi
Suika

Contents of /markup/html/html5/spec-ja/edit2.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Sun Nov 2 04:49:55 2008 UTC (17 years, 2 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +5 -4 lines
Do width normalization

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use CGI::Carp qw(fatalsToBrowser);
4    
5     use lib qw[/home/wakaba/work/manakai2/lib/];
6    
7     require 'common.pl';
8    
9     my $path = $ENV{PATH_INFO};
10    
11     if ($path eq '/') {
12     if ($ENV{REQUEST_METHOD} eq 'POST') {
13     require Message::CGI::HTTP;
14     require Encode;
15    
16     my $cgi = Message::CGI::HTTP->new;
17     $cgi->{decoder}->{'#default'} = sub {
18     return Encode::decode ('utf-8', $_[1]);
19     };
20    
21 wakaba 1.8 my $en = normalize_width ($cgi->get_parameter ('en'));
22     my $ja = normalize_width ($cgi->get_parameter ('ja'));
23 wakaba 1.1 my $is_pattern = $cgi->get_parameter ('pattern');
24     my $tags = [map {normalize ($_)}
25 wakaba 1.8 split /[\x0D\x0A]+/,
26     normalize_width ($cgi->get_parameter ('tags') // '')];
27 wakaba 1.1
28     my $hash = get_hash ($en);
29 wakaba 1.4 my $entry = {en => $en, ja => $ja, tags => $tags,
30 wakaba 1.6 isPattern => $is_pattern};
31 wakaba 1.3
32 wakaba 1.1 lock_entry ($hash);
33 wakaba 1.3 set_entry ($hash, $is_pattern => $entry);
34 wakaba 1.7 commit_entries ("$path: $hash updated by $ENV{REMOTE_USER}");
35 wakaba 1.1
36 wakaba 1.3 print "Status: 200 Saved\n";
37    
38     my $updates = {$hash => $entry};
39    
40     binmode STDOUT, ':encoding(utf-8)';
41     print "Content-Type: application/json\n\n";
42    
43     require JSON;
44     print scalar JSON::objToJson ($updates);
45 wakaba 1.1 exit;
46     } else {
47     print q[Status: 405 Method Not Allowed
48     Content-Type: text/plain ; charset=us-ascii
49     Allow: POST
50    
51     405];
52     exit;
53     }
54     } elsif ($path =~ m#^/([0-9a-f]+)\.json$#) {
55     my $hash = $1;
56 wakaba 1.2 my $entry = get_entry_or_fallback_entry ($hash);
57 wakaba 1.1
58     binmode STDOUT, ':encoding(utf-8)';
59     print "Content-Type: application/json\n\n";
60    
61     require JSON;
62     print scalar JSON::objToJson ($entry);
63 wakaba 1.2 exit;
64     } elsif ($path eq '/updates.json') {
65     my $updates = {};
66     for (get_modified_hashes ()) {
67     $updates->{$_} = get_entry_or_fallback_entry ($_);
68     }
69    
70     binmode STDOUT, ':encoding(utf-8)';
71     print "Content-Type: application/json\n\n";
72    
73     require JSON;
74     print scalar JSON::objToJson ($updates);
75 wakaba 1.1 exit;
76     }
77    
78     print q[Content-Type: text/plain ; charset=us-ascii
79     Status: 404 Not Found
80    
81     404];
82 wakaba 1.5
83     ## Author: Wakaba <w@suika.fam.cx>.
84     ## License: Copyright 2008 Wakaba. You are granted a license to use,
85     ## reproduce and create derivative works of this script.
86 wakaba 1.8 ## $Date: 2008/10/31 04:30:24 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24