1 |
=head1 NAME |
2 |
|
3 |
suikawiki-config.ph - SuikaWiki: Configuration for SuikaWiki HTTP CGI Driver |
4 |
|
5 |
=head1 DESCRIPTION |
6 |
|
7 |
This is a configuration file for SuikaWiki Driver for HTTP CGI Script |
8 |
(SWHCS). Basic options such as WikiDB directory mapping and |
9 |
special purpose WikiPage names can be customized with this file. |
10 |
|
11 |
More complex customizing, e.g. modifying navigation bar or |
12 |
adding new mode, is also possible by config.ph (generated from |
13 |
config.wp2) and WikiPlugin modules. For more information, |
14 |
see <http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SuikaWiki>. |
15 |
|
16 |
This file is part of SuikaWiki. |
17 |
|
18 |
=cut |
19 |
|
20 |
package wiki::driver::http; |
21 |
use strict; |
22 |
|
23 |
## These lines should be removed after utf8 support |
24 |
BEGIN { |
25 |
$Message::Util::Formatter::Base::Token = qr/[\w._+\x80-\xFF-]+/; |
26 |
require Message::Util::Formatter::Base; |
27 |
} |
28 |
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 ($) { |
69 |
my $WIKI = shift; |
70 |
use FindBin q($Bin); |
71 |
use File::Spec; |
72 |
|
73 |
## -- Filesystem path mapping |
74 |
for ( |
75 |
[db__cache__dir => q"./wikidata/cache/"], |
76 |
[db__cache_struct__file => q"./wikidata/cache/struct.db"], |
77 |
[db__content__dir => q"./wikidata/page/"], |
78 |
[db__content__error_log => q"./wikidata/log/db-content.log"], |
79 |
[db__bdb__home_dir => q"./wikidata/lock/"], |
80 |
[db__bdb__log_dir => q"./wikidata/log/bdb/"], |
81 |
[db__bdb__log_file => q"./wikidata/log/bdb.log"], |
82 |
[db__bdb__temp_dir => q"./wikidata/lock/"], |
83 |
[db__lock__dir => q"./wikidata/lock/"], |
84 |
[db__lock__log_file => q"./wikidata/log/lock.log"], |
85 |
[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/"], |
89 |
[namazu__index_dir => q"/var/namazu/index/suikawiki"], |
90 |
) { |
91 |
## On system that does not set current directory as main script |
92 |
## directory, you should specify it instead of using "abs_path". |
93 |
$WIKI->{config}->{path_to}->{$_->[0]} = File::Spec->rel2abs ($_->[1], $Bin); |
94 |
} |
95 |
|
96 |
## -- Namazu URI Mapping (See SuikaWiki:SuikaWiki//Namazu) -- |
97 |
$WIKI->{config}->{nmz__uri_to_uri} = sub { |
98 |
my ($nmzuri, %opt) = @_; |
99 |
if ($nmzuri =~ s!^\Q$opt{o}->{wiki}->{config}->{path_to}->{db__content__dir}\E/*!!o) { |
100 |
$nmzuri =~ s/\.txt$//; |
101 |
return $opt{o}->{wiki}->uri_reference |
102 |
(page => $opt{o}->{wiki}->name ([ |
103 |
map {s/([0-9A-F][0-9A-F])/pack 'C', hex $1/ge; $_} |
104 |
split m!\.ns/!, $nmzuri |
105 |
]), base => 1); |
106 |
} else { |
107 |
$nmzuri =~ s<^/home/wakaba/public_html/([^.]+)><http://suika.fam.cx/~wakaba/$1>; |
108 |
return ($nmzuri, $nmzuri); |
109 |
} |
110 |
}; |
111 |
|
112 |
## -- WikiPlugin |
113 |
push @{$WIKI->{event}->{plugin_manager_loaded}}, sub { |
114 |
my $wiki = shift; |
115 |
|
116 |
## Installed plugin modules |
117 |
$wiki->{plugin}->load_directory (qw( |
118 |
lib/SuikaWiki/Plugin/ |
119 |
misc/plugins/ |
120 |
misc/plugins/form/ |
121 |
misc/plugins/format/ |
122 |
misc/plugins/link/ |
123 |
misc/plugins/view/ |
124 |
)); |
125 |
|
126 |
## Configuration file as pseudo-plugin module |
127 |
require 'wikidata/config.ph'; |
128 |
}; |
129 |
|
130 |
## -- WikiDatabase: Mapping logical to physical |
131 |
push @{$WIKI->{event}->{database_loaded}}, sub { |
132 |
my $wiki = shift; |
133 |
|
134 |
## Main content |
135 |
$wiki->{db}->_set_prop_db (content => {-db_open => sub { |
136 |
require SuikaWiki::DB::FileSystem::LeafFile; |
137 |
SuikaWiki::DB::FileSystem::LeafFile->new |
138 |
(base_directory => $wiki->{config}->{path_to}->{db__content__dir}, |
139 |
directory_suffix => '.ns', |
140 |
file_suffix => '.txt', |
141 |
root_key => $wiki->{config}->{page}->{Default}, |
142 |
-lock => $wiki->{var}->{db}->{lock_prop}->('content')); |
143 |
}, -db_close => sub { |
144 |
my %opt = @_; |
145 |
$opt{prop_info}->{-db}->close; |
146 |
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 |
165 |
$wiki->{db}->_set_prop_db (lastmodified => {-db_open => sub { |
166 |
require SuikaWiki::DB::FileSystem::SuikaWikiMetaInfo09; |
167 |
SuikaWiki::DB::FileSystem::SuikaWikiMetaInfo09->new |
168 |
(directory => $wiki->{config}->{path_to}->{db__content__dir}, |
169 |
-lock => $wiki->{var}->{db}->{lock_prop}->('lastmodified')); |
170 |
}, -prop => 'last_modified', -db_close => sub { |
171 |
my %opt = @_; |
172 |
$opt{prop_info}->{-db}->close; |
173 |
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 |
212 |
require SuikaWiki::DB::FileSystem::SuikaWikiCache09; |
213 |
my $cachedb = SuikaWiki::DB::FileSystem::SuikaWikiCache09->new |
214 |
(directory => $wiki->{config}->{path_to}->{db__cache__dir}, |
215 |
expires => 86400 * 3, removes => 86400 * 3); # 3 days |
216 |
$wiki->{db}->_set_prop_db (m__search_result => |
217 |
{-db => $cachedb, -prop => 'search_result', -db_close => sub { |
218 |
my %opt = @_; |
219 |
$opt{prop_info}->{-db}->close; |
220 |
delete $opt{prop_info}->{-db}; |
221 |
}}); |
222 |
$wiki->{db}->_set_prop_db (wpp__headsummary => |
223 |
{-db => $cachedb, -prop => 'headsummary', -db_close => sub { |
224 |
my %opt = @_; |
225 |
$opt{prop_info}->{-db}->close; |
226 |
delete $opt{prop_info}->{-db}; |
227 |
}}); |
228 |
$wiki->{db}->_set_prop_db (ref__item_template => |
229 |
{-db => $cachedb, -prop => 'refereritem', -db_close => sub { |
230 |
my %opt = @_; |
231 |
$opt{prop_info}->{-db}->close; |
232 |
delete $opt{prop_info}->{-db}; |
233 |
}}); |
234 |
|
235 |
## Berkely DB Environment Preparation |
236 |
use BerkeleyDB; |
237 |
my $bdbenv = new BerkeleyDB::Env |
238 |
-Home => $wiki->{config}->{path_to}->{db__bdb__home_dir}, |
239 |
-Config => { |
240 |
DB_DATA_DIR => $wiki->{config}->{path_to}->{db__content__dir}, |
241 |
DB_LOG_DIR => $wiki->{config}->{path_to}->{db__bdb__log_dir}, |
242 |
DB_TMP_DIR => $wiki->{config}->{path_to}->{db__bdb__temp_dir}, |
243 |
}, |
244 |
-ErrFile => $wiki->{config}->{path_to}->{db__bdb__log_file}, |
245 |
-Flags => DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL, |
246 |
-Verbose => $wiki->{config}->{debug}->{db}; |
247 |
|
248 |
$wiki->{db}->_set_prop_db (content__structured => {-db_open => sub { |
249 |
require SuikaWiki::DB::Hash; |
250 |
new SuikaWiki::DB::Hash constructor => sub { |
251 |
use MLDBM qw(BerkeleyDB::Hash);# Storable); |
252 |
tie my %mldb, 'MLDBM', |
253 |
-Filename => $wiki->{config}->{path_to} |
254 |
->{db__cache_struct__file}, |
255 |
-Env => $bdbenv, |
256 |
-Flags => DB_CREATE, |
257 |
-Mode => 0644; |
258 |
\%mldb; |
259 |
}; |
260 |
}}); |
261 |
|
262 |
## Referer Database (See Referer plugin module) |
263 |
$wiki->{db}->_set_prop_db (referer => {-db_open => sub { |
264 |
require SuikaWiki::DB::FileSystem::Count; |
265 |
SuikaWiki::DB::FileSystem::Count->new |
266 |
(base_directory => $wiki->{config}->{path_to}->{db__content__dir}, |
267 |
directory_suffix => '.ns', |
268 |
file_suffix => '.ref', |
269 |
root_key => $wiki->{config}->{page}->{Default}, |
270 |
auto_mkdir => 0, |
271 |
-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) |
279 |
$wiki->{db}->_set_prop_db (log__http_request => {-db_open => sub { |
280 |
require SuikaWiki::DB::FileSystem::Count; |
281 |
SuikaWiki::DB::FileSystem::Count->new |
282 |
(base_directory => $wiki->{config}->{path_to}->{db__request_log__dir}, |
283 |
directory_suffix => '.ns', |
284 |
file_suffix => '.rlog', |
285 |
root_key => $wiki->{config}->{page}->{Default}, |
286 |
auto_mkdir => 1); |
287 |
}, -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 |
294 |
# ... |
295 |
}; |
296 |
|
297 |
push @{$WIKI->{event}->{input_close}}, sub { |
298 |
my ($wiki, $event) = @_; |
299 |
try { |
300 |
SuikaWiki::Plugin->module_package ('RequestLog') |
301 |
->http_request_log (wiki => $wiki, |
302 |
prop => 'log__http_request'); |
303 |
} catch SuikaWiki::Plugin::error with { |
304 |
my $err = shift; |
305 |
$err->raise unless $err->{-type} eq 'PLUGIN_NOT_FOUND'; |
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 |
313 |
$WIKI->{config}->{page} = { |
314 |
Default => $WIKI->name ([qw/HomePage/]), |
315 |
InterWikiName => $WIKI->name ([qw/Wiki InterWikiName/]), |
316 |
NewPageTemplate => $WIKI->name ([qw/Wiki NewPageTemplate/]), |
317 |
'StyleSheetList(text/html)' => $WIKI->name ([qw<Wiki Style List text/html>]), |
318 |
ExpandedURI q<log:root> => $WIKI->name ([]), |
319 |
}; |
320 |
|
321 |
## -- WikiNamespace constants |
322 |
$WIKI->{config}->{name}->{space} = { |
323 |
separator => '//', |
324 |
separator_reg => qr#\s*//\s*#, |
325 |
self => '.', |
326 |
parent => '..', |
327 |
root => '//', |
328 |
}; |
329 |
|
330 |
## -- Default character codes |
331 |
$WIKI->{config}->{charset} = { |
332 |
## Internal code - MUST be ASCII + 8bit coding scheme |
333 |
internal => 'euc-jp', |
334 |
## Default output code |
335 |
output => 'iso-2022-jp', |
336 |
## "query" part in URI reference |
337 |
uri_query => '', # auto-detected |
338 |
uri_query_encode => 'euc-jp', ## For compatibility w/ SuikaWiki 2 |
339 |
uri_param => '', # auto-detected |
340 |
uri_param_encode => 'euc-jp', ## For compatibility w/ SuikaWiki 2 |
341 |
## PATH_INFO part in URI reference |
342 |
uri_path_info => 'x-utf-8-10646', ## Reserved for future use |
343 |
## Fragment identifier in URI reference |
344 |
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 |
358 |
$WIKI->{config}->{entity}->{expires} = { |
359 |
edit => {delta => 60}, |
360 |
view => {delta => 2*3600}, |
361 |
list => {delta => 60}, |
362 |
lm_flaged => {delta => 30*24*3600}, |
363 |
stylesheet => {delta => 30*24*3600}, |
364 |
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 |
409 |
$WIKI->{config}->{debug} = { |
410 |
general => 0, |
411 |
db => 0, |
412 |
format => 0, |
413 |
view => 0, |
414 |
}; |
415 |
|
416 |
}; |
417 |
|
418 |
=head1 SEE ALSO |
419 |
|
420 |
C<lib/suikawiki.pl>, C<wiki.cgi>, |
421 |
<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SuikaWiki>, |
422 |
<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SWHCS> |
423 |
|
424 |
=head1 LICENSE |
425 |
|
426 |
Copyright 2003-2004 Wakaba <w@suika.fam.cx>. All rights reserved. |
427 |
|
428 |
This program is free software; you can redistribute it and/or |
429 |
modify it under the same terms as Perl itself. |
430 |
|
431 |
=cut |
432 |
|
433 |
1; # $Date: 2005/02/06 12:58:58 $ |