2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: edit.inc.php,v 1.22 2004/11/20 06:38:32 henoheno Exp $
10 function plugin_edit_action()
12 global $vars, $_title_edit, $load_template_func;
14 $page = isset($vars['page']) ? $vars['page'] : '';
16 check_editable($page, true, true);
18 if (isset($vars['preview']) || ($load_template_func && isset($vars['template']))) {
19 return plugin_edit_preview();
20 } else if (isset($vars['write'])) {
21 return plugin_edit_write();
22 } else if (isset($vars['cancel'])) {
23 return plugin_edit_cancel();
26 $postdata = @join('', get_source($page));
27 if ($postdata == '') {
28 $postdata = auto_template($page);
31 return array('msg'=>$_title_edit, 'body'=>edit_form($page, $postdata));
35 function plugin_edit_preview()
38 global $_title_preview, $_msg_preview, $_msg_preview_delete;
40 $page = isset($vars['page']) ? $vars['page'] : '';
43 if (isset($vars['template_page']) && is_page($vars['template_page'])) {
45 $vars['msg'] = join('', get_source($vars['template_page']));
48 $vars['msg'] = preg_replace('/^(\*{1,3}.*)\[#[A-Za-z][\w-]+\](.*)$/m', '$1$2', $vars['msg']);
51 // ¼ê½ñ¤¤Î#freeze¤òºï½ü
52 $vars['msg'] = preg_replace('/^#freeze\s*$/im', '', $vars['msg']);
53 $postdata = $vars['msg'];
55 if (isset($vars['add']) && $vars['add']) {
56 if (isset($vars['add_top']) && $vars['add_top']) {
57 $postdata = $postdata . "\n\n" . @join('', get_source($page));
59 $postdata = @join('', get_source($page)) . "\n\n" . $postdata;
63 $body = "$_msg_preview<br />\n";
65 $body .= "<strong>$_msg_preview_delete</strong>";
69 $postdata = make_str_rules($postdata);
70 $postdata = explode("\n", $postdata);
71 $postdata = drop_submit(convert_html($postdata));
72 $body .= '<div id="preview">' . $postdata . '</div>' . "\n";
74 $body .= edit_form($page, $vars['msg'], $vars['digest'], FALSE);
76 return array('msg'=>$_title_preview, 'body'=>$body);
79 // Inline: Show edit (or unfreeze text) link
80 function plugin_edit_inline()
82 static $usage = '&edit(pagename#anchor[[,noicon],nolabel])[{label}];';
84 global $script, $vars;
85 global $_symbol_paraedit, $fixed_heading_anchor_edit;
88 $args = func_get_args();
89 $s_label = array_pop($args); // {label}
90 $page = array_shift($args);
91 if($page == NULL) $page = '';
92 $_noicon = $_nolabel = $_paraedit = FALSE;
93 foreach($args as $arg){
96 case 'noicon': $_noicon = TRUE; break;
97 case 'nolabel': $_nolabel = TRUE; break;
98 case 'paraedit': $_paraedit = TRUE; break; // Paragraph-edit
99 default: return $usage;
102 if($_paraedit) $_nolabel = TRUE;
104 // Separate a page-name and a fixed anchor
105 list($s_page, $id, $editable) = anchor_explode($page, TRUE);
107 if ($s_page == '') $s_page = isset($vars['page']) ? $vars['page'] : '';
109 $isfreeze = is_freeze($s_page);
110 $ispage = is_page($s_page);
112 // Paragraph edit enabled or not
113 $short = htmlspecialchars('Edit');
114 if ($fixed_heading_anchor_edit && $editable && $ispage && ! $isfreeze) {
116 $id = rawurlencode($id);
117 $title = htmlspecialchars(sprintf('Edit %s', $page));
118 $icon = '<img src="' . IMAGE_DIR . 'paraedit.png' .
119 '" width="9" height="9" alt="' .
120 $short . '" title="' . $title . '" /> ';
121 $class = 'anchor_super';
123 // Normal editing / unfreeze
126 $title = 'Unfreeze %s';
127 $icon = 'unfreeze.png';
132 $title = htmlspecialchars(sprintf($title, $s_page));
133 $icon = '<img src="' . IMAGE_DIR . $icon .
134 '" width="20" height="20" alt="' .
135 $short . '" title="' . $title . '" />';
138 if ($_noicon || $_paraedit) $icon = ''; // No more icon
141 $s_label = ''; // No label with an icon
143 $s_label = $short; // Short label without an icon
146 if ($s_label == '') $s_label = $title; // Rich label with an icon
151 $url = $script . '?cmd=unfreeze&page=' . rawurlencode($s_page);
154 $s_id = '&id=' . $id;
158 $url = $script . '?cmd=edit&page=' . rawurlencode($s_page) . $s_id;
160 $atag = '<a class="' . $class . '" href="' . $url . '" title="' . $title . '">';
161 static $atags = '</a>';
165 return $atag . $icon . $s_label . $atags;
167 // Dangling edit link
168 return $atag . $icon . $atags . '<span class="noexists">' .
169 $s_label . $atag . '?' . $atags . '</span>';
173 // Write, add, or insert new comment
174 function plugin_edit_write()
177 global $_title_collided, $_msg_collided_auto, $_msg_collided, $_title_deleted;
179 $page = isset($vars['page']) ? $vars['page'] : '';
182 // ¼ê½ñ¤¤Î#freeze¤òºï½ü
183 $vars['msg'] = preg_replace('/^#freeze\s*$/im','',$vars['msg']);
184 $postdata = $postdata_input = $vars['msg'];
186 if (isset($vars['add']) && $vars['add']) {
187 if (isset($vars['add_top']) && $vars['add_top']) {
188 $postdata = $postdata . "\n\n" . @join('', get_source($page));
190 $postdata = @join('', get_source($page)) . "\n\n" . $postdata;
194 $oldpagesrc = join('', get_source($page));
195 $oldpagemd5 = md5($oldpagesrc);
197 if (! isset($vars['digest']) || $vars['digest'] != $oldpagemd5) {
198 $vars['digest'] = $oldpagemd5;
200 $retvars['msg'] = $_title_collided;
201 list($postdata_input, $auto) = do_update_diff($oldpagesrc, $postdata_input, $vars['original']);
203 $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided)."\n";
206 global $do_update_diff_table;
207 $retvars['body'] .= $do_update_diff_table;
210 $retvars['body'] .= edit_form($page, $postdata_input, $oldpagemd5, FALSE);
213 $notimestamp = (isset($vars['notimestamp']) && $vars['notimestamp'] != '');
214 page_write($page, $postdata, $notimestamp);
217 header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
221 $retvars['msg'] = $_title_deleted;
222 $retvars['body'] = str_replace('$1', htmlspecialchars($page), $_title_deleted);
229 // Cancel (Back to the page / Escape edit page)
230 function plugin_edit_cancel()
233 header('Location: ' . get_script_uri() . '?' . rawurlencode($vars['page']));