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

Legend:
Removed from v.1.12.4.7  
changed lines
  Added in v.1.12.4.8

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24