225 |
|
|
226 |
package main; |
package main; |
227 |
our $VERSION = do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
our $VERSION = do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
228 |
push @{$WIKI->{event}->{setting_initial_variables}}, sub { |
|
229 |
my $wiki = shift; |
$WIKI->{implementation_version} = 'hcs'.$VERSION; |
|
$wiki->{implementation_version} = 'hcs'.$VERSION; |
|
230 |
|
|
231 |
## Error output |
## Error output |
232 |
require SuikaWiki::Output::CGICarp; |
require SuikaWiki::Output::CGICarp; |
236 |
my $msg = shift; |
my $msg = shift; |
237 |
#$msg =~ s/&/&/g; |
#$msg =~ s/&/&/g; |
238 |
#$msg =~ s/</</g; |
#$msg =~ s/</</g; |
239 |
my $wiki_name_version = $wiki->{implementation_name} .'/'. $wiki->version; |
my $wiki_name_version = $WIKI->{implementation_name} .'/'. $WIKI->version; |
240 |
for ($wiki_name_version) { s/&/&/g; s/</</g; |
for ($wiki_name_version) { s/&/&/g; s/</</g; |
241 |
s/([^\x20-\x7E])/sprintf '&#x%02X;', |
s/([^\x20-\x7E])/sprintf '&#x%02X;', |
242 |
ord $1/g; }; |
ord $1/g; }; |
249 |
EOH |
EOH |
250 |
}); |
}); |
251 |
|
|
252 |
|
push @{$WIKI->{event}->{setting_initial_variables}}, sub { |
253 |
|
my $wiki = shift; |
254 |
$wiki->{var}->{db}->{read_only}->{'#default'} = 1; |
$wiki->{var}->{db}->{read_only}->{'#default'} = 1; |
255 |
|
|
256 |
require SuikaWiki::Input::HTTP; |
require SuikaWiki::Input::HTTP; |
257 |
$wiki->{input} = SuikaWiki::Input::HTTP->new; |
$wiki->{input} = SuikaWiki::Input::HTTP->new (wiki => $wiki); |
258 |
$wiki->{input}->{decoder}->{'#default'} = sub { |
$wiki->{input}->{decoder}->{'#default'} = sub { |
259 |
my ($http, $s, $temp_params) = @_; |
my ($http, $s, $temp_params) = @_; |
260 |
return main::code_convert (\$s, $wiki->{config}->{charset}->{internal}, |
return main::code_convert (\$s, $wiki->{config}->{charset}->{internal}, |
264 |
$wiki->{var}->{client}->{user_agent_name} |
$wiki->{var}->{client}->{user_agent_name} |
265 |
= $wiki->{input}->meta_variable ('HTTP_USER_AGENT'); |
= $wiki->{input}->meta_variable ('HTTP_USER_AGENT'); |
266 |
$wiki->{var}->{client}->{used_for_negotiate} = ['User-Agent']; |
$wiki->{var}->{client}->{used_for_negotiate} = ['User-Agent']; |
267 |
|
my $dg = SuikaWiki::Plugin->module_package ('Downgrade'); |
268 |
|
$dg->set_downgrade_flags ($wiki) if $dg; |
269 |
|
|
270 |
## TODO: PATH_INFO support |
## TODO: PATH_INFO support |
271 |
my $page = $wiki->{input}->meta_variable ('QUERY_STRING'); |
my $page = $wiki->{input}->meta_variable ('QUERY_STRING'); |
305 |
push @{$wiki->{var}->{client}->{used_for_negotiate}}, 'Cookie'; |
push @{$wiki->{var}->{client}->{used_for_negotiate}}, 'Cookie'; |
306 |
} |
} |
307 |
$wiki->{var}->{mode} = $mode; |
$wiki->{var}->{mode} = $mode; |
|
|
|
|
## Transitional variables |
|
|
tie %main::form, 'wiki::transitional::uri_param', $wiki->{input}; |
|
|
$main::UA = $wiki->{var}->{client}->{user_agent_name}; |
|
|
$main::form{mypage} = join '//', @{$wiki->{var}->{page}}; |
|
|
$main::form{mycmd} = $mode; |
|
308 |
}; |
}; |
309 |
|
|
310 |
|
{ |
311 |
|
my $error_report = sub { |
312 |
|
my ($wiki, $err) = @_; |
313 |
|
my $report = ($err->{-def}->{level} eq 'fatal' or |
314 |
|
$err->{-def}->{level} eq 'stop' or |
315 |
|
$wiki->{config}->{debug}->{db}) ? 1 : 0; |
316 |
|
if ($report and $wiki->{config}->{path_to}->{db__content__error_log}) { |
317 |
|
my $err_msg = caller (1).($err->{-method}? '->'.$err->{-method}: '').': ' |
318 |
|
.(defined $err->{-file}? $err->{-file} . ': ' : '') |
319 |
|
.(defined $err->{-prop}? $err->{-prop} . ': ' : '') |
320 |
|
.(defined $err->{-key}? join ('//', @{$err->{-key}}).': ':'') |
321 |
|
. $err->text; |
322 |
|
open LOG, '>>', $wiki->{config}->{path_to}->{db__content__error_log}; |
323 |
|
print LOG scalar (gmtime), " @{[$$]} {$err->{-def}->{level}}: ", |
324 |
|
$err_msg, "\n"; |
325 |
|
close LOG; |
326 |
|
} |
327 |
|
SuikaWiki::Plugin->module_package ('WikiDB') |
328 |
|
->reporting_error ($err, $wiki) if $report; |
329 |
|
if ($err->{-def}->{level} eq 'fatal' or $err->{-def}->{level} eq 'stop') { |
330 |
|
$wiki->view_in_mode (mode => '-wdb--fatal-error'); |
331 |
|
throw SuikaWiki::DB::Util::Error -type => 'ERROR_REPORTED'; |
332 |
|
} |
333 |
|
}; |
334 |
|
unshift @{$WIKI->{event}->{database_loaded}}, sub { |
335 |
|
my $wiki = shift; |
336 |
|
unshift @{$wiki->{db}->{event}->{error}}, sub { |
337 |
|
my ($db, $event) = @_; |
338 |
|
$error_report->($wiki, $event->{error}); |
339 |
|
if ($event->{error}->{-type} eq 'INFO_DB_PROP_OPENED') { |
340 |
|
unshift @{$db->{prop}->{$event->{error}->{prop}}->{-db} |
341 |
|
->{event}->{error}}, sub { |
342 |
|
my ($db, $event) = @_; |
343 |
|
$error_report->($wiki, $event->{error}); |
344 |
|
}; |
345 |
|
} |
346 |
|
}; # database error |
347 |
|
}; # database_loaded |
348 |
|
} |
349 |
|
|
350 |
|
if ($WIKI->{config}->{debug}->{general}) { |
351 |
|
$main::SIG{__WARN__} = sub { |
352 |
|
push @{$WIKI->{var}->{error}||=[]}, { |
353 |
|
description => Message::Markup::XML::Node->new |
354 |
|
(type => '#text', |
355 |
|
value => $_[0]), |
356 |
|
}; |
357 |
|
}; |
358 |
|
} |
359 |
|
|
360 |
push @{$WIKI->{event}->{view_in_mode}}, sub { |
push @{$WIKI->{event}->{view_in_mode}}, sub { |
361 |
my ($wiki, $opt) = @_; |
my ($wiki, $opt) = @_; |
362 |
my $arg = {condition => {mode => $opt->{mode} || '-error', |
my $arg = {condition => {mode => $opt->{mode} || '-error', |
373 |
} |
} |
374 |
}; |
}; |
375 |
|
|
376 |
## Initialization of various functions |
$WIKI->init_plugin; ## WikiPlugin manager |
377 |
$WIKI->init_variables; |
$WIKI->init_view; ## WikiView manager |
|
$WIKI->init_plugin; |
|
|
$WIKI->init_view; |
|
378 |
$WIKI->{view}->register_common_modes; |
$WIKI->{view}->register_common_modes; |
379 |
|
|
380 |
## Error handlers |
## Error handlers |
381 |
use SuikaWiki::DB::Util::Error; |
use SuikaWiki::DB::Util::Error; |
382 |
my $catcher = catch SuikaWiki::DB::Util::Error with { |
my $catcher = catch SuikaWiki::DB::Util::Error with { |
383 |
my $err = shift; |
my $err = shift; |
384 |
my $err_msg = $err->text; |
exit if $err->{-type} eq 'ERROR_REPORTED'; |
385 |
$err_msg = caller (3) . '-->' . caller (2) . '-->' . caller (1) |
$err->throw; |
|
. ($err->{-method} ? '->'.$err->{-method} : '') |
|
|
. ': ' |
|
|
. (defined $err->{-file} ? $err->{-file} . ': ' : '') |
|
|
. (defined $err->{-prop} ? $err->{-prop} . ': ' : '') |
|
|
. (defined $err->{-key} ? join ('//', @{$err->{-key}}) . ': ' : '') |
|
|
. $err_msg; |
|
|
if ($WIKI->{config}->{path_to}->{db__content__error_log}) { |
|
|
open LOG, '>>', $WIKI->{config}->{path_to}->{db__content__error_log}; |
|
|
print LOG scalar (gmtime), " @{[$$]} {$err->{def}->{level}}: ", |
|
|
$err_msg, "\n"; |
|
|
close LOG; |
|
|
} |
|
|
if ($err->{def}->{level} eq 'fatal' or $err->{def}->{level} eq 'stop') { |
|
|
require Carp; |
|
|
local $Carp::Verbose = 1; |
|
|
Carp::croak $err_msg; |
|
|
} |
|
386 |
} catch SuikaWiki::View::Implementation::error with { |
} catch SuikaWiki::View::Implementation::error with { |
387 |
my $err = shift; |
my $err = shift; |
388 |
exit if $err->{type} eq 'ERROR_REPORTED'; |
exit if $err->{-type} eq 'ERROR_REPORTED'; |
389 |
$err->throw; |
$err->throw; |
390 |
}; |
}; |
391 |
|
|
397 |
->reporting_formatting_template_error ($err, $wiki); |
->reporting_formatting_template_error ($err, $wiki); |
398 |
$wiki->view_in_mode (mode => '-error', method => 'GET'); |
$wiki->view_in_mode (mode => '-error', method => 'GET'); |
399 |
throw SuikaWiki::View::Implementation::error |
throw SuikaWiki::View::Implementation::error |
400 |
type => 'ERROR_REPORTED'; |
-type => 'ERROR_REPORTED'; |
401 |
}; |
}; |
402 |
|
|
403 |
$WIKI->{config}->{catch}->{formatter_view_error} |
$WIKI->{config}->{catch}->{formatter_view_error} |
408 |
->reporting_formatting_template_error ($err, $wiki); |
->reporting_formatting_template_error ($err, $wiki); |
409 |
$wiki->view_in_mode (mode => '-error-error', method => 'GET'); |
$wiki->view_in_mode (mode => '-error-error', method => 'GET'); |
410 |
throw SuikaWiki::View::Implementation::error |
throw SuikaWiki::View::Implementation::error |
411 |
type => 'ERROR_REPORTED'; |
-type => 'ERROR_REPORTED'; |
412 |
}; |
}; |
413 |
|
|
414 |
## Main |
## Main |
415 |
|
$WIKI->init_variables; ## Per-session variables |
416 |
try { |
try { |
417 |
$WIKI->view_in_mode |
$WIKI->view_in_mode |
418 |
(mode => $WIKI->{var}->{mode}, |
(mode => $WIKI->{var}->{mode}, |