2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: init.php,v 1.71 2004/03/13 13:43:46 arino Exp $
8 /////////////////////////////////////////////////
9 // ½é´üÀßÄê (¥¨¥é¡¼½ÐÎÏ¥ì¥Ù¥ë)
10 // (E_WARNING | E_NOTICE)¤ò½ü³°¤·¤Æ¤¤¤Þ¤¹¡£
11 error_reporting(E_ERROR | E_PARSE);
13 /////////////////////////////////////////////////
14 // ½é´üÀßÄê (ʸ»ú¥¨¥ó¥³¡¼¥É¡¢¸À¸ì)
15 define('SOURCE_ENCODING','EUC-JP');
18 mb_language('Japanese');
19 mb_internal_encoding(SOURCE_ENCODING);
20 ini_set('mbstring.http_input', 'pass');
21 mb_http_output('pass');
22 mb_detect_order('auto');
25 /////////////////////////////////////////////////
26 // ½é´üÀßÄê(ÀßÄê¥Õ¥¡¥¤¥ë¤Î¾ì½ê)
27 define('INI_FILE','./pukiwiki.ini.php');
29 /////////////////////////////////////////////////
30 // ½é´üÀßÄê (¥Ð¡¼¥¸¥ç¥ó/Ãøºî¸¢)
31 define('S_VERSION','1.4.2');
32 define('S_COPYRIGHT','
33 <strong>"PukiWiki" '.S_VERSION.'</strong> Copyright © 2001,2002,2003
34 <a href="http://pukiwiki.org">PukiWiki Developers Team</a>.
35 License is <a href="http://www.gnu.org/">GNU/GPL</a>.<br />
36 Based on "PukiWiki" 1.3 by <a href="http://factage.com/sng/">sng</a>
39 /////////////////////////////////////////////////
40 // ½é´üÀßÄê (¥µ¡¼¥ÐÊÑ¿ô)
41 foreach (array('HTTP_USER_AGENT','PHP_SELF','SERVER_NAME','SERVER_SOFTWARE','SERVER_ADMIN') as $key) {
42 define($key,array_key_exists($key,$_SERVER) ? $_SERVER[$key] : '');
45 /////////////////////////////////////////////////
46 // ½é´üÀßÄê (¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
50 $foot_explain = array();
53 // <head>Æâ¤ËÄɲ乤륿¥°
56 /////////////////////////////////////////////////
58 define('LOCALZONE',date('Z'));
59 define('UTIME',time() - LOCALZONE);
60 define('MUTIME',getmicrotime());
62 /////////////////////////////////////////////////
63 // ¸À¸ì¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
64 if (!file_exists(LANG.'.lng')||!is_readable(LANG.'.lng')) {
65 die_message(LANG.'.lng(language file) is not found.');
69 /////////////////////////////////////////////////
70 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
71 if (!file_exists(INI_FILE)||!is_readable(INI_FILE)) {
72 die_message(INI_FILE.' is not found.');
76 /////////////////////////////////////////////////
78 if (!isset($script) or $script == '') {
79 $script = get_script_uri();
81 if ($script === FALSE or (php_sapi_name() == 'cgi' and !is_url($script,TRUE)))
83 die_message('please set "$script" in pukiwiki.ini.php.');
86 /////////////////////////////////////////////////
87 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß(UserAgent)
88 foreach ($agents as $agent) {
89 if (preg_match($agent['pattern'],HTTP_USER_AGENT,$matches)) {
90 $agent['matches'] = $matches;
95 define('UA_INI_FILE',$user_agent['name'].'.ini.php');
97 if (!file_exists(UA_INI_FILE)||!is_readable(UA_INI_FILE)) {
98 die_message(UA_INI_FILE.' is not found.');
100 require(UA_INI_FILE);
102 /////////////////////////////////////////////////
103 // ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÊÑ¿ô¥Á¥§¥Ã¥¯
104 if(!is_writable(DATA_DIR)) {
105 die_message('DATA_DIR is not found or not writable.');
107 if(!is_writable(DIFF_DIR)) {
108 die_message('DIFF_DIR is not found or not writable.');
110 if($do_backup && !is_writable(BACKUP_DIR)) {
111 die_message('BACKUP_DIR is not found or not writable.');
113 if(!is_writable(CACHE_DIR)) {
114 die_message('CACHE_DIR is not found or not writable.');
116 $wrong_ini_file = '';
117 if (!isset($rss_max)) $wrong_ini_file .= '$rss_max ';
118 if (!isset($page_title)) $wrong_ini_file .= '$page_title ';
119 if (!isset($note_hr)) $wrong_ini_file .= '$note_hr ';
120 if (!isset($related_link)) $wrong_ini_file .= '$related_link ';
121 if (!isset($show_passage)) $wrong_ini_file .= '$show_passage ';
122 if (!isset($rule_related_str)) $wrong_ini_file .= '$rule_related_str ';
123 if (!isset($load_template_func)) $wrong_ini_file .= '$load_template_func ';
124 if (!defined('LANG')) $wrong_ini_file .= 'LANG ';
125 if (!defined('PLUGIN_DIR')) $wrong_ini_file .= 'PLUGIN_DIR ';
126 if ($wrong_ini_file) {
127 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);
129 if (!is_page($defaultpage)) {
130 touch(get_filename($defaultpage));
132 if (!is_page($whatsnew)) {
133 touch(get_filename($whatsnew));
135 if (!is_page($interwiki)) {
136 touch(get_filename($interwiki));
139 /////////////////////////////////////////////////
140 // ³°Éô¤«¤é¤¯¤ëÊÑ¿ô¤ò¥µ¥Ë¥¿¥¤¥º
141 $get = sanitize($_GET);
142 $post = sanitize($_POST);
143 $cookie = sanitize($_COOKIE);
145 /////////////////////////////////////////////////
148 // <form> ¤ÇÁ÷¿®¤µ¤ì¤¿Ê¸»ú (¥Ö¥é¥¦¥¶¤¬¥¨¥ó¥³¡¼¥É¤·¤¿¥Ç¡¼¥¿) ¤Î¥³¡¼¥É¤òÊÑ´¹
149 // post ¤Ï¾ï¤Ë <form> ¤Ê¤Î¤Ç¡¢É¬¤ºÊÑ´¹
150 if (array_key_exists('encode_hint',$post))
152 // html.php ¤ÎÃæ¤Ç¡¢<form> ¤Ë encode_hint ¤ò»Å¹þ¤ó¤Ç¤¤¤ë¤Î¤Ç¡¢É¬¤º encode_hint ¤¬¤¢¤ë¤Ï¤º¡£
153 // encode_hint ¤Î¤ß¤òÍѤ¤¤Æ¥³¡¼¥É¸¡½Ð¤¹¤ë¡£
154 // Á´ÂΤò¸«¤Æ¥³¡¼¥É¸¡½Ð¤¹¤ë¤È¡¢µ¡¼ï°Í¸ʸ»ú¤ä¡¢Ì¯¤Ê¥Ð¥¤¥Ê¥ê¥³¡¼¥É¤¬º®Æþ¤·¤¿¾ì¹ç¤Ë¡¢
155 // ¥³¡¼¥É¸¡½Ð¤Ë¼ºÇÔ¤¹¤ë¶²¤ì¤¬¤¢¤ë¤¿¤á¡£
156 $encode = mb_detect_encoding($post['encode_hint']);
157 mb_convert_variables(SOURCE_ENCODING,$encode,$post);
159 else if (array_key_exists('charset',$post))
161 // TrackBack Ping¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¤³¤È¤¬¤¢¤ë
162 // »ØÄꤵ¤ì¤¿¾ì¹ç¤Ï¡¢¤½¤ÎÆâÍƤÇÊÑ´¹¤ò»î¤ß¤ë
163 if (mb_convert_variables(SOURCE_ENCODING,$post['charset'],$post) !== $post['charset'])
165 // ¤¦¤Þ¤¯¤¤¤«¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¥³¡¼¥É¸¡½Ð¤ÎÀßÄê¤ÇÊÑ´¹¤·¤Ê¤ª¤·
166 mb_convert_variables(SOURCE_ENCODING,'auto',$post);
169 else if (count($post) > 0)
171 // encode_hint ¤¬Ìµ¤¤¤È¤¤¤¦¤³¤È¤Ï¡¢Ìµ¤¤¤Ï¤º¡£
172 // ¥Ç¥Ð¥Ã¥°ÍѤˡ¢¼è¤ê¤¢¤¨¤º¡¢·Ù¹ð¥á¥Ã¥»¡¼¥¸¤ò½Ð¤·¤Æ¤ª¤¤Þ¤¹¡£
173 // echo "<p>Warning: 'encode_hint' field is not found in the posted data.</p>\n";
174 // Á´Éô¤Þ¤È¤á¤Æ¡¢¥³¡¼¥É¸¡½Ð¡¢ÊÑ´¹
175 mb_convert_variables(SOURCE_ENCODING,'auto',$post);
178 // get ¤Ï <form> ¤«¤é¤Î¾ì¹ç¤È¡¢<a href="http;//script/?query> ¤Î¾ì¹ç¤¬¤¢¤ë
179 if (array_key_exists('encode_hint',$get))
181 // <form> ¤Î¾ì¹ç¤Ï¡¢¥Ö¥é¥¦¥¶¤¬¥¨¥ó¥³¡¼¥É¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¥³¡¼¥É¸¡½Ð¡¦ÊÑ´¹¤¬É¬Íס£
182 // encode_hint ¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤Ï¤º¤Ê¤Î¤Ç¡¢¤½¤ì¤ò¸«¤Æ¡¢¥³¡¼¥É¸¡½Ð¤·¤¿¸å¡¢ÊÑ´¹¤¹¤ë¡£
183 // Íýͳ¤Ï¡¢post ¤ÈƱÍÍ
184 $encode = mb_detect_encoding($get['encode_hint']);
185 mb_convert_variables(SOURCE_ENCODING,$encode,$get);
187 // <a href...> ¤Î¾ì¹ç¤Ï¡¢¥µ¡¼¥Ð¡¼¤¬ rawurlencode ¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¥³¡¼¥ÉÊÑ´¹¤ÏÉÔÍ×
189 // QUERY_STRING¤ò¼èÆÀ
190 // cmd¤âplugin¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢QUERY_STRING¤ò¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹°Ù
191 // ¤Þ¤¿¡¢URI ¤ò urlencode ¤»¤º¤Ë¼êÂǤÁ¤ÇÆþÎϤ·¤¿¾ì¹ç¤ËÂн褹¤ë°Ù
193 if (array_key_exists('QUERY_STRING',$_SERVER) and $_SERVER['QUERY_STRING'] != '')
195 $arg = $_SERVER['QUERY_STRING'];
197 else if (array_key_exists('argv',$_SERVER) and count($_SERVER['argv']))
199 $arg = $_SERVER['argv'][0];
202 // ¥µ¥Ë¥¿¥¤¥º (\0 ½üµî)
203 $arg = sanitize($arg);
205 // URI ¼êÂǤξì¹ç¡¢¥³¡¼¥ÉÊÑ´¹¤·¡¢get[] ¤Ë¾å½ñ¤
206 // mb_convert_variables¤Î¥Ð¥°(?)Âкö ÇÛÎó¤ÇÅϤµ¤Ê¤¤¤ÈÍî¤Á¤ë
208 mb_convert_variables(SOURCE_ENCODING,'auto',$arg);
211 foreach (explode('&',$arg) as $tmp_string)
213 if (preg_match('/^([^=]+)=(.+)/',$tmp_string,$matches)
214 and mb_detect_encoding($matches[2]) != 'ASCII')
216 $get[$matches[1]] = $matches[2];
220 if (!empty($get['page']))
222 $get['page'] = strip_bracket($get['page']);
224 if (!empty($post['page']))
226 $post['page'] = strip_bracket($post['page']);
228 if (!empty($post['msg']))
230 $post['msg'] = str_replace("\r",'',$post['msg']);
233 $vars = array_merge($post,$get);
234 if (!array_key_exists('page',$vars))
236 $get['page'] = $post['page'] = $vars['page'] = '';
239 // ¸åÊý¸ß´¹À (?md5=...)
240 if (array_key_exists('md5',$vars) and $vars['md5'] != '')
242 $vars['cmd'] = 'md5';
245 // cmd¤âplugin¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢QUERY_STRING¤ò¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹
246 if (!array_key_exists('cmd',$vars) and !array_key_exists('plugin',$vars))
250 //¤Ê¤Ë¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï$defaultpage¤òɽ¼¨
253 $arg = rawurldecode($arg);
254 $arg = strip_bracket($arg);
255 $arg = sanitize($arg);
257 $get['cmd'] = $post['cmd'] = $vars['cmd'] = 'read';
258 $get['page'] = $post['page'] = $vars['page'] = $arg;
261 /////////////////////////////////////////////////
262 // ½é´üÀßÄê($WikiName,$BracketName¤Ê¤É)
263 // $WikiName = '[A-Z][a-z]+(?:[A-Z][a-z]+)+';
264 // $WikiName = '\b[A-Z][a-z]+(?:[A-Z][a-z]+)+\b';
265 // $WikiName = '(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])';
266 // $WikiName = '(?<!\w)(?:[A-Z][a-z]+){2,}(?!\w)';
267 // BugTrack/304»ÃÄêÂнè
268 $WikiName = '(?:[A-Z][a-z]+){2,}(?!\w)';
269 // $BracketName = ':?[^\s\]#&<>":]+:?';
270 $BracketName = '(?!\s):?[^\r\n\t\f\[\]<>#&":]+:?(?<!\s)';
272 $InterWikiName = "(\[\[)?((?:(?!\s|:|\]\]).)+):(.+)(?(1)\]\])";
274 $NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/ex';
276 /////////////////////////////////////////////////
277 // ½é´üÀßÄê(¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ëÆɤ߹þ¤ß)
278 require('rules.ini.php');
280 /////////////////////////////////////////////////
281 // ½é´üÀßÄê(¤½¤Î¾¤Î¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
283 $now = format_date(UTIME);
284 // skinÆâ¤ÇDTDÀë¸À¤òÀÚ¤êÂؤ¨¤ë¤Î¤Ë»ÈÍÑ¡£paint.inc.phpÂкö
286 // TRUE :XHTML 1.0 Transitional
287 $html_transitional = FALSE;
288 // ¥Õ¥§¥¤¥¹¥Þ¡¼¥¯¤ò$line_rules¤Ë²Ã¤¨¤ë
291 $line_rules += $facemark_rules;
293 unset($facemark_rules);
294 // ¼ÂÂλ²¾È¥Ñ¥¿¡¼¥ó¤ª¤è¤Ó¥·¥¹¥Æ¥à¤Ç»ÈÍѤ¹¤ë¥Ñ¥¿¡¼¥ó¤ò$line_rules¤Ë²Ã¤¨¤ë
295 //$entity_pattern = '[a-zA-Z0-9]{2,8}';
296 $entity_pattern = trim(join('',file(CACHE_DIR.'entities.dat')));
297 $line_rules = array_merge(array(
298 '&(#[0-9]+|#x[0-9a-f]+|'.$entity_pattern.');'=>'&$1;',
299 "\r"=>"<br />\n", /* ¹ÔËö¤Ë¥Á¥ë¥À¤Ï²þ¹Ô */
300 '#related$'=>'<del>#related</del>',
301 '^#contents$'=>'<del>#contents</del>'