2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: edit.inc.php,v 1.4 2003/03/08 13:19:02 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']))
37 $post['msg'] = join('',get_source($post['template_page']));
40 // ¼ê½ñ¤¤Î#freeze¤òºï½ü
41 $post['msg'] = preg_replace('/^#freeze\s*\n/','',$post['msg']);
43 if (!empty($post['add']))
47 $postdata = $post['msg']."\n\n".@join('',get_source($post['page']));
51 $postdata = @join('',get_source($post['page']))."\n\n".$post['msg'];
56 $postdata = $post['msg'];
59 $body = "$_msg_preview<br />\n";
62 $body .= "<strong>$_msg_preview_delete</strong>";
68 $postdata = make_str_rules($postdata);
69 $postdata = explode("\n",$postdata);
70 $postdata = drop_submit(convert_html($postdata));
78 $body .= edit_form($post['page'],$post['msg'],$post['digest'],FALSE);
80 return array('msg'=>$_title_preview,'body'=>$body);
83 // ½ñ¤¹þ¤ß¤â¤·¤¯¤ÏÄɲä⤷¤¯¤Ï¥³¥á¥ó¥È¤ÎÁÞÆþ
84 function plugin_edit_write()
86 global $script,$post,$vars;
87 global $_title_collided,$_msg_collided_auto,$_msg_collided,$_title_deleted;
91 // ¼ê½ñ¤¤Î#freeze¤òºï½ü
92 $post['msg'] = preg_replace('/^#freeze\s*\n/','',$post['msg']);
94 $postdata_input = $post['msg'];
96 if (!empty($post['add'])) {
97 if (!empty($post['add_top'])) {
98 $postdata = $post['msg'];
100 $postdata .= @join('',get_source($post['page']));
103 $postdata = @join('',get_source($post['page']));
105 $postdata .= $post['msg'];
109 $postdata = $post['msg'];
112 $oldpagesrc = join('',get_source($post['page']));
113 $oldpagemd5 = md5($oldpagesrc);
115 if ($oldpagemd5 != $post['digest']) {
116 $retvars['msg'] = $_title_collided;
118 $post['digest'] = $vars['digest'] = $oldpagemd5;
119 list($postdata_input,$auto) = do_update_diff($oldpagesrc,$postdata_input,$post['original']);
121 $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided)."\n";
124 global $do_update_diff_table;
125 $retvars['body'] .= $do_update_diff_table;
128 $retvars['body'] .= edit_form($post['page'],$postdata_input,$oldpagemd5,FALSE);
131 page_write($post['page'],$postdata);
133 if ($postdata != '') {
134 header("Location: $script?".rawurlencode($post['page']));
138 $retvars['msg'] = $_title_deleted;
139 $retvars['body'] = str_replace('$1',htmlspecialchars($post['page']),$_title_deleted);