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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Sun Aug 10 06:15:00 2008 UTC (16 years, 2 months ago) by wakaba
Branch: MAIN
Changes since 1.8: +122 -6 lines
*** empty log message ***

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use CGI::Carp qw(fatalsToBrowser);
4    
5     my $data_dir_name = q[data/];
6    
7     my $path = $ENV{PATH_INFO};
8    
9     sub htescape ($) {
10     my $s = shift;
11     $s =~ s/&/&/g;
12     $s =~ s/</&lt;/g;
13     $s =~ s/"/&quot;/g;
14     return $s;
15     } # htescape
16    
17 wakaba 1.6 if ($path =~ m[^/(_?[0-9a-z-]+)$]) {
18 wakaba 1.1 my $name = $1;
19     my $file_name = $data_dir_name . $name . '.dat';
20     if (-f $file_name) {
21     if ($ENV{REQUEST_METHOD} eq 'GET') {
22     my $data;
23     {
24     open my $file, '<:utf8', $file_name or die "$0: $file_name: $!";
25     local $/ = undef;
26     $data = <$file>;
27     }
28    
29     print qq[Content-Type: text/html; charset=utf-8
30    
31     <!DOCTYPE HTML>
32     <html lang=en>
33     <head>
34     <title>Edit &mdash; @{[htescape ($name)]}</title>
35     <style>
36     textarea {
37     width: 95%;
38     height: 40em;
39     }
40     </style>
41     <link rel=license href="./#license">
42 wakaba 1.9 <link rel=history href="../data/@{[htescape ($name)]}.dat,cvslog">
43 wakaba 1.1 <body>
44     <h1>Edit &mdash; @{[htescape ($name)]}</h1>
45     <form action accept-charset=utf-8 method=post>
46     <p><textarea name=data lang>@{[htescape ($data)]}</textarea>
47     <p><input type=submit value=Save>
48     <strong>Important</strong>: See <a href="./#license" rel=license>license</a>.
49     </form>
50     ];
51     exit;
52     } elsif ($ENV{REQUEST_METHOD} eq 'POST') {
53     eval q{ use CGI qw(param) };
54     my $data = param ('data');
55     open my $file, '>', $file_name or die "$0: $file_name: $!";
56     print $file $data;
57     close $file;
58     my $user = $ENV{REMOTE_USER};
59     $user =~ s/[^0-9A-Za-z_-]/_/g;
60     (system "cvs commit -m \"by remote user \'$user\'\" data > /dev/null") == 0 or die "$0: $?";
61    
62     print q[Status: 204 Saved; No Content];
63     exit;
64     } else {
65     print q[Status: 405 Method Not Allowed
66     Content-Type: text/plain ; charset=us-ascii
67     Allow: GET, POST
68    
69     405];
70     exit;
71     }
72     }
73     } elsif ($path eq '/') {
74     opendir my $data_dir, $data_dir_name or die "$0: $data_dir_name: $!";
75     print q[Content-Type: text/html; charset=utf-8
76    
77     <!DOCTYPE HTML>
78     <html lang=en>
79     <title>English-Japanese Data Files</title>
80     <link rel=history href="../data/,cvslog">
81     <link rel=license href="#license">
82 wakaba 1.4 <link rel=stylesheet href="/www/style/html/xhtml">
83 wakaba 1.1 <h1>English-Japanese Data Files</h1>
84    
85     <ul>];
86     for (sort {$a cmp $b} grep {/\.dat$/} readdir $data_dir) {
87     my $name = $_;
88     $name =~ s/\.dat$//;
89     print qq[<li><a href="@{[htescape ($name)]}"><code class=file>@{[htescape ($name)]}</code></a></li>];
90     }
91     print q[</ul>
92    
93 wakaba 1.7 <section id=tools>
94     <h2>Tools</h2>
95 wakaba 1.5
96 wakaba 1.7 <ul>
97     <li><a href="../words">English-Japanese word mapping table</a>
98     <li id=find><a href="../find" rel=search>Find</a>
99 wakaba 1.9 <li><a href="para/add">Add paragraph</a>
100 wakaba 1.7 </ul>
101 wakaba 1.5 </section>
102    
103 wakaba 1.2 <section id=status>
104     <h2>Status of translation</h2>
105    
106     <p>See <a href="../status.png">progress graph</a>.
107     </section>
108    
109 wakaba 1.1 <section id=license>
110     <h2>License of data files</h2>
111    
112 wakaba 1.3 <p><strong>Texts from HTML5 and Web Workers specs</strong>:
113 wakaba 1.1 <blockquote cite="http://whatwg.org/html5">
114     <p class=copyright>&copy; Copyright 2004-2008 Apple Computer, Inc.,
115     Mozilla Foundation, and Opera Software ASA.</p>
116    
117     <p class=copyright>You are granted a license to use, reproduce and create
118     derivative works of this document.</p>
119 wakaba 1.3 </blockquote>
120    
121     <p><strong>Texts from XBL 2.0 spec</strong>:
122     <blockquote cite="http://www.mozilla.org/projects/xbl/xbl2.html">
123     <p class=copyright>Portions of this content are &copy; 1998&#8211;2006 by
124     individual mozilla.org contributors; content available under a Creative
125     Commons license. (<a
126     href="http://www.mozilla.org/foundation/licensing/website-content.html">Details</a>)</p>
127 wakaba 1.1 </blockquote>
128    
129     <p><strong>For contributors</strong>: You have to agree that your
130     contributions are licensed under the terms quoted above.
131     </section>
132     ];
133     exit;
134 wakaba 1.8 } elsif ($path eq '/para/add') {
135     if ($ENV{REQUEST_METHOD} eq 'POST') {
136 wakaba 1.9 eval q{ use CGI qw(param) };
137     my $data_file_name = param ('data-file');
138     $data_file_name =~ s/[^A-Za-z0-9_-]/_/g;
139     $data_file_name .= '.dat';
140     $data_file_name = $data_dir_name . $data_file_name;
141     if (-f $data_file_name) {
142     my $entry = '';
143     if (param ('pattern')) {
144     $entry .= "#pattern\n";
145     } else {
146     $entry .= "#en\n";
147     }
148    
149     my $en = param ('original-text');
150     $en =~ s/^\s+//;
151     $en =~ s/\x+\z//;
152     $en =~ s/\x0D?\x0A(?:\x0D?\x0A)+/\n/g;
153     $entry .= $en;
154    
155     $entry .= "\n#ja\n";
156    
157     my $ja = param ('translated-text');
158     $ja =~ s/^\s+//;
159     $ja =~ s/\x+\z//;
160     $ja =~ s/\x0D?\x0A(?:\x0D?\x0A)+/\n/g;
161     $entry .= $ja; # utf8
162    
163     open my $data_file, '>>', $data_file_name
164     or die "$0: $data_file_name: $!";
165     print $data_file "\n\n";
166     print $data_file $entry;
167     close $data_file;
168 wakaba 1.8
169 wakaba 1.9 my $user = $ENV{REMOTE_USER};
170     $user =~ s/[^0-9A-Za-z_-]/_/g;
171     (system "cvs commit -m \"by remote user \'$user\'\" data > /dev/null") == 0 or die "$0: $?";
172    
173     print q[Status: 204 Saved; No Content
174    
175     ];
176     exit;
177     }
178     } else {
179     print q[Content-Type: text/html ; charset=utf-8
180 wakaba 1.8
181     <!DOCTYPE HTML>
182     <html lang=en>
183     <head>
184     <title>Add paragraph</title>
185 wakaba 1.9 <link rel=license href="../#license">
186 wakaba 1.8 <link rel=stylesheet href="/www/style/html/xhtml">
187 wakaba 1.9 <style>
188     form p {
189     text-indent: 0 !important;
190     }
191     textarea {
192     height: 15em;
193     }
194     select[size] {
195     width: 100%;
196     height: 20em;
197     }
198     select[size] option {
199     white-space: pre;
200     height: 4em;
201     width: 100%;
202     overflow: hidden;
203     }
204     </style>
205     <script>
206     function updateOriginalsBox () {
207     var dataFileId = document.getElementById ('originals-data-file').value;
208     var xhr = new XMLHttpRequest ();
209     xhr.open ('GET', '../../tbt-' + dataFileId + '.dat', true);
210     xhr.onreadystatechange = function () {
211     if (xhr.readyState == 4) {
212     if (xhr.status < 400) {
213     var originals = document.getElementById ('originals');
214     originals.textContent = '';
215    
216     var data = xhr.responseText.split (/\u000D?\u000A\u000D?\u000A/);
217     for (var i = 0; i < data.length; i++) {
218     var opt = document.createElement ('option');
219     opt.textContent = data[i];
220     originals.appendChild (opt);
221     }
222     }
223     xhr.onreadystatechange = null;
224     }
225     };
226     xhr.send (null);
227     } // updateOriginalsBox
228     </script>
229     <body onload=" updateOriginalsBox () ">
230 wakaba 1.8 <h1>Add paragraph</h1>
231     <form action=add accept-charset=utf-8 method=post>
232 wakaba 1.9
233     <p><select id=originals-data-file onchange=" updateOriginalsBox () ">
234     <option value=apps>HTML5
235     <option value=workers>Web Workers
236     <option value=xbl>XBL 2.0</select>
237     <p><select id=originals size=30 onclick="
238     var opt = event.target;
239     if (opt.nodeName == 'OPTION') {
240     document.forms[0]['original-text'].value = opt.textContent;
241     }
242     "></select>
243     <p><label><strong>Original text</strong>:<br>
244     <textarea id=original-text name=original-text></textarea></label><br>
245     (<label><input type=checkbox name=pattern> Pattern</label>)
246    
247     <p><label><strong>Translated text</strong>:<br>
248     <textarea id=translated-text name=translated-text></textarea></label>
249    
250     <p><button type=submit>Save</button> to
251     <select name=data-file>
252 wakaba 1.8 ];
253    
254 wakaba 1.9 require 'common.pl';
255     for_each_data_file (sub {
256     shift;
257     my $data_file_name = shift;
258     $data_file_name =~ s/\.dat\z//;
259     print q[<option>], htescape ($data_file_name);
260     });
261    
262     print q[</select>
263     <p><strong>Important</strong>: See <a href="../#license" rel=license>license</a>.
264     </form>];
265     exit;
266     }
267 wakaba 1.1 }
268    
269     print q[Content-Type: text/plain ; charset=us-ascii
270     Status: 404 Not Found
271    
272     404];

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24