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/</</g; |
13 |
|
|
$s =~ s/"/"/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 — @{[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 — @{[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>© 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 |
wakaba |
1.11 |
<!--<p><strong>Texts from XBL 2.0 spec</strong>: |
122 |
wakaba |
1.3 |
<blockquote cite="http://www.mozilla.org/projects/xbl/xbl2.html"> |
123 |
|
|
<p class=copyright>Portions of this content are © 1998–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.11 |
</blockquote>--> |
128 |
wakaba |
1.1 |
|
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 |
wakaba |
1.10 |
<option value=apps-cover>HTML5 Cover |
235 |
|
|
<option value=apps-introduction>HTML5 Introduction |
236 |
|
|
<option value=apps-infrastructure>HTML5 Common Infrastructure |
237 |
|
|
<option value=apps-dom>HTML5 Documents |
238 |
|
|
<option value=apps-semantics>HTML5 Elements |
239 |
|
|
<option value=apps-browsers>HTML5 Web Browsers |
240 |
|
|
<option value=apps-editing>HTML5 User Interaction |
241 |
|
|
<option value=apps-comms>HTML5 Communication |
242 |
|
|
<option value=apps-syntax>HTML5 Syntax |
243 |
|
|
<option value=apps-rendering>HTML5 Rendering |
244 |
|
|
<option value=apps-no>HTML5 Appendices |
245 |
wakaba |
1.9 |
<option value=workers>Web Workers |
246 |
|
|
<option value=xbl>XBL 2.0</select> |
247 |
|
|
<p><select id=originals size=30 onclick=" |
248 |
|
|
var opt = event.target; |
249 |
|
|
if (opt.nodeName == 'OPTION') { |
250 |
|
|
document.forms[0]['original-text'].value = opt.textContent; |
251 |
|
|
} |
252 |
|
|
"></select> |
253 |
|
|
<p><label><strong>Original text</strong>:<br> |
254 |
|
|
<textarea id=original-text name=original-text></textarea></label><br> |
255 |
|
|
(<label><input type=checkbox name=pattern> Pattern</label>) |
256 |
|
|
|
257 |
|
|
<p><label><strong>Translated text</strong>:<br> |
258 |
|
|
<textarea id=translated-text name=translated-text></textarea></label> |
259 |
|
|
|
260 |
|
|
<p><button type=submit>Save</button> to |
261 |
|
|
<select name=data-file> |
262 |
wakaba |
1.8 |
]; |
263 |
|
|
|
264 |
wakaba |
1.9 |
require 'common.pl'; |
265 |
|
|
for_each_data_file (sub { |
266 |
|
|
shift; |
267 |
|
|
my $data_file_name = shift; |
268 |
|
|
$data_file_name =~ s/\.dat\z//; |
269 |
|
|
print q[<option>], htescape ($data_file_name); |
270 |
|
|
}); |
271 |
|
|
|
272 |
|
|
print q[</select> |
273 |
|
|
<p><strong>Important</strong>: See <a href="../#license" rel=license>license</a>. |
274 |
|
|
</form>]; |
275 |
|
|
exit; |
276 |
|
|
} |
277 |
wakaba |
1.1 |
} |
278 |
|
|
|
279 |
|
|
print q[Content-Type: text/plain ; charset=us-ascii |
280 |
|
|
Status: 404 Not Found |
281 |
|
|
|
282 |
|
|
404]; |