/[pub]/suikawiki/script/lib/suikawiki.pl
Suika

Contents of /suikawiki/script/lib/suikawiki.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (hide annotations) (download)
Sat Oct 18 07:08:34 2003 UTC (21 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.14: +206 -366 lines
File MIME type: text/plain
Imporoved SuikaWiki 3 implementation

1 wakaba 1.1 use strict;
2    
3 wakaba 1.12 package wiki;
4 wakaba 1.15 our $VERSION = do{my @r=(q$Revision: 1.14 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
5 wakaba 1.1 package main;
6     binmode STDOUT; binmode STDIN;
7 wakaba 1.14
8 wakaba 1.1 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 w 1.9 require SuikaWiki::Name::Space;
15 wakaba 1.5 my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
16 wakaba 1.14 our $WIKI;
17 wakaba 1.15 require Message::Markup::XML;
18 wakaba 1.1
19     sub _do_view_msg (%) {
20 w 1.9 require SuikaWiki::View;
21 wakaba 1.1 my %option = @_;
22 wakaba 1.15 my $o = $option{-o} || bless {param => \%main::form, page => $option{-page},
23 w 1.9 &_compatible_options ()}, 'SuikaWiki::Plugin';
24     $o->{toc} = [];
25     $o->{condition} = \%option; ## This parameter really used??
26 wakaba 1.3 my $view_def = SuikaWiki::View->definition ($option{-view});
27     unless ($view_def->check ($o)) {
28 wakaba 1.1 print "Status: 406 Unsupported Media Type\n";
29     $option{-view} = '-UnsupportedMediaType';
30 wakaba 1.3 $view_def = SuikaWiki::View->definition ($option{-view});
31 wakaba 1.1 }
32 w 1.9 my $prop = $view_def->properties;
33     my $media = $prop->{media};
34 wakaba 1.15 if ($prop->{xmedia} && $main::UA =~ /Gecko/) {
35 w 1.9 $media = $prop->{xmedia};
36 wakaba 1.1 $o->{media} = $media;
37     }
38 w 1.9 &print_header($option{-page}, -media => $media, -view => $view_def, o => $o, -goto => $option{-goto});
39 wakaba 1.15 print "\n";
40 w 1.9 ## Output HTTP message body
41     my $fmt = SuikaWiki::Plugin->formatter ('view');
42     my $s = $fmt->replace ($view_def->as_string => $o, {formatter => $fmt});
43 wakaba 1.15 print $s;
44 wakaba 1.1 }
45    
46 wakaba 1.15 =pod
47    
48 w 1.9 # [move to SuikaWiki::Plugin::WikiAdmin]
49 wakaba 1.1 sub do_adminchangepassword {
50 wakaba 1.15 if ($main::form{mynewpassword} ne $main::form{mynewpassword2}) {
51     &_do_view_msg (-view => '-error', -page => $main::form{mypage},
52 wakaba 1.1 error_message => &Resource ('Error:PasswordMismatch'));
53     return;
54     }
55 wakaba 1.15 my ($validpassword_crypt) = $main::database->meta (AdminPassword => $PageName{AdminSpecialPage});
56 wakaba 1.1 if ($validpassword_crypt) {
57 wakaba 1.15 if (not &valid_password($main::form{myoldpassword})) {
58     &_do_view_msg (-view => '-error', -page => $main::form{mypage},
59 wakaba 1.1 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 wakaba 1.15 my $crypted = crypt($main::form{mynewpassword}, "$salt1$salt2");
68     $main::database->meta (AdminPassword => $main::PageName{AdminSpecialPage} => $crypted);
69 wakaba 1.1
70 wakaba 1.15 &_do_view_msg (-view => '-wrote', -page => $main::form{mypage});
71 wakaba 1.1 }
72    
73 wakaba 1.15 =cut
74    
75 w 1.9 # [move to SuikaWiki::WikiDB]
76 wakaba 1.1 sub valid_password ($) {
77 wakaba 1.15 return 0;
78     # my ($validpassword_crypt) = $main::database->meta (AdminPassword => $PageName{AdminSpecialPage});
79     # return crypt (shift, $validpassword_crypt) eq $validpassword_crypt ? 1 : 0;
80 wakaba 1.1 }
81    
82 wakaba 1.15 ## [obsolete] BugTrack, RandomJump
83 w 1.9 sub _http_see_other (%) {
84     my %o = @_;
85 wakaba 1.14 $o{page} = join '//', @{$o{page}} if ref $o{page};
86 wakaba 1.10 $o{uri} ||= SuikaWiki::Plugin->_uri_wiki_page ($o{page}, absolute => 1);
87 wakaba 1.14 if ($o{alternate_view} && ($main::ENV{SERVER_PROTOCOL} eq 'HTTP/1.0')
88     && !($main::UA =~ m#M(?:ozilla|icrosoft Internet Explorer)#)) {
89 w 1.9 &_do_view_msg (-view => $o{alternate_view}, -page => $o{page}, -goto => $o{uri}, -o => $o{o});
90     } else {
91 wakaba 1.15 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 w 1.9 }
96 wakaba 1.14 exit;
97 w 1.9 }
98    
99 wakaba 1.15 # temp
100     sub is_editable { 1 }
101    
102 wakaba 1.1 sub _compatible_options () {
103 wakaba 1.10 (use_anchor_name => ($main::UA =~ m#Mozilla/[1-4]\.|Microsoft Internet Explorer# ? 1 : 0));
104 wakaba 1.1 }
105    
106 w 1.9
107 wakaba 1.1
108     sub print_header ($;%) {
109     my ($page, %option) = @_;
110 w 1.9 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 wakaba 1.14 exit;
122 w 1.9 }
123     }
124     }
125 wakaba 1.15 #my $UA = SuikaWiki::Plugin->user_agent_names;
126 wakaba 1.8 $option{o}->{-header}->{class}->{frozen} = 1 if &main::is_frozen ($page);
127 w 1.9 $option{o}->{-header}->{class}->{'wiki-page-obsoleted'} = 1 if $option{-magic} =~ /obsoleted="yes"/;
128 wakaba 1.8 $option{o}->{-header}->{additional_html_element} ||= SuikaWiki::Markup::XML->new (type => '#fragment');
129 wakaba 1.14 #print "Vary: Negotiate,User-Agent,Accept-Language,Accept\n";
130 wakaba 1.1 if ($option{-goto}) {
131 wakaba 1.15 if ($main::UA =~ m#Opera|MSIE 2\.#) {
132 wakaba 1.8 ## WARNING: This code may output unsafe HTML document if $option{-goto} is unclean.
133 wakaba 1.15 $option{-goto} =~ tr/;/&/ if $main::UA =~ m#Opera#;
134 wakaba 1.8 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 wakaba 1.10 $_->option (use_EmptyElemTag => 1);
140 wakaba 1.8 }
141 wakaba 1.1 } else {
142 wakaba 1.15 $option{-goto} =~ tr/;/&/ if $main::UA =~ m#Mozilla/[1-4]\.#;
143 wakaba 1.8 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 wakaba 1.10 $_->option (use_EmptyElemTag => 1);
149 wakaba 1.8 }
150 wakaba 1.1 }
151     }
152 wakaba 1.8 print qq{Last-Modified: @{[scalar gmtime $option{-last_modified}]}\n}
153     if $option{-last_modified};
154 wakaba 1.1 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 wakaba 1.15 if ($option{-media}->{charset} && $main::UA =~ m#Mozilla/[12]\.#) {
162 wakaba 1.8 ## 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 wakaba 1.15 } elsif (!$option{-media}->{charset} || $main::UA =~ m#Infomosaic|Mozilla/0\.#) {
171 wakaba 1.8 ## 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 wakaba 1.1 } else {
181 wakaba 1.8 ## Modern UAs and Media types with charset parameter
182     my $type = $option{-media}->{type};
183 wakaba 1.15 $type = 'application/xml' if ($type =~ m!^application/rdf\+xml$!) && ($main::UA =~ m#Gecko#);
184 wakaba 1.8 print qq{Content-Type: $type; charset=@{[&main::get_charset_name ($main::kanjicode)]}\n};
185     ## meta element is not needed
186 wakaba 1.1 }
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 w 1.9 # [move to SuikaWiki::WikiDB]
203 wakaba 1.1 sub frozen_reject {
204 wakaba 1.15 my ($isfrozen) = $main::database->meta (IsFrozen => $main::form{mypage});
205     my ($willbefrozen) = $main::form{myfrozen};
206 wakaba 1.1 if (not $isfrozen and not $willbefrozen) {
207     # You need no check.
208     return 0;
209 wakaba 1.15 } elsif (valid_password($main::form{mypassword})) {
210 wakaba 1.1 # You are admin.
211     return 0;
212     } else {
213 wakaba 1.15 &_do_view_msg (-view => '-error', -page => $main::form{mypage},
214 wakaba 1.8 error_message => SuikaWiki::Plugin->resource ('Error:PasswordIsIncorrect'));
215 wakaba 1.1 exit;
216     }
217     }
218    
219 w 1.9 # [move to SuikaWiki::WikiDB]
220 wakaba 1.8 sub is_frozen ($) { SuikaWiki::Plugin->_database->meta (IsFrozen => $_[0]) ? 1 : 0 }
221 wakaba 1.1
222 w 1.9 # [to be obsolete]
223 wakaba 1.1 sub do_comment {
224 wakaba 1.15 my ($content) = $main::database{$main::form{mypage}};
225 wakaba 1.1 my $default_name; ## this code is not strict.
226     $default_name = $1 if $content =~ /default-name="([^"]+)"/;
227 w 1.9 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 wakaba 1.15 my $namestr = $main::form{myname} || $default_name || &Resource('WikiForm:WikiComment:DefaultName');
230     ($namestr = '', $datestr = '') if $main::form{myname} eq 'nodate';
231 wakaba 1.1 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 wakaba 1.15 if ($i == $main::form{comment_index}) {
241 wakaba 1.1 if ($embed ne '[[#rcomment]]') {
242 wakaba 1.15 $embed = "- [$anchor] $datestr$namestr$main::form{mymsg}\n$embed"; $o = 1;
243 wakaba 1.1 } else {
244 wakaba 1.15 $embed .= "\n- [$anchor] $datestr$namestr$main::form{mymsg}"; $o = 1;
245 wakaba 1.1 }
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 wakaba 1.15 $content .= "- [$anchor] $datestr$namestr$main::form{mymsg}\n";
253 wakaba 1.1 }
254 wakaba 1.15 $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 wakaba 1.1 &do_write;
259     } else { ## Don't write
260 wakaba 1.15 #$main::form{mycmd} = 'default';
261     #&do_view;
262     die "No comment specified";
263 wakaba 1.1 }
264     }
265    
266 w 1.9 # [move to SuikaWiki::Plugin::WikiForm]
267 wakaba 1.1 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 w 1.9 # [move to SuikaWiki::Plugin::WikiForm]
275 wakaba 1.1 sub do_wikiform {
276 wakaba 1.15 my $content = $main::database{$main::form{mypage}};
277 wakaba 1.1 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 wakaba 1.15 if (($wfname && $wfname eq $main::form{wikiform_targetform})
283     || $i == $main::form{wikiform_index}) {
284 wakaba 1.1 $template =~ s/\\([\\'])/$1/g;
285     $option =~ s/\\([\\'])/$1/g;
286     my $param = bless {depth=>10}, 'SuikaWiki::Plugin';
287 wakaba 1.15 $param->{page} = $main::form{mypage};
288 wakaba 1.1 $param->{form_index} = $i;
289     $param->{form_name} = $wfname;
290     $param->{anchor_index} = $anchor;
291 wakaba 1.15 $param->{argv} = \%main::form;
292 wakaba 1.1 $param->{default_name} = $1 if $content =~ /default-name="([^"]+)"/;
293     $param->{default_name} ||= &Resource('WikiForm:WikiComment:DefaultName');
294 w 1.9 SuikaWiki::Plugin->formatter ('form_option')->replace ($option, $param);
295 wakaba 1.1 my $t = 1;
296     for (keys %{$param->{require}||{}}) {
297     (undef $t, last) unless length $param->{argv}->{'wikiform__'.$_};
298     }
299 w 1.9 $t = SuikaWiki::Plugin->formatter ('form_template')->replace ($template, $param) if $t;
300 wakaba 1.1 if (length $t) {
301     if ($param->{output}->{reverse}) {
302     $embed .= "\n" . $t;
303     } else {
304     $embed = $t . "\n" . $embed;
305     }
306     $write = 1;
307 wakaba 1.15 $main::form{__comment_anchor_index} = $anchor
308 wakaba 1.1 if $param->{anchor_index_}; ## $anchor is used!
309     }
310 wakaba 1.15 $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 wakaba 1.1 }
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 wakaba 1.15 $main::form{mymsg} = $content;
323     $main::form{mytouch} = 'on';
324 wakaba 1.1 &do_write;
325     } else { ## Don't write!
326 wakaba 1.15 #$main::form{mycmd} = 'default';
327     #&do_view;
328     die "No content specified";
329 wakaba 1.1 }
330     }
331    
332 w 1.9 # [to be obsolete] ->Message::MIME::Charset
333 wakaba 1.1 sub code_convert {
334     require Jcode;
335 wakaba 1.15 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 wakaba 1.1 }
351    
352 w 1.9 # [to be obsolete] ->Message::Field::Date
353 wakaba 1.1 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 wakaba 1.15 # [obsolete] ->SuikaWiki::SrcFormat : SuikaWiki09 plugin
359 w 1.9 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 wakaba 1.15 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 w 1.9
414 wakaba 1.1 package main;
415 wakaba 1.15 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/&/&amp;/g;
426     #$msg =~ s/</&lt;/g;
427     my $wiki_name_version = $wiki->{implementation_name} .'/'. $wiki->version;
428     for ($wiki_name_version) { s/&/&amp;/g; s/</&lt;/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 wakaba 1.14 $WIKI->init_plugin;
503     $WIKI->init_view;
504     $WIKI->{plugin}->use_type ('view-definition');
505     $WIKI->{view}->register_common_modes;
506 wakaba 1.15 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 wakaba 1.14 $viewobj->main ($opt); ## TODO: or unsupported mode
510    
511     exit;
512     END {
513     $WIKI->exit;
514     }
515 wakaba 1.1
516     =head1 NAME
517    
518 wakaba 1.4 lib/suikawiki.pl --- SuikaWiki transitional library
519 wakaba 1.1
520     =head1 AUTHOR
521    
522 wakaba 1.4 Hiroshi Yuki <hyuki@hyuki.com> <http://www.hyuki.com/yukiwiki/> (YukiWiki)
523 wakaba 1.1
524 wakaba 1.4 Makio Tsukamoto <http://digit.que.ne.jp/> (WalWiki)
525 wakaba 1.1
526     Wakaba <w@suika.fam.cx>
527    
528     =head1 LICENSE
529    
530 wakaba 1.4 Copyright AUTHORS 2000-2003
531 wakaba 1.1
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 wakaba 1.15 1; # $Date: 2003/10/05 11:50:40 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24