27 |
} |
} |
28 |
use Message::Util::Error; |
use Message::Util::Error; |
29 |
|
|
30 |
|
use Message::Util::QName::General [q<ExpandedURI>], { |
31 |
|
'bt' => q<http://suika.fam.cx/~wakaba/archive/2004/8/11/sw-bt#>, |
32 |
|
'log' => q<http://suika.fam.cx/~wakaba/-temp/2004/05/01/reqlog#>, |
33 |
|
'media-type' => q<http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt#>, |
34 |
|
'pe' => q<http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit#>, |
35 |
|
'relrev' => q<http://suika.fam.cx/~wakaba/archive/2004/7/25/html-relrev#>, |
36 |
|
'ss' => q<http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet#>, |
37 |
|
'sw' => q<http://suika.fam.cx/~wakaba/archive/2004/7/20/sw#>, |
38 |
|
'sw09' => q<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SuikaWiki%2F0.9#>, |
39 |
|
}; |
40 |
|
|
41 |
|
BEGIN { |
42 |
|
if ($main::ENV{REQUEST_URI} =~ /\#/) { |
43 |
|
require SuikaWiki::Output::HTTP; |
44 |
|
my $out = SuikaWiki::Output::HTTP->new; |
45 |
|
$out->{status_code} = 401; |
46 |
|
$out->{status_phrase} = q<Request-URI MUST NOT have Fragment Identifier>; |
47 |
|
$out->{entity}->{media_type} = q<text/html>; |
48 |
|
$out->{entity}->{charset} = q<iso-8859-1>; |
49 |
|
$out->{entity}->{language} = [q<en>]; |
50 |
|
$out->{entity}->{body_is_octet_stream} = 1; |
51 |
|
my $ua = $main::ENV{HTTP_USER_AGENT}; |
52 |
|
for ($ua) { |
53 |
|
s/&/&/g; s/</</g; s/([^\x20-\x7E])/sprintf '&#x%02X;', ord $1/ge; |
54 |
|
}; |
55 |
|
$out->{entity}->{body} = qq< |
56 |
|
<!DOCTYPE html SYSTEM> |
57 |
|
<title>401 Bad Request-URI</title> |
58 |
|
<h1>Bad Request-URI</h1> |
59 |
|
<p>Your Request-URI has fragment identifier but it is not allowed here. |
60 |
|
It might be a bug of your user agent ($ua). Please contact to the UA |
61 |
|
vendor.</p> |
62 |
|
>; |
63 |
|
$out->output (output => 'http-cgi'); |
64 |
|
exit; |
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
push our @Config, sub ($) { |
push our @Config, sub ($) { |
69 |
my $WIKI = shift; |
my $WIKI = shift; |
70 |
use Cwd qw(abs_path); |
use FindBin q($Bin); |
71 |
|
use File::Spec; |
72 |
|
|
73 |
## -- Filesystem path mapping |
## -- Filesystem path mapping |
74 |
for ( |
for ( |
75 |
[db__cache__dir => q"./wikidata/lock/"], |
[db__cache__dir => q"./wikidata/cache/"], |
76 |
[db__cache_struct__file => q"./wikidata/lock/struct.db"], |
[db__cache_struct__file => q"./wikidata/cache/struct.db"], |
77 |
[db__content__dir => q"./wikidata/page/"], |
[db__content__dir => q"./wikidata/page/"], |
78 |
[db__content__error_log => q"./wikidata/log/db-content.log"], |
[db__content__error_log => q"./wikidata/log/db-content.log"], |
79 |
[db__bdb__home_dir => q"./wikidata/lock/"], |
[db__bdb__home_dir => q"./wikidata/lock/"], |
83 |
[db__lock__dir => q"./wikidata/lock/"], |
[db__lock__dir => q"./wikidata/lock/"], |
84 |
[db__lock__log_file => q"./wikidata/log/lock.log"], |
[db__lock__log_file => q"./wikidata/log/lock.log"], |
85 |
[db__log__dir => q"./wikidata/log/"], |
[db__log__dir => q"./wikidata/log/"], |
86 |
|
[db__request_log__dir => q"./wikidata/rlog/"], |
87 |
|
[db__static__dir => q"./wikidata/static/"], |
88 |
[db__temp__dir => q"./wikidata/lock/"], |
[db__temp__dir => q"./wikidata/lock/"], |
89 |
[namazu__index_dir => q"/var/namazu/index/suikawiki"], |
[namazu__index_dir => q"/var/namazu/index/suikawiki"], |
90 |
) { |
) { |
91 |
## On system that does not set current directory as main script |
## On system that does not set current directory as main script |
92 |
## directory, you should specify it instead of using "abs_path". |
## directory, you should specify it instead of using "abs_path". |
93 |
$WIKI->{config}->{path_to}->{$_->[0]} = abs_path $_->[1]; |
$WIKI->{config}->{path_to}->{$_->[0]} = File::Spec->rel2abs ($_->[1], $Bin); |
94 |
} |
} |
95 |
|
|
96 |
## -- Namazu URI Mapping (See SuikaWiki:SuikaWiki//Namazu) -- |
## -- Namazu URI Mapping (See SuikaWiki:SuikaWiki//Namazu) -- |
133 |
|
|
134 |
## Main content |
## Main content |
135 |
$wiki->{db}->_set_prop_db (content => {-db_open => sub { |
$wiki->{db}->_set_prop_db (content => {-db_open => sub { |
136 |
require SuikaWiki::DB::FileSystem::YukiWikiDBNS; |
require SuikaWiki::DB::FileSystem::LeafFile; |
137 |
SuikaWiki::DB::FileSystem::YukiWikiDBNS->new |
SuikaWiki::DB::FileSystem::LeafFile->new |
138 |
(directory => $wiki->{config}->{path_to}->{db__content__dir}, |
(base_directory => $wiki->{config}->{path_to}->{db__content__dir}, |
139 |
logfile => $wiki->{config}->{path_to}->{db__content__error_log}, |
directory_suffix => '.ns', |
140 |
suffix => '.txt', |
file_suffix => '.txt', |
141 |
root_key => $wiki->{config}->{page}->{Default}, |
root_key => $wiki->{config}->{page}->{Default}, |
142 |
-lock => $wiki->{var}->{db}->{lock_prop}->('content')); |
-lock => $wiki->{var}->{db}->{lock_prop}->('content')); |
143 |
}, -db_close => sub { |
}, -db_close => sub { |
144 |
my %opt = @_; |
my %opt = @_; |
145 |
$opt{prop_info}->{-db}->close; |
$opt{prop_info}->{-db}->close; |
146 |
delete $opt{prop_info}->{-db}; |
delete $opt{prop_info}->{-db}; |
147 |
}}); |
}}); |
148 |
|
|
149 |
|
## Properties |
150 |
|
$wiki->{db}->_set_prop_db (content_prop => {-db_open => sub { |
151 |
|
require SuikaWiki::DB::FileSystem::LeafProp; |
152 |
|
SuikaWiki::DB::FileSystem::LeafProp->new |
153 |
|
(base_directory => $wiki->{config}->{path_to}->{db__content__dir}, |
154 |
|
directory_suffix => '.ns', |
155 |
|
file_suffix => '.prop', |
156 |
|
root_key => $wiki->{config}->{page}->{Default}, |
157 |
|
-lock => $wiki->{var}->{db}->{lock_prop}->('content_prop')); |
158 |
|
}, -db_close => sub { |
159 |
|
my %opt = @_; |
160 |
|
$opt{prop_info}->{-db}->close; |
161 |
|
delete $opt{prop_info}->{-db}; |
162 |
|
}}); |
163 |
|
|
164 |
## Last modified |
## Last modified |
165 |
$wiki->{db}->_set_prop_db (lastmodified => {-db_open => sub { |
$wiki->{db}->_set_prop_db (lastmodified => {-db_open => sub { |
173 |
delete $opt{prop_info}->{-db}; |
delete $opt{prop_info}->{-db}; |
174 |
}}); |
}}); |
175 |
|
|
176 |
|
## Static version |
177 |
|
$wiki->{db}->_set_prop_db (static__css => {-db_open => sub { |
178 |
|
require SuikaWiki::DB::FileSystem::LeafFileP; |
179 |
|
SuikaWiki::DB::FileSystem::LeafFileP->new |
180 |
|
(base_directory => $wiki->{config}->{path_to}->{db__static__dir}, |
181 |
|
directory_suffix => '.ns', |
182 |
|
file_suffix => '.css', |
183 |
|
root_key => $wiki->{config}->{page}->{Default}); |
184 |
|
}, -db_close => sub { |
185 |
|
my %opt = @_; |
186 |
|
$opt{prop_info}->{-db}->close; |
187 |
|
delete $opt{prop_info}->{-db}; |
188 |
|
}}); |
189 |
|
$wiki->{config}->{ExpandedURI q<ss:use-static>} = 1; |
190 |
|
## URI maker for LeafFileP generated files |
191 |
|
$wiki->{config}->{ExpandedURI q<ss:wikiname-to-uri>} = sub { |
192 |
|
my (undef, %opt) = @_; |
193 |
|
my $page = join '.ns/', |
194 |
|
map {s/([^0-9A-Za-z_-])/sprintf '+%02X', ord $1/ge;$_} |
195 |
|
@{$opt{wikiname}}; |
196 |
|
return URI->new ('wikidata/static/' . $page . '.css' . |
197 |
|
($opt{lm} ? '?x-lm=' . $opt{lm} : '')); |
198 |
|
}; |
199 |
|
## Reverse mapping of generate-uri |
200 |
|
$wiki->{config}->{ExpandedURI q<ss:uri-to-wikiname>} = sub { |
201 |
|
my (undef, %opt) = @_; |
202 |
|
$opt{uri} =~ s!^.+/wikidata/static/!!g; |
203 |
|
$opt{uri} =~ s/\?[^?]*$//g; |
204 |
|
$opt{uri} =~ s/\.css$//g; |
205 |
|
return $opt{wiki}->name |
206 |
|
([map {s/\+([0-9A-Fa-f_-][0-9A-Fa-f_-])/pack 'CC', hex $1/ge;$_} |
207 |
|
split m!.ns/!, $opt{uri}]); |
208 |
|
}; |
209 |
|
|
210 |
|
|
211 |
## Cache DBs |
## Cache DBs |
212 |
require SuikaWiki::DB::FileSystem::SuikaWikiCache09; |
require SuikaWiki::DB::FileSystem::SuikaWikiCache09; |
213 |
my $cachedb = SuikaWiki::DB::FileSystem::SuikaWikiCache09->new |
my $cachedb = SuikaWiki::DB::FileSystem::SuikaWikiCache09->new |
261 |
|
|
262 |
## Referer Database (See Referer plugin module) |
## Referer Database (See Referer plugin module) |
263 |
$wiki->{db}->_set_prop_db (referer => {-db_open => sub { |
$wiki->{db}->_set_prop_db (referer => {-db_open => sub { |
264 |
require SuikaWiki::DB::Hash; |
require SuikaWiki::DB::FileSystem::Count; |
265 |
new SuikaWiki::DB::Hash constructor => sub { |
SuikaWiki::DB::FileSystem::Count->new |
266 |
tie my %db, 'BerkeleyDB::Hash', |
(base_directory => $wiki->{config}->{path_to}->{db__content__dir}, |
267 |
-Filename => 'referer.db', |
directory_suffix => '.ns', |
268 |
-Env => $bdbenv, |
file_suffix => '.ref', |
269 |
-Flags => DB_CREATE, |
root_key => $wiki->{config}->{page}->{Default}, |
270 |
-Mode => 0644; |
auto_mkdir => 0, |
271 |
\%db; |
-lock => $wiki->{var}->{db}->{lock_prop}->('referer')); |
272 |
}; |
}, -db_close => sub { |
273 |
|
my %opt = @_; |
274 |
|
$opt{prop_info}->{-db}->close; |
275 |
|
delete $opt{prop_info}->{-db}; |
276 |
}}); |
}}); |
277 |
|
|
278 |
## HTTP Request Logging Database (See RequestLog plugin module) |
## HTTP Request Logging Database (See RequestLog plugin module) |
279 |
$wiki->{db}->_set_prop_db (log__http_request => {-db_open => sub { |
$wiki->{db}->_set_prop_db (log__http_request => {-db_open => sub { |
280 |
require SuikaWiki::DB::Hash; |
require SuikaWiki::DB::FileSystem::Count; |
281 |
new SuikaWiki::DB::Hash constructor => sub { |
SuikaWiki::DB::FileSystem::Count->new |
282 |
tie my %db, 'BerkeleyDB::Hash', |
(base_directory => $wiki->{config}->{path_to}->{db__request_log__dir}, |
283 |
-Filename => 'http-request-log.db', |
directory_suffix => '.ns', |
284 |
-Env => $bdbenv, |
file_suffix => '.rlog', |
285 |
-Flags => DB_CREATE, |
root_key => $wiki->{config}->{page}->{Default}, |
286 |
-Mode => 0644; |
auto_mkdir => 1); |
287 |
\%db; |
}, -db_close => sub { |
288 |
}; |
my %opt = @_; |
289 |
|
$opt{prop_info}->{-db}->close; |
290 |
|
delete $opt{prop_info}->{-db}; |
291 |
}}); |
}}); |
292 |
|
|
293 |
## Additional WikiDB properties should be defined here |
## Additional WikiDB properties should be defined here |
297 |
push @{$WIKI->{event}->{input_close}}, sub { |
push @{$WIKI->{event}->{input_close}}, sub { |
298 |
my ($wiki, $event) = @_; |
my ($wiki, $event) = @_; |
299 |
try { |
try { |
|
SuikaWiki::Plugin->module_package ('Referer') |
|
|
->add_referer (wiki => $wiki, |
|
|
uri => $wiki->{input}->meta_variable |
|
|
('HTTP_REFERER')); |
|
|
} catch SuikaWiki::Plugin::error with { |
|
|
my $err = shift; |
|
|
$err->raise unless $err->{-type} eq 'PLUGIN_NOT_FOUND'; |
|
|
}; |
|
|
try { |
|
300 |
SuikaWiki::Plugin->module_package ('RequestLog') |
SuikaWiki::Plugin->module_package ('RequestLog') |
301 |
->http_request_log (wiki => $wiki, |
->http_request_log (wiki => $wiki, |
302 |
prop => 'log__http_request'); |
prop => 'log__http_request'); |
306 |
}; |
}; |
307 |
}; |
}; |
308 |
|
|
309 |
|
$WIKI->{config}->{engine_robot_max_access} = 1; |
310 |
|
$WIKI->{config}->{engine_max_access} = 3; |
311 |
|
|
312 |
## -- WikiName of special purpose WikiPages |
## -- WikiName of special purpose WikiPages |
313 |
$WIKI->{config}->{page} = { |
$WIKI->{config}->{page} = { |
314 |
Default => $WIKI->name ([qw/HomePage/]), |
Default => $WIKI->name ([qw/HomePage/]), |
315 |
InterWikiName => $WIKI->name ([qw/Wiki InterWikiName/]), |
InterWikiName => $WIKI->name ([qw/Wiki InterWikiName/]), |
316 |
NewPageTemplate => $WIKI->name ([qw/Wiki NewPageTemplate/]), |
NewPageTemplate => $WIKI->name ([qw/Wiki NewPageTemplate/]), |
317 |
'StyleSheetList(text/html)' => $WIKI->name ([qw<Wiki Style List text/html>]), |
'StyleSheetList(text/html)' => $WIKI->name ([qw<Wiki Style List text/html>]), |
318 |
|
ExpandedURI q<log:root> => $WIKI->name ([]), |
319 |
}; |
}; |
320 |
|
|
321 |
## -- WikiNamespace constants |
## -- WikiNamespace constants |
343 |
## Fragment identifier in URI reference |
## Fragment identifier in URI reference |
344 |
uri_fragment => 'x-punycode', ## Reserved for possible future use |
uri_fragment => 'x-punycode', ## Reserved for possible future use |
345 |
}; |
}; |
346 |
|
|
347 |
|
## -- User option for media types |
348 |
|
$WIKI->{config}->{ExpandedURI q<media-type:accept-media-type>} = { |
349 |
|
q<IMT:text/css##> => 1, |
350 |
|
q<IMT:text/plain##> => 1, |
351 |
|
q<IMT:text/x-suikawiki;version="0.9"##> => 1, |
352 |
|
q<IMT:text/x-suikawiki;version="0.10"##> => 1, |
353 |
|
q<IMT:text/x.suikawiki.image;version="0.9"##> => 1, |
354 |
|
q<IMT:application/x.suikawiki.config;version="2.0"##> => 1, |
355 |
|
}; |
356 |
|
|
357 |
## -- Expires duration templates |
## -- Expires duration templates |
358 |
$WIKI->{config}->{entity}->{expires} = { |
$WIKI->{config}->{entity}->{expires} = { |
364 |
error => {delta => 60}, |
error => {delta => 60}, |
365 |
}; |
}; |
366 |
|
|
367 |
|
## -- User-editable content properties |
368 |
|
$WIKI->{config}->{ExpandedURI q<pe:prop>} = { |
369 |
|
'abstract' => {uri => ExpandedURI q<sw:abstract>, |
370 |
|
ExpandedURI q<media-type:media-type-prop> |
371 |
|
=> ExpandedURI q<sw:abstract--type>}, |
372 |
|
'abstract--type' => {uri => ExpandedURI q<sw:abstract--type>, |
373 |
|
type => ExpandedURI q<media-type:media-type>, |
374 |
|
depend => [qw/abstract/]}, |
375 |
|
'category' => {uri => ExpandedURI q<sw:category>, is_list => 1, |
376 |
|
type => ExpandedURI q<sw:WikiName>, |
377 |
|
ExpandedURI q<pe:revWNList> => ExpandedURI q<pe:inCategory>}, |
378 |
|
'keyword' => {uri => ExpandedURI q<sw:keyword>, is_list => 1}, |
379 |
|
'license' => {uri => ExpandedURI q<sw:license>, |
380 |
|
ExpandedURI q<media-type:media-type-prop> |
381 |
|
=> ExpandedURI q<sw:license--type>}, |
382 |
|
'license--type' => {uri => ExpandedURI q<sw:license--type>, |
383 |
|
type => ExpandedURI q<media-type:media-type>, |
384 |
|
depend => [qw/license/]}, |
385 |
|
'obsolete' => {uri => ExpandedURI q<sw:obsolete>, is_list => 1, |
386 |
|
type => ExpandedURI q<sw:WikiName>}, |
387 |
|
'rel-contents' => {uri => ExpandedURI q<relrev:contents>, is_list => 1, |
388 |
|
type => ExpandedURI q<sw:WikiName>}, |
389 |
|
'rel-index' => {uri => ExpandedURI q<relrev:index>, is_list => 1, |
390 |
|
type => ExpandedURI q<sw:WikiName>}, |
391 |
|
'rel-next' => {uri => ExpandedURI q<relrev:next>, is_list => 1, |
392 |
|
type => ExpandedURI q<sw:WikiName>, |
393 |
|
ExpandedURI q<pe:revWNList> => ExpandedURI q<relrev:prev>}, |
394 |
|
'rel-prev' => {uri => ExpandedURI q<relrev:prev>, is_list => 1, |
395 |
|
type => ExpandedURI q<sw:WikiName>, |
396 |
|
ExpandedURI q<pe:revWNList> => ExpandedURI q<relrev:next>}, |
397 |
|
'rel-up' => {uri => ExpandedURI q<relrev:up>, is_list => 1, |
398 |
|
type => ExpandedURI q<sw:WikiName>, |
399 |
|
ExpandedURI q<pe:revWNList> => ExpandedURI q<relrev:down>}, |
400 |
|
|
401 |
|
## For BugTrack plugin |
402 |
|
'bt--status' => {uri => ExpandedURI q<bt:status>}, |
403 |
|
'bt--priority' => {uri => ExpandedURI q<bt:priority>}, |
404 |
|
'bt--category' => {uri => ExpandedURI q<bt:category>, is_list => 1}, |
405 |
|
'bt--subject' => {uri => ExpandedURI q<bt:subject>}, |
406 |
|
}; |
407 |
|
|
408 |
## -- Debug mode |
## -- Debug mode |
409 |
$WIKI->{config}->{debug} = { |
$WIKI->{config}->{debug} = { |
410 |
general => 0, |
general => 0, |