2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: init.php,v 1.42 2003/04/30 08:16:30 arino Exp $
8 /////////////////////////////////////////////////
9 // ½é´üÀßÄê (¥¨¥é¡¼½ÐÎÏ¥ì¥Ù¥ë)
10 // (E_WARNING | E_NOTICE)¤ò½ü³°¤·¤Æ¤¤¤Þ¤¹¡£
11 error_reporting(E_ERROR | E_PARSE);
13 /////////////////////////////////////////////////
14 // ½é´üÀßÄê (ʸ»ú¥¨¥ó¥³¡¼¥É¡¢¸À¸ì)
15 define('SOURCE_ENCODING','EUC-JP');
17 mb_internal_encoding(SOURCE_ENCODING);
18 mb_http_output(SOURCE_ENCODING);
20 /////////////////////////////////////////////////
21 // ½é´üÀßÄê(ÀßÄê¥Õ¥¡¥¤¥ë¤Î¾ì½ê)
22 define('INI_FILE','./pukiwiki.ini.php');
24 /////////////////////////////////////////////////
25 // ½é´üÀßÄê (¥Ð¡¼¥¸¥ç¥ó/Ãøºî¸¢)
26 define('S_VERSION','1.4rc2');
27 define('S_COPYRIGHT','
28 <strong>"PukiWiki" '.S_VERSION.'</strong> Copyright © 2001,2002,2003
29 <a href="http://pukiwiki.org">PukiWiki Developers Team</a>.
30 License is <a href="http://www.gnu.org/">GNU/GPL</a>.<br />
31 Based on "PukiWiki" 1.3 by <a href="http://factage.com/sng/">sng</a>
34 /////////////////////////////////////////////////
35 // ½é´üÀßÄê (¥µ¡¼¥ÐÊÑ¿ô)
36 foreach (array('HTTP_USER_AGENT','PHP_SELF','SERVER_NAME','SERVER_SOFTWARE','SERVER_ADMIN') as $key) {
37 define($key,array_key_exists($key,$HTTP_SERVER_VARS) ? $HTTP_SERVER_VARS[$key] : '');
40 /////////////////////////////////////////////////
41 // ½é´üÀßÄê (¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
45 $foot_explain = array();
48 // <head>Æâ¤ËÄɲ乤륿¥°
51 /////////////////////////////////////////////////
53 define('LOCALZONE',date('Z'));
54 define('UTIME',time() - LOCALZONE);
55 define('MUTIME',getmicrotime());
57 /////////////////////////////////////////////////
58 // ¸À¸ì¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
59 if (!file_exists(LANG.'.lng')||!is_readable(LANG.'.lng')) {
60 die_message(LANG.'.lng(language file) is not found.');
64 /////////////////////////////////////////////////
65 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
66 if (!file_exists(INI_FILE)||!is_readable(INI_FILE)) {
67 die_message(INI_FILE.' is not found.');
71 /////////////////////////////////////////////////
73 if (!isset($script) or $script == '') {
74 $script = ($_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://');
75 $script .= $_SERVER['SERVER_NAME'];
76 $script .= ($_SERVER['SERVER_PORT'] == 80 ? '' : ':'.$_SERVER['SERVER_PORT']);
77 $parse_url = parse_url($_SERVER['REQUEST_URI']);
78 $script .= (isset($parse_url['path']) ? $parse_url['path'] : $_SERVER['SCRIPT_NAME']);
80 if (php_sapi_name() == 'cgi' && !preg_match("/^http:\/\/[-a-zA-Z0-9\@:;_.]+\//",$script)) {
81 die_message("please set '\$script' in ".INI_FILE);
84 /////////////////////////////////////////////////
85 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß(UserAgent)
86 foreach ($agents as $agent) {
87 if (preg_match($agent['pattern'],HTTP_USER_AGENT,$matches)) {
88 $agent['matches'] = $matches;
93 define('UA_INI_FILE',$user_agent['name'].'.ini.php');
95 if (!file_exists(UA_INI_FILE)||!is_readable(UA_INI_FILE)) {
96 die_message(UA_INI_FILE.' is not found.');
100 /////////////////////////////////////////////////
101 // ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÊÑ¿ô¥Á¥§¥Ã¥¯
102 if(!is_writable(DATA_DIR)) {
103 die_message('DATA_DIR is not found or not writable.');
105 if(!is_writable(DIFF_DIR)) {
106 die_message('DIFF_DIR is not found or not writable.');
108 if($do_backup && !is_writable(BACKUP_DIR)) {
109 die_message('BACKUP_DIR is not found or not writable.');
111 if(!is_writable(CACHE_DIR)) {
112 die_message('CACHE_DIR is not found or not writable.');
114 $wrong_ini_file = '';
115 if (!isset($rss_max)) $wrong_ini_file .= '$rss_max ';
116 if (!isset($page_title)) $wrong_ini_file .= '$page_title ';
117 if (!isset($note_hr)) $wrong_ini_file .= '$note_hr ';
118 if (!isset($related_link)) $wrong_ini_file .= '$related_link ';
119 if (!isset($show_passage)) $wrong_ini_file .= '$show_passage ';
120 if (!isset($rule_related_str)) $wrong_ini_file .= '$rule_related_str ';
121 if (!isset($load_template_func)) $wrong_ini_file .= '$load_template_func ';
122 if (!defined('LANG')) $wrong_ini_file .= 'LANG ';
123 if (!defined('PLUGIN_DIR')) $wrong_ini_file .= 'PLUGIN_DIR ';
124 if ($wrong_ini_file) {
125 die_message('The setting file runs short of information.<br>The version of a setting file may be old.<br><br>These option are not found : '.$wrong_ini_file);
127 if (!is_page($defaultpage)) {
128 touch(get_filename($defaultpage));
130 if (!is_page($whatsnew)) {
131 touch(get_filename($whatsnew));
133 if (!is_page($interwiki)) {
134 touch(get_filename($interwiki));
137 /////////////////////////////////////////////////
139 if (get_magic_quotes_gpc()) {
140 $get = $post = $cookie = array();
141 foreach($HTTP_GET_VARS as $key => $value) {
142 if (!is_array($value)) {
143 $get[$key] = stripslashes($value);
146 foreach($HTTP_POST_VARS as $key => $value) {
147 $post[$key] = stripslashes($value);
149 foreach($HTTP_COOKIE_VARS as $key => $value) {
150 $cookie[$key] = stripslashes($value);
154 $post = is_array($HTTP_POST_VARS) ? $HTTP_POST_VARS : array();
155 $get = is_array($HTTP_GET_VARS) ? $HTTP_GET_VARS : array();
156 $cookie = is_array($HTTP_COOKIE_VARS) ? $HTTP_COOKIE_VARS : array();
159 // ³°Éô¤«¤é¤¯¤ëÊÑ¿ô¤ò¥µ¥Ë¥¿¥¤¥º
160 $get = sanitize_null_character($get);
161 $post = sanitize_null_character($post);
162 $cookie = sanitize_null_character($cookie);
164 // ¥Ý¥¹¥È¤µ¤ì¤¿Ê¸»ú¤Î¥³¡¼¥É¤òÊÑ´¹
165 // original by nitoyon (2003/02/20)
166 $encode = mb_detect_encoding(join('',array_merge($post,$get)));
167 if ($encode != 'ASCII' and $encode != SOURCE_ENCODING) {
168 foreach(array_keys($get) as $key) {
169 $get[$key] = mb_convert_encoding($get[$key],SOURCE_ENCODING,$encode);
171 foreach(array_keys($post) as $key) {
172 $post[$key] = mb_convert_encoding($post[$key],SOURCE_ENCODING,$encode);
176 if (!empty($get['page'])) {
177 $get['page'] = strip_bracket($get['page']);
179 if (!empty($post['page'])) {
180 $post['page'] = strip_bracket($post['page']);
182 if (!empty($post['msg'])) {
183 $post['msg'] = str_replace("\r",'',$post['msg']);
186 $vars = array_merge($post,$get);
187 if (!array_key_exists('page',$vars)) {
188 $get['page'] = $post['page'] = $vars['page'] = '';
191 // ¸åÊý¸ß´¹À (?md5=...)
192 if (array_key_exists('md5',$vars) and $vars['md5'] != '') {
193 $vars['cmd'] = 'md5';
196 // cmd¤âplugin¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢QUERY_STRING¤ò¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹
197 if (!array_key_exists('cmd',$vars) and !array_key_exists('plugin',$vars))
199 if ($HTTP_SERVER_VARS['QUERY_STRING'] != '')
201 $arg = $HTTP_SERVER_VARS['QUERY_STRING'];
203 else if (array_key_exists(0,$HTTP_SERVER_VARS['argv']))
205 $arg = $HTTP_SERVER_VARS['argv'][0];
209 //¤Ê¤Ë¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï$defaultpage¤òɽ¼¨
212 $arg = rawurldecode($arg);
213 $arg = strip_bracket($arg);
214 $arg = sanitize_null_character($arg);
216 $get['cmd'] = $post['cmd'] = $vars['cmd'] = 'read';
217 $get['page'] = $post['page'] = $vars['page'] = $arg;
220 /////////////////////////////////////////////////
221 // ½é´üÀßÄê($WikiName,$BracketName¤Ê¤É)
222 // $WikiName = '[A-Z][a-z]+(?:[A-Z][a-z]+)+';
223 // $WikiName = '\b[A-Z][a-z]+(?:[A-Z][a-z]+)+\b';
224 // $WikiName = '(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])';
225 // $WikiName = '(?<!\w)(?:[A-Z][a-z]+){2,}(?!\w)';
226 // BugTrack/304»ÃÄêÂнè
227 $WikiName = '(?:[A-Z][a-z]+){2,}(?!\w)';
228 // $BracketName = ':?[^\s\]#&<>":]+:?';
229 $BracketName = '(?!\s):?[^\r\n\t\f\[\]<>#&":]+:?(?<!\s)';
231 $InterWikiName = "(\[\[)?(\[*[^\s\]]+?\]*):(\[*[^>\]]+?\]*)(?(1)\]\])";
233 $NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/ex';
235 /////////////////////////////////////////////////
236 // ½é´üÀßÄê(¤½¤Î¾¤Î¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
238 $now = format_date(UTIME);
239 // skinÆâ¤ÇDTDÀë¸À¤òÀÚ¤êÂؤ¨¤ë¤Î¤Ë»ÈÍÑ¡£paint.inc.phpÂкö
241 // TRUE :XHTML 1.0 Transitional
242 $html_transitional = FALSE;
243 // ¥Õ¥§¥¤¥¹¥Þ¡¼¥¯¤ò$line_rules¤Ë²Ã¤¨¤ë
246 $line_rules += $facemark_rules;