OSDN Git Service

651f043db296432a5770d5a23ade34537005e343
[pukiwiki/pukiwiki.git] / lib / pukiwiki.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: pukiwiki.php,v 1.21 2007/08/26 15:17:28 henoheno Exp $
4 //
5 // PukiWiki 1.4.*
6 //  Copyright (C) 2002-2007 by PukiWiki Developers Team
7 //  http://pukiwiki.sourceforge.jp/
8 //
9 // PukiWiki 1.3.*
10 //  Copyright (C) 2002-2004 by PukiWiki Developers Team
11 //  http://pukiwiki.sourceforge.jp/
12 //
13 // PukiWiki 1.3 (Base)
14 //  Copyright (C) 2001-2002 by yu-ji <sng@factage.com>
15 //  http://factage.com/sng/pukiwiki/
16 //
17 // Special thanks
18 //  YukiWiki by Hiroshi Yuki <hyuki@hyuki.com>
19 //  http://www.hyuki.com/yukiwiki/
20 //
21 // This program is free software; you can redistribute it and/or modify
22 // it under the terms of the GNU General Public License as published by
23 // the Free Software Foundation; either version 2 of the License, or
24 // (at your option) any later version.
25 //
26 // This program is distributed in the hope that it will be useful,
27 // but WITHOUT ANY WARRANTY; without even the implied warranty of
28 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29 // GNU General Public License for more details.
30
31 if (! defined('DATA_HOME')) define('DATA_HOME', '');
32
33 /////////////////////////////////////////////////
34 // Include subroutines
35
36 if (! defined('LIB_DIR')) define('LIB_DIR', '');
37
38 require(LIB_DIR . 'func.php');
39 require(LIB_DIR . 'file.php');
40 require(LIB_DIR . 'plugin.php');
41 require(LIB_DIR . 'html.php');
42 require(LIB_DIR . 'backup.php');
43
44 require(LIB_DIR . 'convert_html.php');
45 require(LIB_DIR . 'make_link.php');
46 require(LIB_DIR . 'diff.php');
47 require(LIB_DIR . 'config.php');
48 require(LIB_DIR . 'link.php');
49 require(LIB_DIR . 'auth.php');
50 require(LIB_DIR . 'proxy.php');
51 if (! extension_loaded('mbstring')) {
52         require(LIB_DIR . 'mbstring.php');
53 }
54
55 // Defaults
56 $notify = 0;
57
58 // Load *.ini.php files and init PukiWiki
59 require(LIB_DIR . 'init.php');
60
61 // Load optional libraries
62 if ($notify) {
63         require(LIB_DIR . 'mail.php'); // Mail notification
64 }
65
66 /////////////////////////////////////////////////
67 // Main
68
69 $retvars = array();
70 $page  = isset($vars['page'])  ? $vars['page']  : '';
71 $refer = isset($vars['refer']) ? $vars['refer'] : '';
72
73 if (isset($vars['cmd'])) {
74         $plugin = & $vars['cmd'];
75 } else if (isset($vars['plugin'])) {
76         $plugin = & $vars['plugin'];
77 } else {
78         $plugin = '';
79 }
80
81 // Spam filtering
82 if ($spam && $method != 'GET') {
83         // Adjustment
84         $_spam   = ! empty($spam);
85         $_plugin = strtolower($plugin);
86         $_ignore = array();
87
88         switch ($_plugin) {
89                 case 'search': $_spam = FALSE; break;
90                 case 'edit':
91                         $_page = & $page;
92                         if (isset($vars['add']) && $vars['add']) {
93                                 $_plugin = 'add';
94                         } else {
95                                 $_ignore[] = 'original';
96                         }
97                         break;
98                 case 'bugtrack': $_page = & $vars['base'];  break;
99                 case 'tracker':  $_page = & $vars['_base']; break;
100                 case 'read':     $_page = & $page;  break;
101                 default: $_page = & $refer; break;
102         }
103
104         if ($_spam) {
105                 require(LIB_DIR . 'spam.php');
106                 require(LIB_DIR . 'spam_pickup.php');
107
108                 if (isset($spam['method'][$_plugin])) {
109                         $_method = & $spam['method'][$_plugin];
110                 } else if (isset($spam['method']['_default'])) {
111                         $_method = & $spam['method']['_default'];
112                 } else {
113                         $_method = array();
114                 }
115                 $exitmode = isset($spam['exitmode']) ? $spam['exitmode'] : '';
116
117                 // Hack: ignorance several keys
118                 if ($_ignore) {
119                         $_vars = array();
120                         foreach($vars as $key => $value) {
121                                 $_vars[$key] = & $vars[$key];
122                         }
123                         foreach($_ignore as $key) {
124                                 unset($_vars[$key]);
125                         }
126                 } else {
127                         $_vars = & $vars;
128                 }
129
130                 pkwk_spamfilter($method . ' to #' . $_plugin, $_page, $_vars, $_method, $exitmode);
131         }
132 }
133
134 // Plugin execution
135 if ($plugin != '') {
136         if (exist_plugin_action($plugin)) {
137                 $retvars = do_plugin_action($plugin);
138                 if ($retvars === FALSE) exit; // Done
139
140                 // Rescan $vars (Some plugins rewrite it)
141                 if (isset($vars['cmd'])) {
142                         $base = isset($vars['page'])  ? $vars['page']  : '';
143                 } else {
144                         $base = isset($vars['refer']) ? $vars['refer'] : '';
145                 }
146         } else {
147                 $msg = 'plugin=' . htmlspecialchars($plugin) . ' is not implemented.';
148                 $retvars = array('msg'=>$msg,'body'=>$msg);
149                 $base    = & $defaultpage;
150         }
151 }
152
153 // Page output
154 $title = htmlspecialchars(strip_bracket($base));
155 $page  = make_search($base);
156 if (isset($retvars['msg']) && $retvars['msg'] != '') {
157         $title = str_replace('$1', $title, $retvars['msg']);
158         $page  = str_replace('$1', $page,  $retvars['msg']);
159 }
160
161 if (isset($retvars['body']) && $retvars['body'] != '') {
162         $body = & $retvars['body'];
163 } else {
164         if ($base == '' || ! is_page($base)) {
165                 $base  = & $defaultpage;
166                 $title = htmlspecialchars(strip_bracket($base));
167                 $page  = make_search($base);
168         }
169
170         $vars['cmd']  = 'read';
171         $vars['page'] = & $base;
172
173         $body  = convert_html(get_source($base));
174 }
175
176 // Output
177 catbody($title, $page, $body);
178 exit;
179 ?>