OSDN Git Service

BugTrack/555 mbstring設定
[pukiwiki/pukiwiki.git] / init.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: init.php,v 1.71 2004/03/13 13:43:46 arino Exp $
6 //
7
8 /////////////////////////////////////////////////
9 // ½é´üÀßÄê (¥¨¥é¡¼½ÐÎÏ¥ì¥Ù¥ë)
10 // (E_WARNING | E_NOTICE)¤ò½ü³°¤·¤Æ¤¤¤Þ¤¹¡£
11 error_reporting(E_ERROR | E_PARSE);
12
13 /////////////////////////////////////////////////
14 // ½é´üÀßÄê (ʸ»ú¥¨¥ó¥³¡¼¥É¡¢¸À¸ì)
15 define('SOURCE_ENCODING','EUC-JP');
16 define('LANG','ja');
17
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');
23
24
25 /////////////////////////////////////////////////
26 // ½é´üÀßÄê(ÀßÄê¥Õ¥¡¥¤¥ë¤Î¾ì½ê)
27 define('INI_FILE','./pukiwiki.ini.php');
28
29 /////////////////////////////////////////////////
30 // ½é´üÀßÄê (¥Ð¡¼¥¸¥ç¥ó/Ãøºî¸¢)
31 define('S_VERSION','1.4.2');
32 define('S_COPYRIGHT','
33 <strong>"PukiWiki" '.S_VERSION.'</strong> Copyright &copy; 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>
37 ');
38
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] : '');
43 }
44
45 /////////////////////////////////////////////////
46 // ½é´üÀßÄê (¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
47 // ¥µ¡¼¥Ð¤«¤éÍè¤ëÊÑ¿ô
48 $vars = array();
49 // µÓÃí
50 $foot_explain = array();
51 // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
52 $related = array();
53 // <head>Æâ¤ËÄɲ乤륿¥°
54 $head_tags = array();
55
56 /////////////////////////////////////////////////
57 // ½é´üÀßÄê(»þ´Ö)
58 define('LOCALZONE',date('Z'));
59 define('UTIME',time() - LOCALZONE);
60 define('MUTIME',getmicrotime());
61
62 /////////////////////////////////////////////////
63 // ¸À¸ì¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
64 if (!file_exists(LANG.'.lng')||!is_readable(LANG.'.lng')) {
65         die_message(LANG.'.lng(language file) is not found.');
66 }
67 require(LANG.'.lng');
68
69 /////////////////////////////////////////////////
70 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
71 if (!file_exists(INI_FILE)||!is_readable(INI_FILE)) {
72         die_message(INI_FILE.' is not found.');
73 }
74 require(INI_FILE);
75
76 /////////////////////////////////////////////////
77 // ½é´üÀßÄê($script)
78 if (!isset($script) or $script == '') {
79         $script = get_script_uri();
80 }
81 if ($script === FALSE or (php_sapi_name() == 'cgi' and !is_url($script,TRUE)))
82 {
83         die_message('please set "$script" in pukiwiki.ini.php.');
84 }
85
86 /////////////////////////////////////////////////
87 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß(UserAgent)
88 foreach ($agents as $agent) {
89         if (preg_match($agent['pattern'],HTTP_USER_AGENT,$matches)) {
90                 $agent['matches'] = $matches;
91                 $user_agent = $agent;
92                 break;
93         }
94 }
95 define('UA_INI_FILE',$user_agent['name'].'.ini.php');
96
97 if (!file_exists(UA_INI_FILE)||!is_readable(UA_INI_FILE)) {
98         die_message(UA_INI_FILE.' is not found.');
99 }
100 require(UA_INI_FILE);
101
102 /////////////////////////////////////////////////
103 // ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÊÑ¿ô¥Á¥§¥Ã¥¯
104 if(!is_writable(DATA_DIR)) {
105         die_message('DATA_DIR is not found or not writable.');
106 }
107 if(!is_writable(DIFF_DIR)) {
108         die_message('DIFF_DIR is not found or not writable.');
109 }
110 if($do_backup && !is_writable(BACKUP_DIR)) {
111         die_message('BACKUP_DIR is not found or not writable.');
112 }
113 if(!is_writable(CACHE_DIR)) {
114         die_message('CACHE_DIR is not found or not writable.');
115 }
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);
128 }
129 if (!is_page($defaultpage)) {
130         touch(get_filename($defaultpage));
131 }
132 if (!is_page($whatsnew)) {
133         touch(get_filename($whatsnew));
134 }
135 if (!is_page($interwiki)) {
136         touch(get_filename($interwiki));
137 }
138
139 /////////////////////////////////////////////////
140 // ³°Éô¤«¤é¤¯¤ëÊÑ¿ô¤ò¥µ¥Ë¥¿¥¤¥º
141 $get    = sanitize($_GET);
142 $post   = sanitize($_POST);
143 $cookie = sanitize($_COOKIE);
144
145 /////////////////////////////////////////////////
146 // Ê¸»ú¥³¡¼¥É¤òÊÑ´¹
147
148 // <form> ¤ÇÁ÷¿®¤µ¤ì¤¿Ê¸»ú (¥Ö¥é¥¦¥¶¤¬¥¨¥ó¥³¡¼¥É¤·¤¿¥Ç¡¼¥¿) ¤Î¥³¡¼¥É¤òÊÑ´¹
149 // post ¤Ï¾ï¤Ë <form> ¤Ê¤Î¤Ç¡¢É¬¤ºÊÑ´¹
150 if (array_key_exists('encode_hint',$post))
151 {
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);
158 }
159 else if (array_key_exists('charset',$post))
160 {
161         // TrackBack Ping¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¤³¤È¤¬¤¢¤ë
162         // »ØÄꤵ¤ì¤¿¾ì¹ç¤Ï¡¢¤½¤ÎÆâÍƤÇÊÑ´¹¤ò»î¤ß¤ë
163         if (mb_convert_variables(SOURCE_ENCODING,$post['charset'],$post) !== $post['charset'])
164         {
165                 // ¤¦¤Þ¤¯¤¤¤«¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¥³¡¼¥É¸¡½Ð¤ÎÀßÄê¤ÇÊÑ´¹¤·¤Ê¤ª¤·
166                 mb_convert_variables(SOURCE_ENCODING,'auto',$post);
167         }
168 }
169 else if (count($post) > 0)
170 {
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);
176 }
177
178 // get ¤Ï <form> ¤«¤é¤Î¾ì¹ç¤È¡¢<a href="http;//script/?query> ¤Î¾ì¹ç¤¬¤¢¤ë
179 if (array_key_exists('encode_hint',$get))
180 {
181         // <form> ¤Î¾ì¹ç¤Ï¡¢¥Ö¥é¥¦¥¶¤¬¥¨¥ó¥³¡¼¥É¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¥³¡¼¥É¸¡½Ð¡¦ÊÑ´¹¤¬É¬Íס£
182         // encode_hint ¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤Ï¤º¤Ê¤Î¤Ç¡¢¤½¤ì¤ò¸«¤Æ¡¢¥³¡¼¥É¸¡½Ð¤·¤¿¸å¡¢ÊÑ´¹¤¹¤ë¡£
183         // Íýͳ¤Ï¡¢post ¤ÈƱÍÍ
184         $encode = mb_detect_encoding($get['encode_hint']);
185         mb_convert_variables(SOURCE_ENCODING,$encode,$get);
186 }       
187 // <a href...> ¤Î¾ì¹ç¤Ï¡¢¥µ¡¼¥Ð¡¼¤¬ rawurlencode ¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¥³¡¼¥ÉÊÑ´¹¤ÏÉÔÍ×
188
189 // QUERY_STRING¤ò¼èÆÀ
190 // cmd¤âplugin¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢QUERY_STRING¤ò¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹°Ù
191 // ¤Þ¤¿¡¢URI ¤ò urlencode ¤»¤º¤Ë¼êÂǤÁ¤ÇÆþÎϤ·¤¿¾ì¹ç¤ËÂн褹¤ë°Ù
192 $arg = '';
193 if (array_key_exists('QUERY_STRING',$_SERVER) and $_SERVER['QUERY_STRING'] != '')
194 {
195         $arg = $_SERVER['QUERY_STRING'];
196 }
197 else if (array_key_exists('argv',$_SERVER) and count($_SERVER['argv']))
198 {
199         $arg = $_SERVER['argv'][0];
200 }
201
202 // ¥µ¥Ë¥¿¥¤¥º (\0 ½üµî)
203 $arg = sanitize($arg);
204
205 // URI ¼êÂǤξì¹ç¡¢¥³¡¼¥ÉÊÑ´¹¤·¡¢get[] ¤Ë¾å½ñ¤­
206 // mb_convert_variables¤Î¥Ð¥°(?)Âкö ÇÛÎó¤ÇÅϤµ¤Ê¤¤¤ÈÍî¤Á¤ë
207 $arg = array($arg);
208 mb_convert_variables(SOURCE_ENCODING,'auto',$arg);
209 $arg = $arg[0];
210
211 foreach (explode('&',$arg) as $tmp_string)
212 {
213         if (preg_match('/^([^=]+)=(.+)/',$tmp_string,$matches)
214                 and mb_detect_encoding($matches[2]) != 'ASCII')
215         {
216                 $get[$matches[1]] = $matches[2];
217         }
218 }
219
220 if (!empty($get['page']))
221 {
222         $get['page']  = strip_bracket($get['page']);
223 }
224 if (!empty($post['page']))
225 {
226         $post['page'] = strip_bracket($post['page']);
227 }
228 if (!empty($post['msg']))
229 {
230         $post['msg']  = str_replace("\r",'',$post['msg']);
231 }
232
233 $vars = array_merge($post,$get);
234 if (!array_key_exists('page',$vars))
235 {
236         $get['page'] = $post['page'] = $vars['page'] = '';
237 }
238
239 // ¸åÊý¸ß´¹À­ (?md5=...)
240 if (array_key_exists('md5',$vars) and $vars['md5'] != '')
241 {
242         $vars['cmd'] = 'md5';
243 }
244
245 // cmd¤âplugin¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢QUERY_STRING¤ò¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹
246 if (!array_key_exists('cmd',$vars)  and !array_key_exists('plugin',$vars))
247 {
248         if ($arg == '')
249         {
250                 //¤Ê¤Ë¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï$defaultpage¤òɽ¼¨
251                 $arg = $defaultpage;
252         }               
253         $arg = rawurldecode($arg);
254         $arg = strip_bracket($arg);
255         $arg = sanitize($arg);
256
257         $get['cmd'] = $post['cmd'] = $vars['cmd'] = 'read';
258         $get['page'] = $post['page'] = $vars['page'] = $arg;
259 }
260
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)';
271 // InterWiki
272 $InterWikiName = "(\[\[)?((?:(?!\s|:|\]\]).)+):(.+)(?(1)\]\])";
273 // Ãí¼á
274 $NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/ex';
275
276 /////////////////////////////////////////////////
277 // ½é´üÀßÄê(¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ëÆɤ߹þ¤ß)
278 require('rules.ini.php');
279
280 /////////////////////////////////////////////////
281 // ½é´üÀßÄê(¤½¤Î¾¤Î¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
282 // ¸½ºß»þ¹ï
283 $now = format_date(UTIME);
284 // skinÆâ¤ÇDTDÀë¸À¤òÀÚ¤êÂؤ¨¤ë¤Î¤Ë»ÈÍÑ¡£paint.inc.phpÂкö
285 // FALSE:XHTML 1.1
286 // TRUE :XHTML 1.0 Transitional
287 $html_transitional = FALSE;
288 // ¥Õ¥§¥¤¥¹¥Þ¡¼¥¯¤ò$line_rules¤Ë²Ã¤¨¤ë
289 if ($usefacemark)
290 {
291         $line_rules += $facemark_rules;
292 }
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         '&amp;(#[0-9]+|#x[0-9a-f]+|'.$entity_pattern.');'=>'&$1;',
299         "\r"=>"<br />\n", /* ¹ÔËö¤Ë¥Á¥ë¥À¤Ï²þ¹Ô */
300         '#related$'=>'<del>#related</del>',
301         '^#contents$'=>'<del>#contents</del>'
302 ),$line_rules);
303 ?>