/[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.3 - (hide annotations) (download)
Sun Oct 26 10:10:54 2008 UTC (17 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +12 -3 lines
Dynamic update of just-updated entry improved

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     my $en = $cgi->get_parameter ('en');
22     my $ja = $cgi->get_parameter ('ja');
23     my $is_pattern = $cgi->get_parameter ('pattern');
24     my $tags = [map {normalize ($_)}
25     split /[\x0D\x0A]+/, $cgi->get_parameter ('tags') // ''];
26    
27     my $hash = get_hash ($en);
28 wakaba 1.3 my $entry = {en => $en, ja => $ja, tags => $tags};
29    
30 wakaba 1.1 lock_entry ($hash);
31 wakaba 1.3 set_entry ($hash, $is_pattern => $entry);
32 wakaba 1.1 commit_entries ("$path: $hash updated by $ENV{AUTH_USER}");
33    
34 wakaba 1.3 print "Status: 200 Saved\n";
35    
36     my $updates = {$hash => $entry};
37    
38     binmode STDOUT, ':encoding(utf-8)';
39     print "Content-Type: application/json\n\n";
40    
41     require JSON;
42     print scalar JSON::objToJson ($updates);
43 wakaba 1.1 exit;
44     } else {
45     print q[Status: 405 Method Not Allowed
46     Content-Type: text/plain ; charset=us-ascii
47     Allow: POST
48    
49     405];
50     exit;
51     }
52     } elsif ($path =~ m#^/([0-9a-f]+)\.json$#) {
53     my $hash = $1;
54 wakaba 1.2 my $entry = get_entry_or_fallback_entry ($hash);
55 wakaba 1.1
56     binmode STDOUT, ':encoding(utf-8)';
57     print "Content-Type: application/json\n\n";
58    
59     require JSON;
60     print scalar JSON::objToJson ($entry);
61 wakaba 1.2 exit;
62     } elsif ($path eq '/updates.json') {
63     my $updates = {};
64     for (get_modified_hashes ()) {
65     $updates->{$_} = get_entry_or_fallback_entry ($_);
66     }
67    
68     binmode STDOUT, ':encoding(utf-8)';
69     print "Content-Type: application/json\n\n";
70    
71     require JSON;
72     print scalar JSON::objToJson ($updates);
73 wakaba 1.1 exit;
74     }
75    
76     print q[Content-Type: text/plain ; charset=us-ascii
77     Status: 404 Not Found
78    
79     404];

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24