OSDN Git Service

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