/[pub]/suikawiki/wikidata/suikawiki-config.ph
Suika

Contents of /suikawiki/wikidata/suikawiki-config.ph

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations) (download)
Thu Jun 3 06:40:02 2004 UTC (21 years ago) by wakaba
Branch: MAIN
CVS Tags: release-3-0-0
Changes since 1.17: +39 -1 lines
Static output of stylesheet implemented

1 wakaba 1.13 =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 w 1.1 use strict;
22 wakaba 1.6
23 wakaba 1.13 ## 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 wakaba 1.6 }
28 wakaba 1.13 use Message::Util::Error;
29 wakaba 1.6
30 wakaba 1.15 use Message::Util::QName::General [q<ExpandedURI>], {
31 wakaba 1.16 'log' => q<http://suika.fam.cx/~wakaba/-temp/2004/05/01/reqlog#>,
32 wakaba 1.15 'media-type' => q<http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt#>,
33 wakaba 1.18 'ss' => q<http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet#>,
34 wakaba 1.15 };
35    
36 wakaba 1.14 BEGIN {
37     if ($main::ENV{REQUEST_URI} =~ /\#/) {
38     require SuikaWiki::Output::HTTP;
39     my $out = SuikaWiki::Output::HTTP->new;
40     $out->{status_code} = 401;
41     $out->{status_phrase} = q<Request-URI MUST NOT have Fragment Identifier>;
42     $out->{entity}->{media_type} = q<text/html>;
43     $out->{entity}->{charset} = q<iso-8859-1>;
44     $out->{entity}->{language} = [q<en>];
45     $out->{entity}->{body_is_octet_stream} = 1;
46     my $ua = $main::ENV{HTTP_USER_AGENT};
47     for ($ua) {
48     s/&/&amp;/g; s/</&lt;/g; s/([^\x20-\x7E])/sprintf '&#x%02X;', ord $1/ge;
49     };
50     $out->{entity}->{body} = qq<
51     <!DOCTYPE html SYSTEM>
52     <title>401 Bad Request-URI</title>
53     <h1>Bad Request-URI</h1>
54     <p>Your Request-URI has fragment identifier but it is not allowed here.
55     It might be a bug of your user agent ($ua). Please contact to the UA
56     vendor.</p>
57     >;
58     $out->output (output => 'http-cgi');
59     exit;
60     }
61     }
62    
63 wakaba 1.13 push our @Config, sub ($) {
64     my $WIKI = shift;
65 wakaba 1.16 use FindBin q($Bin);
66     use File::Spec;
67 wakaba 1.13
68     ## -- Filesystem path mapping
69     for (
70 wakaba 1.14 [db__cache__dir => q"./wikidata/cache/"],
71     [db__cache_struct__file => q"./wikidata/cache/struct.db"],
72 wakaba 1.13 [db__content__dir => q"./wikidata/page/"],
73     [db__content__error_log => q"./wikidata/log/db-content.log"],
74     [db__bdb__home_dir => q"./wikidata/lock/"],
75     [db__bdb__log_dir => q"./wikidata/log/bdb/"],
76     [db__bdb__log_file => q"./wikidata/log/bdb.log"],
77     [db__bdb__temp_dir => q"./wikidata/lock/"],
78     [db__lock__dir => q"./wikidata/lock/"],
79     [db__lock__log_file => q"./wikidata/log/lock.log"],
80     [db__log__dir => q"./wikidata/log/"],
81 wakaba 1.16 [db__request_log__dir => q"./wikidata/rlog/"],
82 wakaba 1.18 [db__static__dir => q"./wikidata/static/"],
83 wakaba 1.13 [db__temp__dir => q"./wikidata/lock/"],
84     [namazu__index_dir => q"/var/namazu/index/suikawiki"],
85     ) {
86     ## On system that does not set current directory as main script
87     ## directory, you should specify it instead of using "abs_path".
88 wakaba 1.17 $WIKI->{config}->{path_to}->{$_->[0]} = File::Spec->rel2abs ($_->[1], $Bin);
89 wakaba 1.13 }
90    
91     ## -- Namazu URI Mapping (See SuikaWiki:SuikaWiki//Namazu) --
92     $WIKI->{config}->{nmz__uri_to_uri} = sub {
93     my ($nmzuri, %opt) = @_;
94     if ($nmzuri =~ s!^\Q$opt{o}->{wiki}->{config}->{path_to}->{db__content__dir}\E/*!!o) {
95     $nmzuri =~ s/\.txt$//;
96     return $opt{o}->{wiki}->uri_reference
97     (page => $opt{o}->{wiki}->name ([
98     map {s/([0-9A-F][0-9A-F])/pack 'C', hex $1/ge; $_}
99     split m!\.ns/!, $nmzuri
100     ]), base => 1);
101     } else {
102     $nmzuri =~ s<^/home/wakaba/public_html/([^.]+)><http://suika.fam.cx/~wakaba/$1>;
103     return ($nmzuri, $nmzuri);
104     }
105     };
106    
107     ## -- WikiPlugin
108     push @{$WIKI->{event}->{plugin_manager_loaded}}, sub {
109     my $wiki = shift;
110    
111     ## Installed plugin modules
112     $wiki->{plugin}->load_directory (qw(
113     lib/SuikaWiki/Plugin/
114     misc/plugins/
115     misc/plugins/form/
116     misc/plugins/format/
117     misc/plugins/link/
118     misc/plugins/view/
119     ));
120    
121     ## Configuration file as pseudo-plugin module
122     require 'wikidata/config.ph';
123     };
124    
125     ## -- WikiDatabase: Mapping logical to physical
126     push @{$WIKI->{event}->{database_loaded}}, sub {
127     my $wiki = shift;
128    
129     ## Main content
130     $wiki->{db}->_set_prop_db (content => {-db_open => sub {
131 wakaba 1.14 require SuikaWiki::DB::FileSystem::LeafFile;
132     SuikaWiki::DB::FileSystem::LeafFile->new
133     (base_directory => $wiki->{config}->{path_to}->{db__content__dir},
134     directory_suffix => '.ns',
135     file_suffix => '.txt',
136     root_key => $wiki->{config}->{page}->{Default},
137 wakaba 1.15 -lock => $wiki->{var}->{db}->{lock_prop}->('content_prop'));
138     }, -db_close => sub {
139     my %opt = @_;
140     $opt{prop_info}->{-db}->close;
141     delete $opt{prop_info}->{-db};
142     }});
143    
144     ## Properties
145     $wiki->{db}->_set_prop_db (content_prop => {-db_open => sub {
146     require SuikaWiki::DB::FileSystem::LeafProp;
147     SuikaWiki::DB::FileSystem::LeafProp->new
148     (base_directory => $wiki->{config}->{path_to}->{db__content__dir},
149     directory_suffix => '.ns',
150     file_suffix => '.prop',
151     root_key => $wiki->{config}->{page}->{Default},
152 wakaba 1.13 -lock => $wiki->{var}->{db}->{lock_prop}->('content'));
153     }, -db_close => sub {
154     my %opt = @_;
155     $opt{prop_info}->{-db}->close;
156     delete $opt{prop_info}->{-db};
157     }});
158    
159     ## Last modified
160     $wiki->{db}->_set_prop_db (lastmodified => {-db_open => sub {
161     require SuikaWiki::DB::FileSystem::SuikaWikiMetaInfo09;
162     SuikaWiki::DB::FileSystem::SuikaWikiMetaInfo09->new
163     (directory => $wiki->{config}->{path_to}->{db__content__dir},
164     -lock => $wiki->{var}->{db}->{lock_prop}->('lastmodified'));
165     }, -prop => 'last_modified', -db_close => sub {
166     my %opt = @_;
167     $opt{prop_info}->{-db}->close;
168     delete $opt{prop_info}->{-db};
169     }});
170    
171 wakaba 1.18 ## Static version
172     $wiki->{db}->_set_prop_db (static__css => {-db_open => sub {
173     require SuikaWiki::DB::FileSystem::LeafFileP;
174     SuikaWiki::DB::FileSystem::LeafFileP->new
175     (base_directory => $wiki->{config}->{path_to}->{db__static__dir},
176     directory_suffix => '.ns',
177     file_suffix => '.css',
178     root_key => $wiki->{config}->{page}->{Default});
179     }, -db_close => sub {
180     my %opt = @_;
181     $opt{prop_info}->{-db}->close;
182     delete $opt{prop_info}->{-db};
183     }});
184     $wiki->{config}->{ExpandedURI q<ss:use-static>} = 1;
185     ## URI maker for LeafFileP generated files
186     $wiki->{config}->{ExpandedURI q<ss:wikiname-to-uri>} = sub {
187     my (undef, %opt) = @_;
188     my $page = join '.ns/',
189     map {s/([^0-9A-Za-z_-])/sprintf '+%02X', ord $1/ge;$_}
190     @{$opt{wikiname}};
191     return URI->new ('wikidata/static/' . $page . '.css');
192     };
193     ## Reverse mapping of generate-uri
194     $wiki->{config}->{ExpandedURI q<ss:uri-to-wikiname>} = sub {
195     my (undef, %opt) = @_;
196     $opt{uri} =~ s!^.+/wikidata/static/!!g;
197     $opt{uri} =~ s/\?[^?]*$//g;
198     $opt{uri} =~ s/\.css$//g;
199     return $opt{wiki}->name
200     ([map {s/\+([0-9A-Fa-f_-][0-9A-Fa-f_-])/pack 'CC', hex $1/ge;$_}
201     split m!.ns/!, $opt{uri}]);
202     };
203    
204    
205 wakaba 1.13 ## Cache DBs
206     require SuikaWiki::DB::FileSystem::SuikaWikiCache09;
207     my $cachedb = SuikaWiki::DB::FileSystem::SuikaWikiCache09->new
208     (directory => $wiki->{config}->{path_to}->{db__cache__dir},
209     expires => 86400 * 3, removes => 86400 * 3); # 3 days
210     $wiki->{db}->_set_prop_db (m__search_result =>
211     {-db => $cachedb, -prop => 'search_result', -db_close => sub {
212     my %opt = @_;
213     $opt{prop_info}->{-db}->close;
214     delete $opt{prop_info}->{-db};
215     }});
216     $wiki->{db}->_set_prop_db (wpp__headsummary =>
217     {-db => $cachedb, -prop => 'headsummary', -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 (ref__item_template =>
223     {-db => $cachedb, -prop => 'refereritem', -db_close => sub {
224     my %opt = @_;
225     $opt{prop_info}->{-db}->close;
226     delete $opt{prop_info}->{-db};
227     }});
228    
229     ## Berkely DB Environment Preparation
230     use BerkeleyDB;
231     my $bdbenv = new BerkeleyDB::Env
232     -Home => $wiki->{config}->{path_to}->{db__bdb__home_dir},
233     -Config => {
234     DB_DATA_DIR => $wiki->{config}->{path_to}->{db__content__dir},
235     DB_LOG_DIR => $wiki->{config}->{path_to}->{db__bdb__log_dir},
236     DB_TMP_DIR => $wiki->{config}->{path_to}->{db__bdb__temp_dir},
237     },
238     -ErrFile => $wiki->{config}->{path_to}->{db__bdb__log_file},
239     -Flags => DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL,
240     -Verbose => $wiki->{config}->{debug}->{db};
241    
242     $wiki->{db}->_set_prop_db (content__structured => {-db_open => sub {
243     require SuikaWiki::DB::Hash;
244     new SuikaWiki::DB::Hash constructor => sub {
245     use MLDBM qw(BerkeleyDB::Hash);# Storable);
246     tie my %mldb, 'MLDBM',
247     -Filename => $wiki->{config}->{path_to}
248     ->{db__cache_struct__file},
249     -Env => $bdbenv,
250     -Flags => DB_CREATE,
251     -Mode => 0644;
252     \%mldb;
253     };
254     }});
255    
256     ## Referer Database (See Referer plugin module)
257     $wiki->{db}->_set_prop_db (referer => {-db_open => sub {
258 wakaba 1.14 require SuikaWiki::DB::FileSystem::Count;
259     SuikaWiki::DB::FileSystem::Count->new
260     (base_directory => $wiki->{config}->{path_to}->{db__content__dir},
261     directory_suffix => '.ns',
262     file_suffix => '.ref',
263     root_key => $wiki->{config}->{page}->{Default},
264     auto_mkdir => 0,
265     -lock => $wiki->{var}->{db}->{lock_prop}->('referer'));
266     }, -db_close => sub {
267     my %opt = @_;
268     $opt{prop_info}->{-db}->close;
269     delete $opt{prop_info}->{-db};
270 wakaba 1.13 }});
271    
272     ## HTTP Request Logging Database (See RequestLog plugin module)
273     $wiki->{db}->_set_prop_db (log__http_request => {-db_open => sub {
274 wakaba 1.16 require SuikaWiki::DB::FileSystem::Count;
275     SuikaWiki::DB::FileSystem::Count->new
276     (base_directory => $wiki->{config}->{path_to}->{db__request_log__dir},
277     directory_suffix => '.ns',
278     file_suffix => '.rlog',
279     root_key => $wiki->{config}->{page}->{Default},
280     auto_mkdir => 1);
281     }, -db_close => sub {
282     my %opt = @_;
283     $opt{prop_info}->{-db}->close;
284     delete $opt{prop_info}->{-db};
285 wakaba 1.13 }});
286    
287     ## Additional WikiDB properties should be defined here
288     # ...
289     };
290    
291     push @{$WIKI->{event}->{input_close}}, sub {
292     my ($wiki, $event) = @_;
293     try {
294     SuikaWiki::Plugin->module_package ('RequestLog')
295     ->http_request_log (wiki => $wiki,
296     prop => 'log__http_request');
297     } catch SuikaWiki::Plugin::error with {
298     my $err = shift;
299     $err->raise unless $err->{-type} eq 'PLUGIN_NOT_FOUND';
300     };
301     };
302    
303 wakaba 1.18 $WIKI->{config}->{engine_max_access} = 15;
304    
305 wakaba 1.13 ## -- WikiName of special purpose WikiPages
306     $WIKI->{config}->{page} = {
307     Default => $WIKI->name ([qw/HomePage/]),
308     InterWikiName => $WIKI->name ([qw/Wiki InterWikiName/]),
309     NewPageTemplate => $WIKI->name ([qw/Wiki NewPageTemplate/]),
310     'StyleSheetList(text/html)' => $WIKI->name ([qw<Wiki Style List text/html>]),
311 wakaba 1.16 ExpandedURI q<log:root> => $WIKI->name ([]),
312 wakaba 1.13 };
313    
314     ## -- WikiNamespace constants
315     $WIKI->{config}->{name}->{space} = {
316     separator => '//',
317     separator_reg => qr#\s*//\s*#,
318     self => '.',
319     parent => '..',
320     root => '//',
321     };
322    
323     ## -- Default character codes
324     $WIKI->{config}->{charset} = {
325     ## Internal code - MUST be ASCII + 8bit coding scheme
326     internal => 'euc-jp',
327     ## Default output code
328     output => 'iso-2022-jp',
329     ## "query" part in URI reference
330     uri_query => '', # auto-detected
331     uri_query_encode => 'euc-jp', ## For compatibility w/ SuikaWiki 2
332     uri_param => '', # auto-detected
333     uri_param_encode => 'euc-jp', ## For compatibility w/ SuikaWiki 2
334     ## PATH_INFO part in URI reference
335     uri_path_info => 'x-utf-8-10646', ## Reserved for future use
336     ## Fragment identifier in URI reference
337     uri_fragment => 'x-punycode', ## Reserved for possible future use
338     };
339 wakaba 1.15
340     ## -- User option for media types
341     $WIKI->{config}->{ExpandedURI q<media-type:accept-media-type>} = {
342     q<IMT:text/css##> => 1,
343     q<IMT:text/plain##> => 1,
344     q<IMT:text/x-suikawiki;version="0.9"##> => 1,
345     q<IMT:application/x.suikawiki.config;version="2.0"##> => 1,
346     };
347 wakaba 1.13
348     ## -- Expires duration templates
349     $WIKI->{config}->{entity}->{expires} = {
350     edit => {delta => 60},
351     view => {delta => 2*3600},
352     list => {delta => 60},
353     lm_flaged => {delta => 30*24*3600},
354     stylesheet => {delta => 30*24*3600},
355     error => {delta => 60},
356     };
357    
358     ## -- Debug mode
359     $WIKI->{config}->{debug} = {
360     general => 0,
361     db => 0,
362     format => 0,
363     view => 0,
364     };
365 wakaba 1.11
366 wakaba 1.8 };
367 w 1.1
368 wakaba 1.13 =head1 SEE ALSO
369 wakaba 1.6
370 wakaba 1.13 C<lib/suikawiki.pl>, C<wiki.cgi>,
371     <http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SuikaWiki>,
372     <http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SWHCS>
373 wakaba 1.6
374     =head1 LICENSE
375    
376 wakaba 1.13 Copyright 2003-2004 Wakaba <w@suika.fam.cx>. All rights reserved.
377 wakaba 1.6
378     This program is free software; you can redistribute it and/or
379     modify it under the same terms as Perl itself.
380    
381     =cut
382    
383 wakaba 1.18 1; # $Date: 2004/05/07 07:51:28 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24