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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by wakaba, Sun Oct 5 11:57:09 2003 UTC revision 1.12.4.5 by wakaba, Sat Mar 20 04:09:14 2004 UTC
# Line 1  Line 1 
1  use strict;  =head1 NAME
2    
3  ## URI (or part of URI) of Wiki CGI itself and its external addons  suikawiki-config.ph - SuikaWiki: Configuration for SuikaWiki HTTP CGI Driver
         ## Note: If your Wiki CGI URI is <http://foo.example/path/to/wiki.cgi>,  
         ##              cookie-path: /path/to/  
         ##              script-short-name: wiki.cgi  
         ##       URI parts MUST NOT contains "&" and/or non-URI characters.  
   our %uri = (  
     cookie_path         => '/~wakaba/-temp/wiki/',  
     external_script     => '../wiki/script/',  
     script_short_name   => 'wiki',  
     ## If you use CVS repository of WikiDatabase,  
     cvs_repository      => '/gate/cvs/suikawiki/wikidata/page/',  
   );  
   our $url_cgi; {  
     my $scheme = 'http';  
     $scheme = lc $1 if $main::ENV{SERVER_PROTOCOL} =~ m#([A-Za-z0-9+.%-]+)#;  
     $url_cgi = "$scheme://".($main::ENV{HTTP_HOST} || $main::ENV{SERVER_NAME}.($main::ENV{SERVER_PORT}==80?'':":$main::ENV{SERVER_PORT}"))."$uri{cookie_path}$uri{script_short_name}";  
   }  
   $uri{wiki_abs} = $url_cgi;  
   $uri{wiki} = qq($uri{cookie_path}$uri{script_short_name});      
4    
5  ## Path to modules and databases  =head1 DESCRIPTION
6    push @main::INC, 'lib';  
7    push @SuikaWiki::Plugin::plugin_directory, (  This is a configuration file for SuikaWiki Driver for HTTP CGI Script
8          q(lib/SuikaWiki/Plugin/),  (SWHCS).  Basic options such as WikiDB directory mapping and
9          q(misc/plugins/),  special purpose WikiPage names can be customized with this file.
10    );  
11    our %PathTo = (       ## Path to your data, from the main CGI script (NOT from this config script)  More complex customizing, e.g. modifying navigation bar or
12                   CachePrefix            => q(./wikidata/.cache.),  adding new mode, is also possible by config.ph (generated from
13                   TempPrefix             => q(./wikidata/.tmp.),  config.wp2) and WikiPlugin modules.  For more information,
14                   WikiDataBase   => q(./wikidata/page),  see <http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SuikaWiki>.
                  WikiDatabase           => q(./wikidata/page),  
                  WikiDatabaseErrorLog   => q(./wikidata/log/error.log),  
                  convert                => q(/usr/X11R6/bin/convert),  
   );  
   
 require SuikaWiki::DB::Util::Lock;  
 our $locker = SuikaWiki::DB::Util::Lock->new (-directory => q(./wikidata/lock),  
    -name => 'wikipage',  
    -retry => ($main::ENV{HTTP_USER_AGENT} =~ m#Openbot/3# ? 2 : 80),  
    -timeout => 300,                                          
    -error_handler => sub {  
      my ($self, %o) = @_;  
        open LOG, '>>', $main::PathTo{WikiDatabaseErrorLog};  
          print LOG scalar (gmtime)."\@@{[time]} @{[$$]} {$o{level}}: ", $o{msg}, "\n";  
        close LOG;  
      if ($o{level} eq 'fatal') {  
        die $o{msg};  
      }  
    });  
 $locker->lock or do {  
   open LOG, '>>', $main::PathTo{WikiDatabaseErrorLog};  
     print LOG scalar (time), " Can't lock\n";  
   close LOG;  
   die "Can't lock";  
 };  
15    
16    This file is part of SuikaWiki.
17    
18    =cut
19    
20    package wiki::driver::http;
21    use strict;
22    
23    push our @Config, sub ($) {
24      eval { use Message::Util::Error };
25      my $WIKI = shift;
26      use Cwd qw(abs_path);
27      
28      ## -- Filesystem path mapping
29      for (
30         [db__cache__dir          => q"./wikidata/lock/"],
31         [db__cache_struct__file  => q"./wikidata/lock/struct.db"],
32         [db__content__dir        => q"./wikidata/page/"],
33         [db__content__error_log  => q"./wikidata/log/db-content.log"],
34         [db__bdb__home_dir       => q"./wikidata/lock/"],
35         [db__bdb__log_dir        => q"./wikidata/log/bdb/"],
36         [db__bdb__log_file       => q"./wikidata/log/bdb.log"],
37         [db__bdb__temp_dir       => q"./wikidata/lock/"],
38         [db__lock__dir           => q"./wikidata/lock/"],
39         [db__lock__log_file      => q"./wikidata/log/lock.log"],
40         [db__log__dir            => q"./wikidata/log/"],
41         [db__temp__dir           => q"./wikidata/lock/"],
42         [namazu__index_dir       => q"/var/namazu/index/wakaba"],
43      ) {
44        ## On system that does not set current directory as main script
45        ## directory, you should specify it instead of using "abs_path".
46        $WIKI->{config}->{path_to}->{$_->[0]} = abs_path $_->[1];
47      }
48      
49      ## -- Namazu URI Mapping (See SuikaWiki:SuikaWiki//Namazu) --
50      $WIKI->{config}->{nmz__uri_to_uri} = sub {
51        my ($nmzuri, %opt) = @_;
52        if ($nmzuri =~ s!^\Q$opt{o}->{wiki}->{config}->{path_to}->{db__content__dir}\E/*!!o) {
53          $nmzuri =~ s/\.txt$//;
54          return $opt{o}->{wiki}->uri_reference
55                          (page => $opt{o}->{wiki}->name ([
56            map {s/([0-9A-F][0-9A-F])/pack 'C', hex $1/ge; $_}
57            split m!\.ns/!, $nmzuri
58          ]), base => 1);
59        } else {
60          $nmzuri =~ s<^/home/wakaba/public_html/([^.]+)><http://suika.fam.cx/~wakaba/$1>;
61          return ($nmzuri, $nmzuri);
62        }
63      };
64    
65      ## -- WikiPlugin
66      push @{$WIKI->{event}->{plugin_manager_loaded}}, sub {
67        my $wiki = shift;
68        
69        ## Installed plugin modules
70        $wiki->{plugin}->load_directory (qw(
71          lib/SuikaWiki/Plugin/
72          misc/plugins/
73          misc/plugins/form/
74          misc/plugins/format/
75          misc/plugins/link/
76          misc/plugins/view/
77        ));
78    
79        ## Configuration file as pseudo-plugin module
80        require 'wikidata/config.ph';
81      };
82    
83      ## -- WikiDatabase: Mapping logical to physical
84      push @{$WIKI->{event}->{database_loaded}}, sub {
85          my $wiki = shift;
86          
87          ## Main content
88          $wiki->{db}->_set_prop_db (content => {-db_open => sub {
89            require SuikaWiki::DB::FileSystem::YukiWikiDBNS;
90            SuikaWiki::DB::FileSystem::YukiWikiDBNS->new
91              (directory => $wiki->{config}->{path_to}->{db__content__dir},
92               logfile   => $wiki->{config}->{path_to}->{db__content__error_log},
93               suffix    => '.txt',
94               -lock => $wiki->{var}->{db}->{lock_prop}->('content'));
95          }, -db_close => sub {
96            my %opt = @_;
97            $opt{prop_info}->{-db}->close;
98            delete $opt{prop_info}->{-db};
99          }});
100          
101          ## Last modified
102          $wiki->{db}->_set_prop_db (lastmodified => {-db_open => sub {
103            require SuikaWiki::DB::FileSystem::SuikaWikiMetaInfo09;
104            SuikaWiki::DB::FileSystem::SuikaWikiMetaInfo09->new
105              (directory => $wiki->{config}->{path_to}->{db__content__dir},
106               -lock => $wiki->{var}->{db}->{lock_prop}->('lastmodified'));
107          }, -prop => 'last_modified', -db_close => sub {
108            my %opt = @_;
109            $opt{prop_info}->{-db}->close;
110            delete $opt{prop_info}->{-db};
111          }});
112          
113          ## Cache DBs
114          require SuikaWiki::DB::FileSystem::SuikaWikiCache09;
115          my $cachedb = SuikaWiki::DB::FileSystem::SuikaWikiCache09->new
116                (directory => $wiki->{config}->{path_to}->{db__cache__dir},
117                 expires => 86400 * 3, removes => 86400 * 3); # 3 days
118          $wiki->{db}->_set_prop_db (m__search_result =>
119            {-db => $cachedb, -prop => 'search_result', -db_close => sub {
120              my %opt = @_;
121              $opt{prop_info}->{-db}->close;
122              delete $opt{prop_info}->{-db};
123            }});
124          $wiki->{db}->_set_prop_db (wpp__headsummary =>
125            {-db => $cachedb, -prop => 'headsummary', -db_close => sub {
126              my %opt = @_;
127              $opt{prop_info}->{-db}->close;
128              delete $opt{prop_info}->{-db};
129            }});
130          $wiki->{db}->_set_prop_db (ref__item_template =>
131            {-db => $cachedb, -prop => 'refereritem', -db_close => sub {
132              my %opt = @_;
133              $opt{prop_info}->{-db}->close;
134              delete $opt{prop_info}->{-db};
135            }});
136    
137          ## Berkely DB Environment Preparation
138          use BerkeleyDB;
139          my $bdbenv = new BerkeleyDB::Env
140             -Home => $wiki->{config}->{path_to}->{db__bdb__home_dir},
141             -Config => {
142               DB_DATA_DIR => $wiki->{config}->{path_to}->{db__content__dir},
143               DB_LOG_DIR => $wiki->{config}->{path_to}->{db__bdb__log_dir},
144               DB_TMP_DIR => $wiki->{config}->{path_to}->{db__bdb__temp_dir},
145             },
146             -ErrFile => $wiki->{config}->{path_to}->{db__bdb__log_file},
147             -Flags => DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL,
148             -Verbose => $wiki->{config}->{debug}->{db};
149    
150          $wiki->{db}->_set_prop_db (content__structured => {-db_open => sub {
151            require SuikaWiki::DB::Hash;
152            new SuikaWiki::DB::Hash constructor => sub {
153              use MLDBM qw(BerkeleyDB::Hash);# Storable);
154              tie my %mldb, 'MLDBM',
155                            -Filename => $wiki->{config}->{path_to}
156                                              ->{db__cache_struct__file},
157                            -Env => $bdbenv,
158                            -Flags => DB_CREATE,
159                            -Mode => 0644;
160              \%mldb;
161           };
162          }});
163          
164          ## Referer Database (See Referer plugin module)
165          $wiki->{db}->_set_prop_db (referer => {-db_open => sub {
166            require SuikaWiki::DB::Hash;
167            new SuikaWiki::DB::Hash constructor => sub {
168              tie my %db, 'BerkeleyDB::Hash',
169                            -Filename => 'referer.db',
170                            -Env => $bdbenv,
171                            -Flags => DB_CREATE,
172                            -Mode => 0644;
173              \%db;
174           };
175          }});
176    
177          ## HTTP Request Logging Database (See RequestLog plugin module)
178          $wiki->{db}->_set_prop_db (log__http_request => {-db_open => sub {
179            require SuikaWiki::DB::Hash;
180            new SuikaWiki::DB::Hash constructor => sub {
181              tie my %db, 'BerkeleyDB::Hash',
182                            -Filename => 'http-request-log.db',
183                            -Env => $bdbenv,
184                            -Flags => DB_CREATE,
185                            -Mode => 0644;
186              \%db;
187           };
188          }});
189          
190          ## Additional WikiDB properties should be defined here
191          # ...    
192      };
193    
194      push @{$WIKI->{event}->{input_close}}, sub {
195        my ($wiki, $event) = @_;
196        try {
197          SuikaWiki::Plugin->module_package ('Referer')
198                         ->add_referer (wiki => $wiki,
199                                        uri => $wiki->{input}->meta_variable
200                                                 ('HTTP_REFERER'));
201        } catch SuikaWiki::Plugin::error with {
202          my $err = shift;
203          $err->raise unless $err->{-type} eq 'PLUGIN_NOT_FOUND';
204        };
205        try {
206          SuikaWiki::Plugin->module_package ('RequestLog')
207                         ->http_request_log (wiki => $wiki,
208                                             prop => 'log__http_request');
209        } catch SuikaWiki::Plugin::error with {
210          my $err = shift;
211          $err->raise unless $err->{-type} eq 'PLUGIN_NOT_FOUND';
212        };
213      };
214    
215      ## -- WikiName of special purpose WikiPages
216      $WIKI->{config}->{page} = {
217        Default         => $WIKI->name ([qw/HomePage/]),
218        InterWikiName   => $WIKI->name ([qw/Wiki InterWikiName/]),
219        NewPageTemplate => $WIKI->name ([qw/Wiki NewPageTemplate/]),
220        'StyleSheetList(text/html)' => $WIKI->name ([qw<Wiki Style List text/html>]),
221      };
222      
223      ## -- WikiNamespace constants
224      $WIKI->{config}->{name}->{space} = {
225        separator => '//',
226        separator_reg => qr#\s*//\s*#,
227        self => '.',
228        parent => '..',
229      };
230      
231      ## -- Default character codes
232      $WIKI->{config}->{charset} = {
233        ## Internal code - MUST be ASCII + 8bit coding scheme
234          internal => 'euc-jp',
235        ## Default output code
236          output => 'iso-2022-jp',
237        ## "query" part in URI reference
238          uri_query => '', # auto-detected
239          uri_query_encode => 'euc-jp',     ## For compatibility w/ SuikaWiki 2
240          uri_param => '', # auto-detected
241          uri_param_encode => 'euc-jp',     ## For compatibility w/ SuikaWiki 2
242        ## PATH_INFO part in URI reference
243          uri_path_info => 'x-utf-8-10646', ## Reserved for future use
244        ## Fragment identifier in URI reference
245          uri_fragment => 'x-punycode',     ## Reserved for possible future use
246      };
247      
248      ## -- Expires duration templates
249      $WIKI->{config}->{entity}->{expires} = {
250        edit      => {delta => 60},
251        view      => {delta => 2*3600},
252        lm_flaged => {delta => 30*24*3600},
253        stylesheet => {delta => 30*24*3600},
254        error     => {delta => 60},
255      };
256    
257      ## -- Debug mode
258      $WIKI->{config}->{debug} = {
259        general => 0,
260        db => 0,
261        format => 0,
262        view => 0,
263      };
264    
 ## Type of WikiPage Database  
   #our $modifier_dbtype = 'AnyDBM_File';  # Fast, not available on some server, page size limited.  
   #our $modifier_dbtype = 'dbmopen';      # Fast, not available on some server, page size limited.  
   #our $modifier_dbtype = 'Yuki::YukiWikiDB';     # Slow, available on all environment.  
   #our $modifier_dbtype = 'Yuki::YukiWikiDB2';     # Slow, available on all environment.  
   our $modifier_dbtype = 'Yuki::YukiWikiDBMeta';     # Slow, available on all environment.  
   our $use_exists = 1; # If you can use 'exists' method for your DB.  
   
 ## Name of Special WikiPage (linked as parts of navigations)  
   our %PageName = (  
     FrontPage   => 'HomePage',  
     IndexPage   => 'IndexPage',  
     InterWikiName       => 'Wiki//InterWikiName',  
     SearchPage  => 'Wiki//Page//Search',  
     CreatePage  => 'Wiki//Page//Create',  
     MenuBar     => 'Wiki//MenuBar',  
     RecentChanges       => 'RecentChanges',  
     RefererDontRecord   => 'Wiki//Referer//IgnoreSite',  
     RefererSiteName     => 'Wiki//Referer//SiteName',  
     ResourceNS  => 'Wiki//Resource//',  
     StyleList   => 'Wiki//Style//List//',  
     UserAgentList       => 'Wiki//UserAgentList',  
     AdminSpecialPage    => "\x11\x11Admin\x11Special\x11Page\x11\x11",  
   );  
   
 ## (Should be reimplemented)  
   our $kanjicode = 'euc';  
   our $lang = 'ja';  
   
 ## Misc. options  
   $SuikaWiki::Plugin::UserAgent::LoggingName = 1;  
         ## Use UA-name log? (require UserAgent plugin module)  
   
 ## Definition of views  
   
 require SuikaWiki::View;  
 SuikaWiki::View->template ('links')->add_line (<<'EOH');  
 %link-wiki(page=>"Wiki//News",rel=>News,class=>wiki,title=>"%res(name=>GoToWikiNewsLink);"p);  
 %link-wiki(page=>"Wiki//Help",rel=>help,class=>wiki,title=>"%res(name=>GoToWikiHelpLink);"p);  
 %link-wiki(page=>"Wiki//Page//License",rel=>copyright,class=>wiki,title=>"%res(name=>GoToWikiPageLicenseLink);"p);  
 EOH  
   
 SuikaWiki::View->template ('navbar')->add_line (<<"EOH");  
 %anchor-wiki(mode=>edit,rel=>edit,class=>wiki-cmd,label=>"%res(name=>EditThisPage);"p,title=>"%res(name=>EditThisPageLong);"p,accesskey=>E,add-param=>{#edit});  
 %anchor-wiki(rel=>view,up_to_date,class=>wiki-cmd,label=>"%res(name=>ViewThisPage);"p,title=>"%res(name=>ViewThisPageLong);"p);  
 %anchor-wiki(page=>{$main::PageName{CreatePage}},class=>wiki,label=>"%res(name=>GoToCreatePage);"p,title=>"%res(name=>GoToCreatePageLong);"p);  
 %anchor-wiki(page=>{$main::PageName{SearchPage}},class=>wiki,label=>"%res(name=>GoToSearchPage);"p,title=>"%res(name=>GoToSearchPageLong);"p);  
 %anchor-wiki(mode=>RandomJump,up-to-date,rel=>lucky,class=>"wiki randomlink",label=>"%res(name=>GoSomewhere);"p,title=>"%res(name=>GoSomewhereLong);"p);  
 %anchor-wiki(page=>{$main::PageName{RecentChanges}},class=>wiki,label=>"%res(name=>GoToRecentChanges);"p,title=>"%res(name=>GoToRecentChangesLong,safe);"p);  
 EOH  
   
 push @{$SuikaWiki::Plugin::On{Load}}, sub {  
   SuikaWiki::View->definition ('read')->property (template => <<'EOH');  
 %html-document(title=>{%res(name=>{View:WebPageTitle});}p,link-meta=>{%predefined-template(name=>links);}p,content=>{  
   %section(level=>1,add-to-toc=>0,type=>body,title=>{%ns-short-page-name;}p,heading,content=>{  
     %section(id=>tools1,class=>tools,add-to-toc=>0,content=>{%predefined-template(name=>navbar);}p);  
     %section(level=>2,id=>read,add-to-toc=>0,content=>{  
       %if-calender(month,true=>{  
         %format(context=>form_input,template=>{%calender;});  
       },false=>{  
         %if-calender(true=>{  
           %format(context=>form_input,template=>{%calender-months;});  
         });  
       });  
       %read(comment);  
     }p);  
     %section(level=>2,id=>children,title=>{%res(name=>{Children:Title});}p,heading,  
     content=>{%page-list(ns=>{%page-name;}p,recursive=>0,type=>both,template=>{%res(name=>{Children:Item});}p);}p);  
     %section(level=>2,id=>see-also,title=>{%res(name=>SeeAlso);}p,heading,content=>{%search-result;}p);  
     %section(level=>2,id=>referer,title=>{%res(name=>Referer);}p,heading,content=>{%referer-list;}p);  
     %section(level=>2,id=>toc,title=>{%res(name=>{TOC:Title});}p,heading,add_to_toc=>0,content=>{%toc(drag);}p);  
     %section(id=>last-modified,add_to_toc=>0,content=>{%res(name=>{LastModified=});%last-modified;}p);  
     %section(class=>tools,add_to_toc=>0,content=>{%predefined-template(name=>navbar);}p);  
     %section(id=>footer,add-to-toc=>0,content=>{%predefined-template(name=>footer);}p);  
   }p);  
 }p);%log-hotness;  
 EOH  
   SuikaWiki::View->definition ('-wrote')->property (template => SuikaWiki::View->definition ('-wrote')->property ('template').q(%log-hotness(weight=>2);));  
   SuikaWiki::View->definition ('WithMenu')->property (template => SuikaWiki::View->definition ('WithMenu')->property ('template').q(%log-hotness;));  
265  };  };
266    
267  =head1 NAME  =head1 SEE ALSO
268    
269  suikawiki-config.ph --- SuikaWiki: site configuration script  C<lib/suikawiki.pl>, C<wiki.cgi>,
270    <http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SuikaWiki>,
271    <http://suika.fam.cx/~wakaba/-temp/wiki/wiki?SWHCS>
272    
273  =head1 LICENSE  =head1 LICENSE
274    
275  Copyright 2003 Wakaba <w@suika.fam.cx>  Copyright 2003-2004 Wakaba <w@suika.fam.cx>.  All rights reserved.
276    
277  This program is free software; you can redistribute it and/or  This program is free software; you can redistribute it and/or
278  modify it under the same terms as Perl itself.  modify it under the same terms as Perl itself.

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.12.4.5

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24