OSDN Git Service

BugTrack/323: accesskey属性を削除
[pukiwiki/pukiwiki.git] / init.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: init.php,v 1.42 2003/04/30 08:16:30 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 mb_internal_encoding(SOURCE_ENCODING);
18 mb_http_output(SOURCE_ENCODING);
19
20 /////////////////////////////////////////////////
21 // ½é´üÀßÄê(ÀßÄê¥Õ¥¡¥¤¥ë¤Î¾ì½ê)
22 define('INI_FILE','./pukiwiki.ini.php');
23
24 /////////////////////////////////////////////////
25 // ½é´üÀßÄê (¥Ð¡¼¥¸¥ç¥ó/Ãøºî¸¢)
26 define('S_VERSION','1.4rc2');
27 define('S_COPYRIGHT','
28 <strong>"PukiWiki" '.S_VERSION.'</strong> Copyright &copy; 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>
32 ');
33
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] : '');
38 }
39
40 /////////////////////////////////////////////////
41 // ½é´üÀßÄê (¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
42 // ¥µ¡¼¥Ð¤«¤éÍè¤ëÊÑ¿ô
43 $vars = array();
44 // µÓÃí
45 $foot_explain = array();
46 // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
47 $related = array();
48 // <head>Æâ¤ËÄɲ乤륿¥°
49 $head_tags = array();
50
51 /////////////////////////////////////////////////
52 // ½é´üÀßÄê(»þ´Ö)
53 define('LOCALZONE',date('Z'));
54 define('UTIME',time() - LOCALZONE);
55 define('MUTIME',getmicrotime());
56
57 /////////////////////////////////////////////////
58 // ¸À¸ì¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
59 if (!file_exists(LANG.'.lng')||!is_readable(LANG.'.lng')) {
60         die_message(LANG.'.lng(language file) is not found.');
61 }
62 require(LANG.'.lng');
63
64 /////////////////////////////////////////////////
65 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß
66 if (!file_exists(INI_FILE)||!is_readable(INI_FILE)) {
67         die_message(INI_FILE.' is not found.');
68 }
69 require(INI_FILE);
70
71 /////////////////////////////////////////////////
72 // ½é´üÀßÄê($script)
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']);
79 }
80 if (php_sapi_name() == 'cgi' && !preg_match("/^http:\/\/[-a-zA-Z0-9\@:;_.]+\//",$script)) {
81         die_message("please set '\$script' in ".INI_FILE);
82 }
83
84 /////////////////////////////////////////////////
85 // ÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß(UserAgent)
86 foreach ($agents as $agent) {
87         if (preg_match($agent['pattern'],HTTP_USER_AGENT,$matches)) {
88                 $agent['matches'] = $matches;
89                 $user_agent = $agent;
90                 break;
91         }
92 }
93 define('UA_INI_FILE',$user_agent['name'].'.ini.php');
94
95 if (!file_exists(UA_INI_FILE)||!is_readable(UA_INI_FILE)) {
96         die_message(UA_INI_FILE.' is not found.');
97 }
98 require(UA_INI_FILE);
99
100 /////////////////////////////////////////////////
101 // ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÊÑ¿ô¥Á¥§¥Ã¥¯
102 if(!is_writable(DATA_DIR)) {
103         die_message('DATA_DIR is not found or not writable.');
104 }
105 if(!is_writable(DIFF_DIR)) {
106         die_message('DIFF_DIR is not found or not writable.');
107 }
108 if($do_backup && !is_writable(BACKUP_DIR)) {
109         die_message('BACKUP_DIR is not found or not writable.');
110 }
111 if(!is_writable(CACHE_DIR)) {
112         die_message('CACHE_DIR is not found or not writable.');
113 }
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);
126 }
127 if (!is_page($defaultpage)) {
128         touch(get_filename($defaultpage));
129 }
130 if (!is_page($whatsnew)) {
131         touch(get_filename($whatsnew));
132 }
133 if (!is_page($interwiki)) {
134         touch(get_filename($interwiki));
135 }
136
137 /////////////////////////////////////////////////
138 // ÆþÎÏÃͤÎÀ°·Á
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);
144                 }
145         }
146         foreach($HTTP_POST_VARS as $key => $value) {
147                 $post[$key] = stripslashes($value);
148         }
149         foreach($HTTP_COOKIE_VARS as $key => $value) {
150                 $cookie[$key] = stripslashes($value);
151         }
152 }
153 else {
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();
157 }
158
159 // ³°Éô¤«¤é¤¯¤ëÊÑ¿ô¤ò¥µ¥Ë¥¿¥¤¥º
160 $get    = sanitize_null_character($get);
161 $post   = sanitize_null_character($post);
162 $cookie = sanitize_null_character($cookie);
163
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);
170         }
171         foreach(array_keys($post) as $key) {
172                 $post[$key] = mb_convert_encoding($post[$key],SOURCE_ENCODING,$encode);
173         }
174 }
175
176 if (!empty($get['page'])) {
177         $get['page']  = strip_bracket($get['page']);
178 }
179 if (!empty($post['page'])) {
180         $post['page'] = strip_bracket($post['page']);
181 }
182 if (!empty($post['msg'])) {
183         $post['msg']  = str_replace("\r",'',$post['msg']);
184 }
185
186 $vars = array_merge($post,$get);
187 if (!array_key_exists('page',$vars)) {
188         $get['page'] = $post['page'] = $vars['page'] = '';
189 }
190
191 // ¸åÊý¸ß´¹À­ (?md5=...)
192 if (array_key_exists('md5',$vars) and $vars['md5'] != '') {
193         $vars['cmd'] = 'md5';
194 }
195
196 // cmd¤âplugin¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢QUERY_STRING¤ò¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹
197 if (!array_key_exists('cmd',$vars)  and !array_key_exists('plugin',$vars))
198 {
199         if ($HTTP_SERVER_VARS['QUERY_STRING'] != '')
200         {
201                 $arg = $HTTP_SERVER_VARS['QUERY_STRING'];
202         }
203         else if (array_key_exists(0,$HTTP_SERVER_VARS['argv']))
204         {
205                 $arg = $HTTP_SERVER_VARS['argv'][0];
206         }
207         else
208         {
209                 //¤Ê¤Ë¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï$defaultpage¤òɽ¼¨
210                 $arg = $defaultpage;
211         }               
212         $arg = rawurldecode($arg);
213         $arg = strip_bracket($arg);
214         $arg = sanitize_null_character($arg);
215
216         $get['cmd'] = $post['cmd'] = $vars['cmd'] = 'read';
217         $get['page'] = $post['page'] = $vars['page'] = $arg;
218 }
219
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)';
230 // InterWiki
231 $InterWikiName = "(\[\[)?(\[*[^\s\]]+?\]*):(\[*[^>\]]+?\]*)(?(1)\]\])";
232 // Ãí¼á
233 $NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/ex';
234
235 /////////////////////////////////////////////////
236 // ½é´üÀßÄê(¤½¤Î¾¤Î¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
237 // ¸½ºß»þ¹ï
238 $now = format_date(UTIME);
239 // skinÆâ¤ÇDTDÀë¸À¤òÀÚ¤êÂؤ¨¤ë¤Î¤Ë»ÈÍÑ¡£paint.inc.phpÂкö
240 // FALSE:XHTML 1.1
241 // TRUE :XHTML 1.0 Transitional
242 $html_transitional = FALSE;
243 // ¥Õ¥§¥¤¥¹¥Þ¡¼¥¯¤ò$line_rules¤Ë²Ã¤¨¤ë
244 if ($usefacemark)
245 {
246         $line_rules += $facemark_rules;
247 }
248 ?>