2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: edit.inc.php,v 1.2 2003/01/31 01:49:35 panda Exp $
9 function plugin_edit_action()
11 global $vars,$_title_edit;
13 if (array_key_exists('preview',$vars) or array_key_exists('template',$vars)) {
14 return plugin_edit_preview();
16 else if (array_key_exists('write',$vars)) {
17 return plugin_edit_write();
22 $postdata = @join('',get_source($vars['page']));
23 if ($postdata == '') {
24 $postdata = auto_template($vars['page']);
27 return array('msg'=>$_title_edit,'body'=>edit_form($vars['page'],$postdata));
30 function plugin_edit_preview()
33 global $_title_preview,$_msg_preview,$_msg_preview_delete;
35 if (array_key_exists('template_page',$post) and is_page($post['template_page'])) {
36 $post['msg'] = join('',get_source($post['template_page']));
39 $post['msg'] = preg_replace("/^#freeze\n/",'',$post['msg']);
40 $postdata_input = $post['msg'];
42 if (!empty($post['add'])) {
43 if ($post['add_top']) {
44 $postdata = $post['msg']."\n\n".@join('',get_source($post['page']));
47 $postdata = @join('',get_source($post['page']))."\n\n".$post['msg'];
51 $postdata = $post['msg'];
54 $body = "$_msg_preview<br />\n";
55 if ($postdata == '') {
56 $body .= "<strong>$_msg_preview_delete</strong>";
60 if ($postdata != '') {
61 $postdata = explode("\n",$postdata);
62 $postdata = drop_submit(convert_html($postdata));
64 if (!empty($post['viewtag'])) {
65 $postdata = preg_replace("/(<[^\/][^>]*>)/e",'"$1".htmlspecialchars("$1")', $postdata);
66 $postdata = preg_replace("/(<\/[^>]+>)/e",'htmlspecialchars("$1")."$1"', $postdata);
75 $body .= edit_form($post['page'],$postdata_input,$post['digest'],FALSE);
77 return array('msg'=>$_title_preview,'body'=>$body);
80 // ½ñ¤¹þ¤ß¤â¤·¤¯¤ÏÄɲä⤷¤¯¤Ï¥³¥á¥ó¥È¤ÎÁÞÆþ
81 function plugin_edit_write()
83 global $script,$post,$vars;
84 global $_title_collided,$_msg_collided_auto,$_msg_collided,$_title_deleted;
88 // ¼ê½ñ¤¤Î#freeze¤òºï½ü
89 $post['msg'] = preg_replace('/^#freeze\n/','',$post['msg']);
91 $postdata_input = $post['msg'];
93 if (!empty($post['add'])) {
94 if (!empty($post['add_top'])) {
95 $postdata = $post['msg'];
97 $postdata .= @join('',get_source($post['page']));
100 $postdata = @join('',get_source($post['page']));
102 $postdata .= $post['msg'];
106 $postdata = $post['msg'];
109 $oldpagesrc = join('',get_source($post['page']));
110 $oldpagemd5 = md5($oldpagesrc);
112 if ($oldpagemd5 != $post['digest']) {
113 $retvars['msg'] = $_title_collided;
115 $post['digest'] = $vars['digest'] = $oldpagemd5;
116 list($postdata_input,$auto) = do_update_diff($oldpagesrc,$postdata_input,$post['original']);
118 $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided)."\n";
121 global $do_update_diff_table;
122 $retvars['body'] .= $do_update_diff_table;
125 $retvars['body'] .= edit_form($post['page'],$postdata_input,$oldpagemd5,FALSE);
128 page_write($post['page'],$postdata);
130 if ($postdata != '') {
131 header("Location: $script?".rawurlencode($post['page']));
135 $retvars['msg'] = $_title_deleted;
136 $retvars['body'] = str_replace('$1',htmlspecialchars($post['page']),$_title_deleted);