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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (hide annotations) (download)
Thu Apr 22 05:45:14 2004 UTC (20 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.13: +48 -18 lines
Use LeafFile

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24