OSDN Git Service

[[pukiwiki:BugTrack/30]] <UL>,<LI>問題解決! - ぱんださんありがとう
[pukiwiki/pukiwiki.git] / html.php
1 <?
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: html.php,v 1.33 2002/08/07 08:51:45 masui Exp $
4 /////////////////////////////////////////////////
5
6 // ËÜʸ¤ò¥Ú¡¼¥¸Ì¾¤«¤é½ÐÎÏ
7 function catbodyall($page,$title="",$pg="")
8 {
9         if($title === "") $title = strip_bracket($page);
10         if($pg === "") $pg = make_search($page);
11
12         $body = join("",get_source($page));
13         $body = convert_html($body);
14
15         header_lastmod($vars["page"]);
16         catbody($title,$pg,$body);
17         die();
18 }
19
20 // ËÜʸ¤ò½ÐÎÏ
21 function catbody($title,$page,$body)
22 {
23         global $script,$vars,$arg,$do_backup,$modifier,$modifierlink,$defaultpage,$whatsnew,$hr;
24         global $date_format,$weeklabels,$time_format,$related_link;
25         global $HTTP_SERVER_VARS,$cantedit;
26         global $longtaketime;
27
28         if($vars["page"] && !arg_check("backup") && $vars["page"] != $whatsnew)
29         {
30                 $is_page = 1;
31         }
32
33         $link_add = "$script?cmd=add&amp;page=".rawurlencode($vars["page"]);
34         $link_edit = "$script?cmd=edit&amp;page=".rawurlencode($vars["page"]);
35         $link_diff = "$script?cmd=diff&amp;page=".rawurlencode($vars["page"]);
36         $link_top = "$script?$defaultpage";
37         $link_list = "$script?cmd=list";
38         $link_filelist = "$script?cmd=filelist";
39         $link_search = "$script?cmd=search";
40         $link_whatsnew = "$script?$whatsnew";
41         $link_backup = "$script?cmd=backup&amp;page=".rawurlencode($vars["page"]);
42         $link_help = "$script?cmd=help";
43
44         if(is_page($vars["page"]) && $is_page)
45         {
46                 $fmt = @filemtime(get_filename(encode($vars["page"])));
47         }
48
49         if(is_page($vars["page"]) && $related_link && $is_page && !arg_check("edit") && !arg_check("freeze") && !arg_check("unfreeze"))
50         {
51                 $related = make_related($vars["page"],FALSE);
52         }
53
54         if(is_page($vars["page"]) && !in_array($vars["page"],$cantedit) && !arg_check("backup") && !arg_check("edit") && !$vars["preview"])
55         {
56                 $is_read = TRUE;
57         }
58
59         //if(!$longtaketime)
60                 $longtaketime = getmicrotime() - MUTIME;
61         $taketime = sprintf("%01.03f",$longtaketime);
62
63         require(SKIN_FILE);
64 }
65
66 // ¥Æ¥­¥¹¥ÈËÜÂΤòHTML¤ËÊÑ´¹¤¹¤ë
67 function convert_html($string)
68 {
69         global $hr,$script,$page,$vars,$top;
70         global $note_id,$foot_explain,$digest,$note_hr;
71         global $user_rules,$str_rules,$line_rules,$strip_link_wall;
72         global $InterWikiName, $BracketName;
73
74         global $longtaketime;
75
76         $string = rtrim($string);
77         $string = preg_replace("/((\x0D\x0A)|(\x0D)|(\x0A))/","\n",$string);
78
79         $start_mtime = getmicrotime();
80
81         $digest = md5(@join("",get_source($vars["page"])));
82
83         $result = array();
84         $saved = array();
85         $arycontents = array();
86
87         $string = preg_replace("/^#freeze\n/","",$string);
88
89         $lines = split("\n", $string);
90         $note_id = 1;
91         $foot_explain = array();
92         // ³Æ¹Ô¤Î¹ÔƬ½ñ¼°¤ò³ÊǼ
93         $headform = array();
94         // ¸½ºß¤Î¹Ô¿ô¤òÆþ¤ì¤Æ¤ª¤³¤¦
95         $_cnt = 0;
96         // ¥Ö¥í¥Ã¥¯¤ÎȽÄê¥Õ¥é¥°
97         $_p = FALSE;
98         $_bq = FALSE;
99
100         $table = 0;
101
102         if(preg_match("/#contents/",$string))
103                 $top_link = "<a href=\"#contents\">$top</a>";
104
105         foreach ($lines as $line)
106         {
107                 if(!preg_match("/^\/\/(.*)/",$line,$comment_out) && $table != 0)
108                 {
109                         if(!preg_match("/^\|(.+)\|$/",$line,$out))
110                                 array_push($result, "</table></div>");
111                         if(!$out[1] || $table != count(explode("|",$out[1])))
112                                 $table = 0;
113                 }
114
115                 $comment_out = $comment_out[1];
116
117                 // ¹ÔƬ½ñ¼°¤«¤É¤¦¤«¤ÎȽÄê
118                 $line_head = substr($line,0,1);
119                 if(     $line_head == ' ' || 
120                         $line_head == ':' || 
121                         $line_head == '>' || 
122                         $line_head == '-' || 
123                         $line_head == '+' || 
124                         $line_head == '|' || 
125                         $line_head == '*' || 
126                         $line_head == '#' || 
127                         $comment_out != ''
128                 ) {
129                         if($headform[$_cnt-1] == '' && $_p){
130                                 array_push($result, "</p>");
131                                 $_p = FALSE;
132                         }
133                         if($line_head != '>' && $_bq){
134                                 array_push($result, "</p>");
135                                 $_bq = FALSE;
136                         }
137
138                         if(preg_match("/^\#([^\(]+)(.*)$/",$line,$out)){
139                                 if(exist_plugin_convert($out[1])) {
140                                         $result = array_merge($result,$saved); $saved = array();
141                                         
142                                         if($out[2]) {
143                                                 $_plugin = preg_replace("/^\#([^\(]+)\((.*)\)$/ex","do_plugin_convert('$1','$2')",$line);
144                                         } else {
145                                                 $_plugin = preg_replace("/^\#([^\(]+)$/ex","do_plugin_convert('$1','$2')",$line);
146                                         }
147                                         // ÀèƬ¤Ë¶õÇò¤òÆþ¤ì¤ë¤³¤È¤Ë¤è¤ê¤È¤ê¤¢¤¨¤ºpre¤Î°·¤¤¤ÈƱÍͤËinline2¤ÎƯ¤­¤òÍÞ¤¨¤ë¡¢¤¦¡Á¤ó¡¢ÌµÃã¡£
148                                         array_push($result,"\t$_plugin");
149                                 } else {
150                                         array_push($result, htmlspecialchars($line));
151                                 }
152                         }
153                         else if(preg_match("/^(\*{1,3})(.*)/",$line,$out))
154                         {
155                                 $result = array_merge($result,$saved); $saved = array();
156                                 $headform[$_cnt] = $out[1];
157                                 $str = inline($out[2]);
158                                 
159                                 $level = strlen($out[1]) + 1;
160
161                                 array_push($result, "<h$level><a name=\"content:$content_id\"></a>$str $top_link</h$level>");
162                                 $arycontents[] = str_repeat("-",$level-1)."<a href=\"#content:$content_id\">".strip_htmltag(make_user_rules($str))."</a>\n";
163                                 $content_id++;
164                         }
165                         else if(preg_match("/^(-{1,4})(.*)/",$line,$out))
166                         {
167                                 $headform[$_cnt] = $out[1];
168                                 if(strlen($out[1]) == 4)
169                                 {
170                                         $result = array_merge($result,$saved); $saved = array();
171                                         array_push($result, $hr);
172                                 }
173                                 else
174                                 {
175                                         list_push($result,$saved,'ul', strlen($out[1]));
176                                         array_push($result, inline($out[2]));
177                                 }
178                         }
179                         else if(preg_match("/^(\+{1,3})(.*)/",$line,$out))
180                         {
181                                 $headform[$_cnt] = $out[1];
182                                 list_push($result,$saved,'ol', strlen($out[1]));
183                                 array_push($result, inline($out[2]));
184                         }
185                         else if (preg_match("/^:([^:]+):(.*)/",$line,$out))
186                         {
187                                 $headform[$_cnt] = ':'.$out[1].':';
188                                 back_push($result,$saved,'dl', 1);
189                                 array_push($result, '<dt>' . inline($out[1]) . '</dt>', '<dd>' . inline($out[2]) . '</dd>');
190                         }
191                         else if(preg_match("/^(>{1,3})(.*)/",$line,$out))
192                         {
193                                 $headform[$_cnt] = $out[1];
194                                 back_push($result,$saved,'blockquote', strlen($out[1]));
195                                 // ¤³¤³¤Î¤¢¤¿¤ê¤Ç¼«Á°¤Çback_push¤«¤±¤Æ¤ë´¶¤¸¡£ÌµÃã¶ìÃã¡Ä
196                                 if($headform[$_cnt-1] != $headform[$_cnt] ) {
197                                         if(!$_bq) {
198                                                 array_push($result, "<p class=\"quotation\">");
199                                                 $_bq = TRUE;
200                                         }
201                                         else if(substr($headform[$_cnt-1],0,1) == '>'){
202                                                 $_level_diff = abs( strlen($out[1]) - strlen($headform[$_cnt-1]) );
203                                                 if( $_level_diff == 1 ){
204                                                         $i = array_pop($result);
205                                                         array_push($result, "</p>");
206                                                         array_push($result,$i);
207                                                         array_push($result, "<p class=\"quotation\">");
208                                                         $_bq = TRUE;
209                                                 } else {
210                                                         $i = array();
211                                                         $i[] = array_pop($result);
212                                                         $i[] = array_pop($result);
213                                                         array_push($result, "</p>");
214                                                         $result = array_merge($result,$i);
215                                                         array_push($result, "<p class=\"quotation\">");
216                                                         $_bq = TRUE;
217                                                 }
218                                         }
219                                 }
220                                 array_push($result, ltrim(inline($out[2])));
221                         }
222                         else if(preg_match("/^(\s+.*)/",$line,$out))
223                         {
224                                 $headform[$_cnt] = ' ';
225                                 back_push($result,$saved,'pre', 1);
226                                 array_push($result, htmlspecialchars($out[1],ENT_NOQUOTES));
227                         }
228                         else if(preg_match("/^\|(.+)\|$/",$line,$out))
229                         {
230                                 $headform[$_cnt] = '|';
231                                 $arytable = explode("|",$out[1]);
232
233                                 if(!$table)
234                                 {
235                                         $result = array_merge($result,$saved); $saved = array();
236                                         array_push($result,"<div class=\"ie5\"><table class=\"style_table\" cellspacing=\"1\" border=\"0\">");
237                                         $table = count($arytable);
238                                 }
239
240                                 array_push($result,"<tr>");
241                                 foreach($arytable as $td)
242                                 {
243                                         array_push($result,"<td class=\"style_td\">");
244                                         array_push($result,ltrim(inline($td)));
245                                         array_push($result,"</td>");
246                                 }
247                                 array_push($result,"</tr>");
248
249                         }
250                         else if(strlen($comment_out) != 0)
251                         {
252                                 $headform[$_cnt] = '//';
253 #                               array_push($result," <!-- ".htmlspecialchars($comment_out)." -->");
254                         }
255
256                 } else {
257
258                         $headform[$_cnt] = '';
259                         if($headform[$_cnt-1] != $headform[$_cnt]){
260                                 if(array_values($saved)){
261                                         if( $_bq ){
262                                                 array_unshift($saved, "</p>");
263                                                 $_bq = FALSE;
264                                         }
265                                         $i = array_pop($saved);
266                                         array_push($saved,$i);
267                                         $result = array_merge($result,$saved); $saved = array();
268                                 }
269                                 if( substr($line,0,1) == '' && !$_p){
270                                         array_push($result, "<p>");
271                                         $_p = TRUE;
272                                 }
273                                 else if( substr($line,0,1) != '' && $_p){
274                                         array_push($result, "</p>");
275                                         $_p = FALSE;
276                                 }
277                         }
278                         
279                         if( substr($line,0,1) == '' && $_p){
280                                 $_tmp = array_pop($result);
281                                 if($_tmp == "<p>") {
282                                         $_tmp = '<p class="empty">';
283                                 }
284                                 array_push($result, $_tmp, "</p>");
285                                 $_p = FALSE;
286                         }
287                         else if( substr($line,0,1) != '' && !$_p) {
288                                 array_push($result, "<p>");
289                                 $_p = TRUE;
290                         }
291                         if( substr($line,0,1) != '' ){
292                                 array_push($result, inline($line));
293                         }
294
295                 }
296
297                 $_cnt++;
298         }
299
300         if($_p) array_push($result, "</p>");
301         if($_bq) {
302                 array_push($result, "</p>");
303                 array_push($result, "</blockquote>");
304                 $saved = array();
305         }
306         if($table) array_push($result, "</table></div>");
307         
308         $result_last = $result = array_merge($result,$saved); $saved = array();
309
310         if($content_id != 0)
311         {
312                 $result = array();
313                 $saved = array();
314
315                 foreach($arycontents as $line)
316                 {
317                         if(preg_match("/^(-{1,3})(.*)/",$line,$out))
318                         {
319                                 list_push($result,$saved,'ul', strlen($out[1]));
320                                 array_push($result, $out[2]);
321                         }
322                 }
323                 $result = array_merge($result,$saved); $saved = array();
324                 
325                 $contents = "<a name=\"contents\"></a>\n";
326                 $contents .= join("\n",$result);
327                 if($strip_link_wall)
328                 {
329                         $contents = preg_replace("/\[\[([^\]:]+):(.+)\]\]/","$1",$contents);
330                         $contents = preg_replace("/\[\[([^\]]+)\]\]/","$1",$contents);
331                 }
332         }
333
334         $result_last = inline2($result_last);
335         
336         $result_last = preg_replace("/^#contents/",$contents,$result_last);
337
338         $str = join("\n", $result_last);
339
340         if($foot_explain)
341         {
342                 $str .= "\n";
343                 $str .= "$note_hr\n";
344                 $str .= join("\n",inline2($foot_explain));
345         }
346
347         $longtaketime = getmicrotime() - $start_mtime;
348
349 #       $str = preg_replace("/&((amp)|(quot)|(nbsp)|(lt)|(gt));/","&$1;",$str);
350
351         return $str;
352 }
353
354 // $tag¤Î¥¿¥°¤ò$level¥ì¥Ù¥ë¤Þ¤ÇµÍ¤á¤ë¡£
355 function back_push(&$result,&$saved,$tag, $level)
356 {
357         while (count($saved) > $level) {
358                 array_push($result, array_shift($saved));
359         }
360         if ($saved[0] != "</$tag>") {
361                 $result = array_merge($result,$saved); $saved = array();
362         }
363         while (count($saved) < $level) {
364                 array_unshift($saved, "</$tag>");
365                 array_push($result, "<$tag>");
366         }
367 }
368
369 function list_push(&$result,&$saved,$tag,$level) {
370         $cont = true;
371         $open = "<$tag%s><li>";
372         $close = "</li></$tag>";
373         
374         while (count($saved) > $level or
375                 (count($saved) > 0 and $saved[0] != $close)) {
376                 array_push($result, array_shift($saved));
377         }
378         
379         $margin = $level - count($saved);
380         
381         while (count($saved) < ($level - 1)) {
382                 array_unshift($saved, ''); //count($saved)¤òÁý¤ä¤¹¤¿¤á¤Îdummy
383         }
384         
385         if (count($saved) < $level) {
386                 $cont = false;
387                 array_unshift($saved, $close);
388                 array_push($result, sprintf($open, " style=\"margin-left:".($margin * 3)."em\""));
389 //              array_push($result, sprintf($open, " class=\"listmargin$margin\""));
390         }
391         
392         if ($cont)
393                 array_push($result, '</li><li>');
394 }
395
396 // ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (Ãí¼á)
397 function inline($line)
398 {
399         $line = htmlspecialchars($line);
400
401         $line = preg_replace("/\(\(((?:(?!\)\)).)*)\)\)/ex","make_note(\"$1\")",$line);
402
403         return $line;
404 }
405
406 // ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (¥ê¥ó¥¯¡¢´ØÏ¢°ìÍ÷¡¢¸«½Ð¤·°ìÍ÷)
407 function inline2($str)
408 {
409         global $WikiName,$BracketName,$InterWikiName,$vars,$related,$related_link,$script;
410         $cnts_plain = array();
411         $arykeep = array();
412
413         for($cnt=0;$cnt<count($str);$cnt++)
414         {
415                 if(preg_match("/^(\s)/",$str[$cnt]))
416                 {
417                         $arykeep[$cnt] = $str[$cnt];
418                         $str[$cnt] = "";
419                         $cnts_plain[] = $cnt;
420                 }
421         }
422
423         $str = preg_replace("/
424                 (
425                         (\[\[([^\]]+)\:(https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)\]\])
426                         |
427                         (\[(https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)\s([^\]]+)\])
428                         |
429                         (https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)
430                         |
431                         ([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)
432                         |
433                         (\[\[([^\]]+)\:([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)\]\])
434                         |
435                         ($InterWikiName)
436                         |
437                         ($BracketName)
438                         |
439                         ($WikiName)
440                 )/ex","make_link('$1')",$str);
441
442         $str = preg_replace("/#related/e",'make_related($vars["page"],TRUE)',$str);
443
444         $str = make_user_rules($str);
445
446         $tmp = $str;
447         $str = preg_replace("/^#norelated$/","",$str);
448         if($tmp != $str)
449                 $related_link = 0;
450
451         foreach($cnts_plain as $cnt)
452                 $str[$cnt] = $arykeep[$cnt];
453
454         return $str;
455 }
456
457 // °ìÍ÷¤Î¼èÆÀ
458 function get_list($withfilename)
459 {
460         global $script,$list_index,$top,$non_list,$whatsnew;
461         global $_msg_symbol,$_msg_other;
462         
463         $retval = array();
464         $files = get_existpages();
465         foreach($files as $page) {
466                 if(preg_match("/$non_list/",$page) && !$withfilename) continue;
467                 if($page == $whatsnew) continue;
468                 $page_url = rawurlencode($page);
469                 $page2 = strip_bracket($page);
470                 $pg_passage = get_pg_passage($page);
471                 $file = encode($page).".txt";
472                 $retval[$page2] .= "<li><a href=\"$script?$page_url\">".htmlspecialchars($page2,ENT_QUOTES)."</a>$pg_passage";
473                 if($withfilename)
474                 {
475                         $retval[$page2] .= "<ul><li>$file</li></ul>\n";
476                 }
477                 $retval[$page2] .= "</li>\n";
478         }
479         
480         $retval = list_sort($retval);
481         
482         if($list_index)
483         {
484                 $head_str = "";
485                 $etc_sw = 0;
486                 $symbol_sw = 0;
487                 $top_link = "";
488                 $link_counter = 0;
489                 foreach($retval as $page => $link)
490                 {
491                         $head = substr($page,0,1);
492                         if($head_str != $head && !$etc_sw)
493                         {
494                                 $retval2[$page] = "";
495                                 
496                                 if(preg_match("/([A-Z])|([a-z])/",$head,$match))
497                                 {
498                                         if($match[1])
499                                                 $head_nm = "High:$head";
500                                         else
501                                                 $head_nm = "Low:$head";
502                                         
503                                         if($head_str) $retval2[$page] = "</ul></li>\n";
504                                         $retval2[$page] .= "<li><a href=\"#top:$head_nm\" name=\"$head_nm\"><strong>$head</strong></a>\n<ul>\n";
505                                         $head_str = $head;
506                                         if($link_counter) $top_link .= "|";
507                                         $link_counter = $link_counter + 1;
508                                         $top_link .= "<a href=\"#$head_nm\" name=\"top:$head_nm\"><strong>&nbsp;".$head."&nbsp;</strong></a>";
509                                         if($link_counter==16) {
510                                                 $top_link .= "<br />";
511                                                 $link_counter = 0;
512                                         }
513                                 }
514                                 else if(preg_match("/[ -~]/",$head))
515                                 {
516                                         if(!$symbol_sw)
517                                         {
518                                                 if($head_str) $retval2[$page] = "</ul></li>\n";
519                                                 $retval2[$page] .= "<li><a href=\"#top:symbol\" name=\"symbol\"><strong>$_msg_symbol</strong></a>\n<ul>\n";
520                                                 $head_str = $head;
521                                                 if($link_counter) $top_link .= "|";
522                                                 $link_counter = $link_counter + 1;
523                                                 $top_link .= "<a href=\"#symbol\" name=\"top:symbol\"><strong>$_msg_symbol</strong></a>";
524                                                 $symbol_sw = 1;
525                                         }
526                                 }
527                                 else
528                                 {
529                                         if($head_str) $retval2[$page] = "</ul></li>\n";
530                                         $retval2[$page] .= "<li><a href=\"#top:etc\" name=\"etc\"><strong>$_msg_other</strong></a>\n<ul>\n";
531                                         $etc_sw = 1;
532                                         if($link_counter) $top_link .= "|";
533                                         $link_counter = $link_counter + 1;
534                                         $top_link .= "<a href=\"#etc\" name=\"top:etc\"><strong>$_msg_other</strong></a>";
535                                 }
536                         }
537                         $retval2[$page] .= $link;
538                 }
539                 $retval2[] = "</ul></li>\n";
540                 
541                 $top_link = "<div style=\"text-align:center\"><a name=\"top\"></a>$top_link</div><br />\n<ul>";
542                 
543                 array_unshift($retval2,$top_link);
544         }
545         else
546         {
547                 $retval2 = $retval;
548                 
549                 $top_link = "<ul>";
550                 
551                 array_unshift($retval2,$top_link);
552         }
553         
554         return join("",$retval2)."</ul>";
555 }
556
557 // ÊÔ½¸¥Õ¥©¡¼¥à¤Îɽ¼¨
558 function edit_form($postdata,$page,$add=0)
559 {
560         global $script,$rows,$cols,$hr,$vars,$function_freeze;
561         global $_btn_addtop,$_btn_preview,$_btn_update,$_btn_freeze,$_msg_help,$_btn_notchangetimestamp;
562         global $whatsnew,$_btn_template,$_btn_load,$non_list,$load_template_func;
563
564         $digest = md5(@join("",get_source($page)));
565
566         if($add)
567         {
568                 $addtag = '<input type="hidden" name="add" value="true" />';
569                 $add_top = '<input type="checkbox" name="add_top" value="true" /><span class="small">'.$_btn_addtop.'</span>';
570         }
571
572         if($vars["help"] == "true")
573                 $help = $hr.catrule();
574         else
575                 $help = "<br />\n<ul><li><a href=\"$script?cmd=edit&amp;help=true&amp;page=".rawurlencode($page)."\">$_msg_help</a></ul></li>\n";
576
577         if($function_freeze)
578                 $str_freeze = '<input type="submit" name="freeze" value="'.$_btn_freeze.'" accesskey="f" />';
579
580         if($load_template_func)
581         {
582                 $vals = array();
583
584                 $files = get_existpages();
585                 foreach($files as $pg_org) {
586                         if($pg_org == $whatsnew) continue;
587                         if(preg_match("/$non_list/",$pg_org)) continue;
588                         $name = strip_bracket($pg_org);
589                         $vals[$name] = "    <option value=\"$pg_org\">$name</option>";
590                 }
591                 @ksort($vals);
592                 
593                 $template = "   <select name=\"template_page\">\n"
594                            ."    <option value=\"\">-- $_btn_template --</option>\n"
595                            .join("\n",$vals)
596                            ."   </select>\n"
597                            ."   <input type=\"submit\" name=\"template\" value=\"$_btn_load\" accesskey=\"r\" /><br />\n";
598
599                 if($vars["refer"]) $refer = $vars["refer"]."\n\n";
600         }
601
602 return '
603 <form action="'.$script.'" method="post">
604 '.$addtag.'
605 <table cellspacing="3" cellpadding="0" border="0">
606  <tr>
607   <td align="right">
608 '.$template.'
609   </td>
610  </tr>
611  <tr>
612   <td align="right">
613    <input type="hidden" name="page" value="'.htmlspecialchars($page).'" />
614    <input type="hidden" name="digest" value="'.htmlspecialchars($digest).'" />
615    <textarea name="msg" rows="'.$rows.'" cols="'.$cols.'" wrap="virtual">
616 '.htmlspecialchars($refer.$postdata).'</textarea>
617   </td>
618  </tr>
619  <tr>
620   <td>
621    <input type="submit" name="preview" value="'.$_btn_preview.'" accesskey="p" />
622    <input type="submit" name="write" value="'.$_btn_update.'" accesskey="s" />
623    '.$add_top.'
624    <input type="checkbox" name="notimestamp" value="true" /><span style="small">'.$_btn_notchangetimestamp.'</span>
625   </td>
626  </tr>
627 </table>
628 </form>
629
630 <form action="'.$script.'?cmd=freeze" method="post">
631 <div>
632 <input type="hidden" name="page" value="'.htmlspecialchars($vars["page"]).'" />
633 '.$str_freeze.'
634 </div>
635 </form>
636
637 ' . $help;
638 }
639
640 // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
641 function make_related($page,$_isrule)
642 {
643         global $related_str,$rule_related_str,$related,$_make_related,$vars;
644
645         $page_name = strip_bracket($vars["page"]);
646
647         if(!is_array($_make_related))
648         {
649                 $aryrelated = do_search($page,"OR",1);
650
651                 if(is_array($aryrelated))
652                 {
653                         foreach($aryrelated as $key => $val)
654                         {
655                                 $new_arylerated[$key.md5($val)] = $val;
656                         }
657                 }
658
659                 if(is_array($related))
660                 {
661                         foreach($related as $key => $val)
662                         {
663                                 $new_arylerated[$key.md5($val)] = $val;
664                         }
665                 }
666
667                 @krsort($new_arylerated);
668                 $_make_related = @array_unique($new_arylerated);
669         }
670
671         if($_isrule)
672         {
673                 if(is_array($_make_related))
674                 {
675                         foreach($_make_related as $str)
676                         {
677                                 preg_match("/<a\shref=\"([^\"]+)\">([^<]+)<\/a>(.*)/",$str,$out);
678                                 
679                                 if($out[3]) $title = " title=\"$out[2] $out[3]\"";
680                                 
681                                 $aryret[$out[2]] = "<a href=\"$out[1]\"$title>$out[2]</a>";
682                         }
683                         @ksort($aryret);
684                 }
685         }
686         else
687         {
688                 $aryret = $_make_related;
689         }
690
691         if($_isrule) $str = $rule_related_str;
692         else         $str = $related_str;
693
694         return @join($str,$aryret);
695 }
696
697 // Ãí¼á½èÍý
698 function make_note($str)
699 {
700         global $note_id,$foot_explain;
701
702         $str = preg_replace("/^\(\(/","",$str);
703         $str = preg_replace("/\)\)$/","",$str);
704
705         $str= str_replace("\\'","'",$str);
706
707         $str = make_user_rules($str);
708
709         $foot_explain[] = "<a name=\"notefoot:$note_id\" href=\"#notetext:$note_id\" class=\"note_super\">*$note_id</a> <span class=\"small\">$str</span><br />\n";
710         $note =  "<a name=\"notetext:$note_id\" href=\"#notefoot:$note_id\" class=\"note_super\">*$note_id</a>";
711         $note_id++;
712
713         return $note;
714 }
715
716 // ¥ê¥ó¥¯¤òÉղ乤ë
717 function make_link($name)
718 {
719         global $BracketName,$WikiName,$InterWikiName,$InterWikiNameNoBracket,$script,$link_target,$interwiki_target;
720         global $related,$show_passage,$vars,$defaultpage;
721
722         $aryconv_htmlspecial = array("&amp;","&lt;","&gt;");
723         $aryconv_html = array("&","<",">");
724
725         $page = $name;
726
727         if(preg_match("/^\[\[([^\]]+)\:((https?|ftp|news)([^\]]+))\]\]$/",$name,$match))
728         {
729                 if(preg_match("/(\.gif|\.png|\.jpeg|\.jpg)$/",$match[1]) )
730                         return "<a href=\"$match[2]\" target=\"$link_target\"><img src=\"$match[1]\" border=\"0\" alt=\"$match[1]\"></a>";
731                 else
732                         return "<a href=\"$match[2]\" target=\"$link_target\">$match[1]</a>";
733         }
734         else if(preg_match("/^\[((https?|ftp|news)([^\]\s]+))\s([^\]]+)\]$/",$name,$match))
735         {
736                 return "<a href=\"$match[1]\" target=\"$link_target\">$match[4]</a>";
737         }
738         else if(preg_match("/^(https?|ftp|news).*?(\.gif|\.png|\.jpeg|\.jpg)?$/",$name,$match))
739         {
740                 if($match[2])
741                         return "<a href=\"$name\" target=\"$link_target\"><img src=\"$name\" border=\"0\"></a>";
742                 else
743                         return "<a href=\"$name\" target=\"$link_target\">$page</a>";
744         }
745         else if(preg_match("/^\[\[([^\]]+)\:([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)\]\]/",$name,$match))
746         {
747                 return "<a href=\"mailto:$match[2]\">$match[1]</a>";
748         }
749         else if(preg_match("/^([[:alnum:]\-_]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)/",$name))
750         {
751                 return "<a href=\"mailto:$name\">$page</a>";
752         }
753         else if(preg_match("/^(.+?)&gt;($InterWikiNameNoBracket)$/",strip_bracket($name),$match))
754         {
755                 $page = $match[1];
756                 $name = '[['.$match[2].']]';
757                 $percent_name = str_replace($aryconv_htmlspecial,$aryconv_html,$name);
758                 $percent_name = rawurlencode($percent_name);
759
760                 return "<a href=\"$script?$percent_name\" target=\"$interwiki_target\">$page</a>";
761         }
762         else if(preg_match("/^($InterWikiName)$/",$name))
763         {
764                 $page = strip_bracket($page);
765                 $percent_name = str_replace($aryconv_htmlspecial,$aryconv_html,$name);
766                 $percent_name = rawurlencode($percent_name);
767
768                 return "<a href=\"$script?$percent_name\" target=\"$interwiki_target\">$page</a>";
769         }
770         else if(preg_match("/^($BracketName)|($WikiName)$/",$name))
771         {
772                 if(preg_match("/^(.+?)&gt;(.+)$/",strip_bracket($name),$match))
773                 {
774
775                         $page = $match[1];
776                         $name = $match[2];
777                         if(!preg_match("/^($BracketName)|($WikiName)$/",$page))
778                                 $page = "[[$page]]";
779                         if(!preg_match("/^($BracketName)|($WikiName)$/",$name))
780                                 $name = "[[$name]]";
781                 }
782                 if(preg_match("/^\[\[\.\/([^\]]*)\]\]/",$name,$match))
783                 {
784                         if(!$match[1])
785                                 $name = $vars["page"];
786                         else
787                                 $name = "[[".strip_bracket($vars["page"])."/$match[1]]]";
788                 }
789                 else if(preg_match("/^\[\[\..\/([^\]]+)\]\]/",$name,$match))
790                 {
791                         for($i=0;$i<substr_count($name,"../");$i++)
792                                 $name = preg_replace("/(.+)\/([^\/]+)$/","$1",strip_bracket($vars["page"]));
793
794                         if(!preg_match("/^($BracketName)|($WikiName)$/",$name))
795                                 $name = "[[$name]]";
796                         
797                         if($vars["page"]==$name)
798                                 $name = "[[$match[1]]]";
799                         else
800                                 $name = "[[".strip_bracket($name)."/$match[1]]]";
801                 }
802                 else if($name == "[[../]]")
803                 {
804                         $name = preg_replace("/(.+)\/([^\/]+)$/","$1",strip_bracket($vars["page"]));
805                         
806                         if(!preg_match("/^($BracketName)|($WikiName)$/",$name))
807                                 $name = "[[$name]]";
808                         if($vars["page"]==$name)
809                                 $name = $defaultpage;
810                 }
811                 
812                 $page = strip_bracket($page);
813                 $pagename = htmlspecialchars(strip_bracket($name));
814                 $percent_name = str_replace($aryconv_htmlspecial,$aryconv_html,$name);
815                 $percent_name = rawurlencode($percent_name);
816
817                 $refer = rawurlencode($vars["page"]);
818                 if(is_page($name))
819                 {
820                         $str = get_pg_passage($name,FALSE);
821                         $tm = @filemtime(get_filename(encode($name)));
822                         if($vars["page"] != $name)
823                                 $related[$tm] = "<a href=\"$script?$percent_name\">$pagename</a>$str";
824                         if($show_passage)
825                         {
826                                 $str_title = "title=\"$pagename $str\"";
827                         }
828                         return "<a href=\"$script?$percent_name\" $str_title>$page</a>";
829                 }
830                 else
831                         return "<span class=\"noexists\">$page<a href=\"$script?cmd=edit&amp;page=$percent_name&amp;refer=$refer\">?</a></span>";
832         }
833         else
834         {
835                 return $page;
836         }
837 }
838
839 // ¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ë(¥½¡¼¥¹¤òÃÖ´¹¤¹¤ë)
840 function user_rules_str($str)
841 {
842         global $str_rules;
843
844         $arystr = split("\n",$str);
845
846         // ÆüÉÕ¡¦»þ¹ïÃÖ´¹½èÍý
847         foreach($arystr as $str)
848         {
849                 if(substr($str,0,1) != " ")
850                 {
851                         foreach($str_rules as $rule => $replace)
852                         {
853                                 $str = preg_replace("/$rule/",$replace,$str);
854                         }
855                 }
856                 $retvars[] = $str;
857         }
858
859         return join("\n",$retvars);
860 }
861
862 // ¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ë(¥½¡¼¥¹¤ÏÃÖ´¹¤»¤º¥³¥ó¥Ð¡¼¥È)
863 function make_user_rules($str)
864 {
865         global $user_rules;
866
867         foreach($user_rules as $rule => $replace)
868         {
869                 $str = preg_replace("/$rule/",$replace,$str);
870         }
871
872         return $str;
873 }
874
875 // HTML¥¿¥°¤ò¼è¤ê½ü¤¯
876 function strip_htmltag($str)
877 {
878         //$str = preg_replace("/<a[^>]+>\?<\/a>/","",$str);
879         return preg_replace("/<[^>]+>/","",$str);
880 }
881
882 // ¥Ú¡¼¥¸Ì¾¤«¤é¥Ú¡¼¥¸Ì¾¤ò¸¡º÷¤¹¤ë¥ê¥ó¥¯¤òºîÀ®
883 function make_search($page)
884 {
885         global $script,$WikiName;
886
887         $name = strip_bracket($page);
888         $url = rawurlencode($page);
889
890         //WikiWikiWeb like...
891         //if(preg_match("/^$WikiName$/",$page))
892         //      $name = preg_replace("/([A-Z][a-z]+)/","$1 ",$name);
893
894         return "<a href=\"$script?cmd=search&amp;word=$url\">".htmlspecialchars($name)."</a> ";
895 }
896
897 ?>