/[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.2 - (show annotations) (download)
Sun Oct 26 08:44:19 2008 UTC (17 years, 3 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +13 -6 lines
Dynamic update implemented

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24