1 |
use strict; |
2 |
|
3 |
package wiki; |
4 |
our $VERSION = do{my @r=(q$Revision: 1.14 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
5 |
package main; |
6 |
binmode STDOUT; binmode STDIN; |
7 |
|
8 |
require SuikaWiki::Plugin; |
9 |
our %embed_command = ( |
10 |
form => qr/\[\[\#form(?:\(([A-Za-z0-9-]+)\))?:'((?:[^'\\]|\\.)*)':'((?:[^'\\]|\\.)*)'(?::'((?:[^'\\]|\\.)*)')?\]\]/, |
11 |
); |
12 |
our $database = bless {}, 'wiki::dummy'; |
13 |
$| = 1; |
14 |
require SuikaWiki::Name::Space; |
15 |
my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml'; |
16 |
our $WIKI; |
17 |
require Message::Markup::XML; |
18 |
|
19 |
sub _do_view_msg (%) { |
20 |
require SuikaWiki::View; |
21 |
my %option = @_; |
22 |
my $o = $option{-o} || bless {param => \%main::form, page => $option{-page}, |
23 |
&_compatible_options ()}, 'SuikaWiki::Plugin'; |
24 |
$o->{toc} = []; |
25 |
$o->{condition} = \%option; ## This parameter really used?? |
26 |
my $view_def = SuikaWiki::View->definition ($option{-view}); |
27 |
unless ($view_def->check ($o)) { |
28 |
print "Status: 406 Unsupported Media Type\n"; |
29 |
$option{-view} = '-UnsupportedMediaType'; |
30 |
$view_def = SuikaWiki::View->definition ($option{-view}); |
31 |
} |
32 |
my $prop = $view_def->properties; |
33 |
my $media = $prop->{media}; |
34 |
if ($prop->{xmedia} && $main::UA =~ /Gecko/) { |
35 |
$media = $prop->{xmedia}; |
36 |
$o->{media} = $media; |
37 |
} |
38 |
&print_header($option{-page}, -media => $media, -view => $view_def, o => $o, -goto => $option{-goto}); |
39 |
print "\n"; |
40 |
## Output HTTP message body |
41 |
my $fmt = SuikaWiki::Plugin->formatter ('view'); |
42 |
my $s = $fmt->replace ($view_def->as_string => $o, {formatter => $fmt}); |
43 |
print $s; |
44 |
} |
45 |
|
46 |
=pod |
47 |
|
48 |
# [move to SuikaWiki::Plugin::WikiAdmin] |
49 |
sub do_adminchangepassword { |
50 |
if ($main::form{mynewpassword} ne $main::form{mynewpassword2}) { |
51 |
&_do_view_msg (-view => '-error', -page => $main::form{mypage}, |
52 |
error_message => &Resource ('Error:PasswordMismatch')); |
53 |
return; |
54 |
} |
55 |
my ($validpassword_crypt) = $main::database->meta (AdminPassword => $PageName{AdminSpecialPage}); |
56 |
if ($validpassword_crypt) { |
57 |
if (not &valid_password($main::form{myoldpassword})) { |
58 |
&_do_view_msg (-view => '-error', -page => $main::form{mypage}, |
59 |
error_message => &Resource ('Error:PasswordIsIncorrect')); |
60 |
return; |
61 |
} |
62 |
} |
63 |
my ($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); |
64 |
my (@token) = ('0'..'9', 'A'..'Z', 'a'..'z'); |
65 |
my $salt1 = $token[(time | $$) % scalar(@token)]; |
66 |
my $salt2 = $token[($sec + $min*60 + $hour*60*60) % scalar(@token)]; |
67 |
my $crypted = crypt($main::form{mynewpassword}, "$salt1$salt2"); |
68 |
$main::database->meta (AdminPassword => $main::PageName{AdminSpecialPage} => $crypted); |
69 |
|
70 |
&_do_view_msg (-view => '-wrote', -page => $main::form{mypage}); |
71 |
} |
72 |
|
73 |
=cut |
74 |
|
75 |
# [move to SuikaWiki::WikiDB] |
76 |
sub valid_password ($) { |
77 |
return 0; |
78 |
# my ($validpassword_crypt) = $main::database->meta (AdminPassword => $PageName{AdminSpecialPage}); |
79 |
# return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0; |
80 |
} |
81 |
|
82 |
## [obsolete] BugTrack, RandomJump |
83 |
sub _http_see_other (%) { |
84 |
my %o = @_; |
85 |
$o{page} = join '//', @{$o{page}} if ref $o{page}; |
86 |
$o{uri} ||= SuikaWiki::Plugin->_uri_wiki_page ($o{page}, absolute => 1); |
87 |
if ($o{alternate_view} && ($main::ENV{SERVER_PROTOCOL} eq 'HTTP/1.0') |
88 |
&& !($main::UA =~ m#M(?:ozilla|icrosoft Internet Explorer)#)) { |
89 |
&_do_view_msg (-view => $o{alternate_view}, -page => $o{page}, -goto => $o{uri}, -o => $o{o}); |
90 |
} else { |
91 |
require SuikaWiki::Output::HTTP; |
92 |
my $output = SuikaWiki::Output::HTTP->new (wiki => $WIKI); |
93 |
$output->set_redirect (uri => $o{uri}, status_code => 303); |
94 |
$output->output (output => 'http-cgi'); |
95 |
} |
96 |
exit; |
97 |
} |
98 |
|
99 |
# temp |
100 |
sub is_editable { 1 } |
101 |
|
102 |
sub _compatible_options () { |
103 |
(use_anchor_name => ($main::UA =~ m#Mozilla/[1-4]\.|Microsoft Internet Explorer# ? 1 : 0)); |
104 |
} |
105 |
|
106 |
|
107 |
|
108 |
sub print_header ($;%) { |
109 |
my ($page, %option) = @_; |
110 |
if ($main::ENV{HTTP_IF_MODIFIED_SINCE} && $option{-last_modified}) { |
111 |
## TODO: use Message::Field::Date |
112 |
if ($option{-view}->properties->{if}->{modified_since} |
113 |
&& $main::ENV{HTTP_IF_MODIFIED_SINCE} =~ /([0-9]{1,2})\s*([A-Za-z]{3})\s*([0-9]{2,4})\s*([0-9]{2}):([0-9]{2}):([0-9]{2})\s*[Gg][Mm][Tt]/) { |
114 |
require Time::Local; |
115 |
my ($d, $M, $y, $h, $m, $s) = ($1, $2, $3, $4, $5, $6); |
116 |
$M = {jan=>0,feb=>1,mar=>2,apr=>3,may=>4,jun=>5,jul=>6,aug=>7,sep=>8,oct=>9,nov=>10,dec=>11}->{lc $M}; |
117 |
#$y += 1900 if $y < 100; ## BUG: don't conform HTTP spec |
118 |
my $t = Time::Local::timegm_nocheck ($s, $m, $h, $d, $M, $y); |
119 |
if ($option{-last_modified} <= $t) { |
120 |
print "Status: 304 Not Modified\n\n"; |
121 |
exit; |
122 |
} |
123 |
} |
124 |
} |
125 |
#my $UA = SuikaWiki::Plugin->user_agent_names; |
126 |
$option{o}->{-header}->{class}->{frozen} = 1 if &main::is_frozen ($page); |
127 |
$option{o}->{-header}->{class}->{'wiki-page-obsoleted'} = 1 if $option{-magic} =~ /obsoleted="yes"/; |
128 |
$option{o}->{-header}->{additional_html_element} ||= SuikaWiki::Markup::XML->new (type => '#fragment'); |
129 |
#print "Vary: Negotiate,User-Agent,Accept-Language,Accept\n"; |
130 |
if ($option{-goto}) { |
131 |
if ($main::UA =~ m#Opera|MSIE 2\.#) { |
132 |
## WARNING: This code may output unsafe HTML document if $option{-goto} is unclean. |
133 |
$option{-goto} =~ tr/;/&/ if $main::UA =~ m#Opera#; |
134 |
print qq{Refresh: 0; url=$option{-goto}\n}; |
135 |
for ($option{o}->{-header}->{additional_html_element}->append_new_node |
136 |
(namespace_uri => $NS_XHTML1, local_name => 'meta')) { |
137 |
$_->set_attribute ('http-equiv' => 'refresh'); |
138 |
$_->set_attribute (content => "0; url=$option{-goto}"); |
139 |
$_->option (use_EmptyElemTag => 1); |
140 |
} |
141 |
} else { |
142 |
$option{-goto} =~ tr/;/&/ if $main::UA =~ m#Mozilla/[1-4]\.#; |
143 |
print qq{Refresh: 0; url="$option{-goto}"\n}; |
144 |
for ($option{o}->{-header}->{additional_html_element}->append_new_node |
145 |
(namespace_uri => $NS_XHTML1, local_name => 'meta')) { |
146 |
$_->set_attribute ('http-equiv' => 'refresh'); |
147 |
$_->set_attribute (content => qq(0; url="$option{-goto}")); |
148 |
$_->option (use_EmptyElemTag => 1); |
149 |
} |
150 |
} |
151 |
} |
152 |
print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n} |
153 |
if $option{-last_modified}; |
154 |
if ($option{-expires} != -1) { |
155 |
if (defined $option{-expires}) { ## TODO: Don't use asctime |
156 |
print qq{Expires: @{[scalar gmtime (time + $option{-expires})]}\n}; |
157 |
} elsif ($option{-media}->{expires} != -1) { |
158 |
print qq{Expires: @{[scalar gmtime (time + $option{-media}->{expires})]}\n}; |
159 |
} |
160 |
} |
161 |
if ($option{-media}->{charset} && $main::UA =~ m#Mozilla/[12]\.#) { |
162 |
## UAs don't support official charset names but do non-official names |
163 |
my $ct = qq{$option{-media}->{type}; charset=@{[ &main::get_charset_name ($main::kanjicode, compatible => 1) ]}}; |
164 |
print qq{Content-Type: $ct\n}; |
165 |
for ($option{o}->{-header}->{additional_html_element}->append_new_node |
166 |
(namespace_uri => $NS_XHTML1, local_name => 'meta')) { |
167 |
$_->set_attribute ('http-equiv' => 'content-type'); |
168 |
$_->set_attribute (content => $ct); |
169 |
} |
170 |
} elsif (!$option{-media}->{charset} || $main::UA =~ m#Infomosaic|Mozilla/0\.#) { |
171 |
## Media types or UAs don't support charset parameter in HTTP header |
172 |
print qq{Content-Type: $option{-media}->{type}\n}; |
173 |
if ($option{-media}->{charset}) { |
174 |
for ($option{o}->{-header}->{additional_html_element}->append_new_node |
175 |
(namespace_uri => $NS_XHTML1, local_name => 'meta')) { |
176 |
$_->set_attribute ('http-equiv' => 'content-type'); |
177 |
$_->set_attribute (content => qq($option{-media}->{type}; charset=).main::get_charset_name ($main::kanjicode, compatible => 1)); |
178 |
} |
179 |
} |
180 |
} else { |
181 |
## Modern UAs and Media types with charset parameter |
182 |
my $type = $option{-media}->{type}; |
183 |
$type = 'application/xml' if ($type =~ m!^application/rdf\+xml$!) && ($main::UA =~ m#Gecko#); |
184 |
print qq{Content-Type: $type; charset=@{[&main::get_charset_name ($main::kanjicode)]}\n}; |
185 |
## meta element is not needed |
186 |
} |
187 |
|
188 |
} |
189 |
|
190 |
sub get_charset_name ($;%) { |
191 |
my ($charset, %option) = (lc shift, @_); |
192 |
if ($charset =~ 'euc') { |
193 |
$charset = $option{compatible} ? 'x-euc-jp' : 'euc-jp'; |
194 |
} elsif ($charset =~ 'sjis' || $charset =~ 'shift') { |
195 |
$charset = $option{compatible} ? 'x-sjis' : 'shift_jis'; |
196 |
} elsif ($charset =~ 'jis') { |
197 |
$charset = 'iso-2022-jp'; |
198 |
} |
199 |
$charset; |
200 |
} |
201 |
|
202 |
# [move to SuikaWiki::WikiDB] |
203 |
sub frozen_reject { |
204 |
my ($isfrozen) = $main::database->meta (IsFrozen => $main::form{mypage}); |
205 |
my ($willbefrozen) = $main::form{myfrozen}; |
206 |
if (not $isfrozen and not $willbefrozen) { |
207 |
# You need no check. |
208 |
return 0; |
209 |
} elsif (valid_password($main::form{mypassword})) { |
210 |
# You are admin. |
211 |
return 0; |
212 |
} else { |
213 |
&_do_view_msg (-view => '-error', -page => $main::form{mypage}, |
214 |
error_message => SuikaWiki::Plugin->resource ('Error:PasswordIsIncorrect')); |
215 |
exit; |
216 |
} |
217 |
} |
218 |
|
219 |
# [move to SuikaWiki::WikiDB] |
220 |
sub is_frozen ($) { SuikaWiki::Plugin->_database->meta (IsFrozen => $_[0]) ? 1 : 0 } |
221 |
|
222 |
# [to be obsolete] |
223 |
sub do_comment { |
224 |
my ($content) = $main::database{$main::form{mypage}}; |
225 |
my $default_name; ## this code is not strict. |
226 |
$default_name = $1 if $content =~ /default-name="([^"]+)"/; |
227 |
my @time = gmtime (time); |
228 |
my $datestr = sprintf '[WEAK[%04d-%02d-%02d %02d:%02d:%02d +00:00]]', $time[5]+1900,$time[4]+1,@time[3,2,1,0]; |
229 |
my $namestr = $main::form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName'); |
230 |
($namestr = '', $datestr = '') if $main::form{myname} eq 'nodate'; |
231 |
if ($namestr =~ /^(?:>>)?[0-9]/) { |
232 |
$namestr = qq( ''$namestr'': ); |
233 |
} elsif (length $namestr) { |
234 |
$namestr = qq( ''[[$namestr]]'': ); |
235 |
} |
236 |
my $anchor = &get_new_anchor_index ($content); |
237 |
my $i = 1; my $o = 0; |
238 |
$content =~ s{(\[\[\#r?comment\]\])}{ |
239 |
my $embed = $1; |
240 |
if ($i == $main::form{comment_index}) { |
241 |
if ($embed ne '[[#rcomment]]') { |
242 |
$embed = "- [$anchor] $datestr$namestr$main::form{mymsg}\n$embed"; $o = 1; |
243 |
} else { |
244 |
$embed .= "\n- [$anchor] $datestr$namestr$main::form{mymsg}"; $o = 1; |
245 |
} |
246 |
} |
247 |
$i++; $embed; |
248 |
}ge; |
249 |
unless ($o) { |
250 |
$content = "#?SuikaWiki/0.9\n\n" unless $content; |
251 |
$content .= "\n" unless $content =~ /\n$/s; |
252 |
$content .= "- [$anchor] $datestr$namestr$main::form{mymsg}\n"; |
253 |
} |
254 |
$main::form{__comment_anchor_index} = $anchor; |
255 |
if ($main::form{mymsg} || $main::form{myname}) { |
256 |
$main::form{mymsg} = $content; |
257 |
$main::form{mytouch} = 'on'; |
258 |
&do_write; |
259 |
} else { ## Don't write |
260 |
#$main::form{mycmd} = 'default'; |
261 |
#&do_view; |
262 |
die "No comment specified"; |
263 |
} |
264 |
} |
265 |
|
266 |
# [move to SuikaWiki::Plugin::WikiForm] |
267 |
sub get_new_anchor_index ($) { |
268 |
my $content = shift; |
269 |
my $anchor = 0; |
270 |
$content =~ s/^(?:[-=]+\s*)?\[([0-9]+)\]/$anchor = $1 if $1 > $anchor; $&/mge; |
271 |
$anchor + 1; |
272 |
} |
273 |
|
274 |
# [move to SuikaWiki::Plugin::WikiForm] |
275 |
sub do_wikiform { |
276 |
my $content = $main::database{$main::form{mypage}}; |
277 |
my $anchor = &get_new_anchor_index ($content); |
278 |
my $write = 0; |
279 |
my $i = 1; |
280 |
$content =~ s{$embed_command{form}}{ |
281 |
my ($embed, $wfname, $template, $option) = ($&, $1, $3, $4); |
282 |
if (($wfname && $wfname eq $main::form{wikiform_targetform}) |
283 |
|| $i == $main::form{wikiform_index}) { |
284 |
$template =~ s/\\([\\'])/$1/g; |
285 |
$option =~ s/\\([\\'])/$1/g; |
286 |
my $param = bless {depth=>10}, 'SuikaWiki::Plugin'; |
287 |
$param->{page} = $main::form{mypage}; |
288 |
$param->{form_index} = $i; |
289 |
$param->{form_name} = $wfname; |
290 |
$param->{anchor_index} = $anchor; |
291 |
$param->{argv} = \%main::form; |
292 |
$param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/; |
293 |
$param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName'); |
294 |
SuikaWiki::Plugin->formatter ('form_option')->replace ($option, $param); |
295 |
my $t = 1; |
296 |
for (keys %{$param->{require}||{}}) { |
297 |
(undef $t, last) unless length $param->{argv}->{'wikiform__'.$_}; |
298 |
} |
299 |
$t = SuikaWiki::Plugin->formatter ('form_template')->replace ($template, $param) if $t; |
300 |
if (length $t) { |
301 |
if ($param->{output}->{reverse}) { |
302 |
$embed .= "\n" . $t; |
303 |
} else { |
304 |
$embed = $t . "\n" . $embed; |
305 |
} |
306 |
$write = 1; |
307 |
$main::form{__comment_anchor_index} = $anchor |
308 |
if $param->{anchor_index_}; ## $anchor is used! |
309 |
} |
310 |
$main::form{__wikiform_anchor_index} = $i; |
311 |
undef $main::form{wikiform_targetform}; ## Make sure never to match |
312 |
undef $main::form{wikiform_index}; ## with WikiForm in rest of page! |
313 |
} |
314 |
$i++; $embed; |
315 |
}ge; |
316 |
unless ($write) { |
317 |
#$content = "#?SuikaWiki/0.9\n\n" unless $content; |
318 |
#$content .= "\n" unless $content =~ /\n$/s; |
319 |
# |
320 |
} |
321 |
if ($write) { |
322 |
$main::form{mymsg} = $content; |
323 |
$main::form{mytouch} = 'on'; |
324 |
&do_write; |
325 |
} else { ## Don't write! |
326 |
#$main::form{mycmd} = 'default'; |
327 |
#&do_view; |
328 |
die "No content specified"; |
329 |
} |
330 |
} |
331 |
|
332 |
# [to be obsolete] ->Message::MIME::Charset |
333 |
sub code_convert { |
334 |
require Jcode; |
335 |
my ($contentref, $code, $srccode) = @_; |
336 |
$code ||= $WIKI->{config}->{charset}->{internal}; |
337 |
for ($code, $srccode) { |
338 |
if ($_ eq 'euc-jp') { $_ = 'euc' } |
339 |
elsif ($_ eq 'iso-2022-jp') { $_ = 'jis' } |
340 |
elsif ($_ eq 'utf-8') { $_ = 'utf8' } |
341 |
elsif ($_ eq 'shift_jis') { $_ = 'sjis' } |
342 |
} |
343 |
$$contentref = Jcode->new ($contentref, $srccode) |
344 |
## Normalize FULLWIDTH characters and IDEOGRAPHIC SPACE |
345 |
->tr ("\xA3\xB0-\xA3\xB9\xA3\xC1-\xA3\xDA\xA3\xE1-\xA3\xFA\xA1\xF5\xA1\xA4\xA1\xA5\xA1\xA7\xA1\xA8\xA1\xA9\xA1\xAA\xA1\xAE\xA1\xB0\xA1\xB2\xA1\xBF\xA1\xC3\xA1\xCA\xA1\xCB\xA1\xCE\xA1\xCF\xA1\xD0\xA1\xD1\xA1\xDC\xA1\xF0\xA1\xF3\xA1\xF4\xA1\xF6\xA1\xF7\xA1\xE1\xA1\xE4\xA1\xE3\xA1\xA1\xA2\xAF\xA2\xB0\xA2\xB2\xA2\xB1\xA1\xA1\xC0" => q(0-9A-Za-z&,.:;?!`^_/|()[]{}+$%#*@=>< '"~-)) |
346 |
->tr (qq(\x8E\xDE\x8E\xDF) => qq(\xA1\xAB\xA1\xAC)) |
347 |
->h2z |
348 |
->$code; |
349 |
return $$contentref; |
350 |
} |
351 |
|
352 |
# [to be obsolete] ->Message::Field::Date |
353 |
sub _rfc3339_date ($) { |
354 |
my @time = gmtime (shift); |
355 |
sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00', $time[5]+1900,$time[4]+1,@time[3,2,1,0]; |
356 |
} |
357 |
|
358 |
# [obsolete] ->SuikaWiki::SrcFormat : SuikaWiki09 plugin |
359 |
sub convert_format ($$$;%) { |
360 |
my ($content, $d => $t, %option) = @_; |
361 |
my $f = SuikaWiki::Plugin->format_converter ($d => $t); |
362 |
if (ref $f) { |
363 |
$option{content} = $content; |
364 |
$option{from} = $d; |
365 |
$option{to} = $t; |
366 |
&$f ({}, bless (\%option, 'SuikaWiki::Plugin')); |
367 |
} elsif ($option{-error_no_return}) { |
368 |
return undef; |
369 |
} elsif ($t =~ /HTML|xml/) { |
370 |
if (length $content) { |
371 |
my $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'pre'); |
372 |
$r->append_text ($content); |
373 |
return $r; |
374 |
} else { |
375 |
return ''; |
376 |
} |
377 |
} else { |
378 |
$content; |
379 |
} |
380 |
} |
381 |
|
382 |
package wiki::transitional::uri_param; |
383 |
require Tie::Hash; |
384 |
our @ISA = 'Tie::Hash'; |
385 |
|
386 |
sub TIEHASH ($@) { |
387 |
bless {http => $_[1]}, $_[0]; |
388 |
} |
389 |
|
390 |
sub FETCH ($$) { |
391 |
my ($self, $key) = @_; |
392 |
exists $self->{val}->{$key} ? |
393 |
$self->{val}->{$key}: |
394 |
$self->{http}->parameter ($key); |
395 |
} |
396 |
|
397 |
sub STORE ($$$) { |
398 |
my ($self, $key, $val) = @_; |
399 |
$self->{val}->{$key} = $val; |
400 |
} |
401 |
|
402 |
sub DELETE ($$) { |
403 |
my ($self, $key) = @_; |
404 |
$self->{val}->{$key} = undef; |
405 |
} |
406 |
|
407 |
sub EXISTS ($$) { |
408 |
my ($self, $key) = @_; |
409 |
exists $self->{val}->{$key} ? |
410 |
1: |
411 |
defined $self->{http}->parameter ($key); |
412 |
} |
413 |
|
414 |
package main; |
415 |
push @{$WIKI->{event}->{setting_initial_variables}}, sub { |
416 |
my $wiki = shift; |
417 |
$wiki->{implementation_version} = 'pl'.$VERSION; |
418 |
|
419 |
## Error output |
420 |
require SuikaWiki::Output::CGICarp; |
421 |
$SuikaWiki::Output::CGICarp::CUSTOM_REASON_TEXT |
422 |
= 'Internal WikiEngine Error'; |
423 |
CGI::Carp::set_message (sub { |
424 |
my $msg = shift; |
425 |
#$msg =~ s/&/&/g; |
426 |
#$msg =~ s/</</g; |
427 |
my $wiki_name_version = $wiki->{implementation_name} .'/'. $wiki->version; |
428 |
for ($wiki_name_version) { s/&/&/g; s/</</g; |
429 |
s/([^\x20-\x7E])/sprintf '&#x%02X;', |
430 |
ord $1/g; }; |
431 |
print STDOUT <<EOH |
432 |
<!DOCTYPE html SYSTEM> |
433 |
<title>500 Internal WikiEngine Error</title> |
434 |
<h1>Internal WikiEngine Error</h1> |
435 |
<p>$msg</p> |
436 |
<address>$wiki_name_version</address> |
437 |
EOH |
438 |
}); |
439 |
|
440 |
$wiki->{var}->{db}->{read_only}->{'#default'} = 1; |
441 |
|
442 |
require SuikaWiki::Input::HTTP; |
443 |
$wiki->{input} = SuikaWiki::Input::HTTP->new; |
444 |
$wiki->{input}->{decoder}->{'#default'} = sub { |
445 |
my ($http, $s, $temp_params) = @_; |
446 |
return main::code_convert (\$s, undef, # internal code |
447 |
@{$temp_params->{ie}||[]}[0] |
448 |
|| $wiki->{config}->{charset}->{uri_param}); |
449 |
}; |
450 |
$wiki->{var}->{client}->{user_agent_name} |
451 |
= $wiki->{input}->meta_variable ('HTTP_USER_AGENT'); |
452 |
$wiki->{var}->{client}->{used_for_negotiate} = ['User-Agent']; |
453 |
|
454 |
## TODO: PATH_INFO support |
455 |
my $page = $wiki->{input}->meta_variable ('QUERY_STRING'); |
456 |
if ($page && !(index ($page, '=') > -1)) { |
457 |
$page =~ tr/+/ /; |
458 |
$page =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack 'C', hex $1/ge; |
459 |
$page = main::code_convert |
460 |
(\$page, undef, # internal code |
461 |
$wiki->{config}->{charset}->{uri_query}); |
462 |
} else { |
463 |
$page = $wiki->{input}->parameter ('mypage'); |
464 |
} |
465 |
|
466 |
|
467 |
## TODO: SuikaWiki 3 WikiName |
468 |
$page =~ tr/\x00-\x20\x7F//d; |
469 |
$page = SuikaWiki::Name::Space::normalize_name ($page); |
470 |
if ($page) { |
471 |
$wiki->{var}->{page} = [split '//', $page]; |
472 |
} else { |
473 |
$wiki->{var}->{page} = $wiki->{config}->{page}->{Default}; |
474 |
} |
475 |
|
476 |
## Mode |
477 |
my $mode = $wiki->{input}->parameter ('mode') |
478 |
|| $wiki->{input}->parameter ('mycmd') ## for compatibility with |
479 |
|| 'default'; ## YukiWiki and SuikaWiki 2 |
480 |
$mode =~ tr/-/_/; |
481 |
if ($mode eq 'default' || $mode =~ /[^0-9A-Za-z_]/) { |
482 |
## BUG: this code is not strict |
483 |
my $cookie = $wiki->{input}->meta_variable ('HTTP_COOKIE'); |
484 |
if ($cookie =~ /SelectedMode=([0-9A-Za-z_-]+)/) { |
485 |
$mode = $1; $mode =~ tr/-/_/; |
486 |
} else { |
487 |
$mode = 'read'; |
488 |
} |
489 |
push @{$wiki->{var}->{client}->{used_for_negotiate}}, 'Cookie'; |
490 |
} |
491 |
$wiki->{var}->{mode} = $mode; |
492 |
|
493 |
## Transitional variables |
494 |
tie %main::form, 'wiki::transitional::uri_param', $wiki->{input}; |
495 |
$main::UA = $wiki->{var}->{client}->{user_agent_name}; |
496 |
$main::form{mypage} = join '//', @{$wiki->{var}->{page}}; |
497 |
$main::form{mycmd} = $mode; |
498 |
}; |
499 |
|
500 |
$WIKI->init_variables; |
501 |
|
502 |
$WIKI->init_plugin; |
503 |
$WIKI->init_view; |
504 |
$WIKI->{plugin}->use_type ('view-definition'); |
505 |
$WIKI->{view}->register_common_modes; |
506 |
my $opt = {condition => {mode => $WIKI->{var}->{mode}, output => 'http-cgi', |
507 |
http_method => $main::ENV{REQUEST_METHOD}}}; |
508 |
my $viewobj = $WIKI->{view}->instantiate ($WIKI->{var}->{mode}, $opt); |
509 |
$viewobj->main ($opt); ## TODO: or unsupported mode |
510 |
|
511 |
exit; |
512 |
END { |
513 |
$WIKI->exit; |
514 |
} |
515 |
|
516 |
=head1 NAME |
517 |
|
518 |
lib/suikawiki.pl --- SuikaWiki transitional library |
519 |
|
520 |
=head1 AUTHOR |
521 |
|
522 |
Hiroshi Yuki <hyuki@hyuki.com> <http://www.hyuki.com/yukiwiki/> (YukiWiki) |
523 |
|
524 |
Makio Tsukamoto <http://digit.que.ne.jp/> (WalWiki) |
525 |
|
526 |
Wakaba <w@suika.fam.cx> |
527 |
|
528 |
=head1 LICENSE |
529 |
|
530 |
Copyright AUTHORS 2000-2003 |
531 |
|
532 |
This program is free software; you can redistribute it and/or |
533 |
modify it under the same terms as Perl itself. |
534 |
|
535 |
=cut |
536 |
|
537 |
1; # $Date: 2003/10/05 11:50:40 $ |