7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2017 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
14 * @link http://www.magic3.org
16 // PukiWiki - Yet another WikiWikiWeb clone.
17 // $Id: edit.inc.php 3474 2010-08-13 10:36:48Z fishbone $
18 // Copyright (C) 2001-2006 PukiWiki Developers Team
19 // License: GPL v2 or (at your option) any later version
21 define('PLUGIN_EDIT_FREEZE_REGEX', '/^(?:#freeze(?!\w)\s*)+/im');
23 function plugin_edit_action()
26 global $script, $_title_cannotedit, $_msg_unfreeze, $_title_invalid_pagename, $_msg_invalid_pagename;
29 // ### パスワード認証フォーム表示 ###
30 // 認証されている場合はスルーして関数以降を実行
31 $retStatus = password_form();
32 if (!empty($retStatus)) return $retStatus;
34 $page = WikiParam::getPage();
36 // 「:」で始まるシステム用ページは作成不可
37 if (strncmp($page, ':', 1) == 0){
38 $msg = $_title_invalid_pagename;
39 $body = sprintf($_msg_invalid_pagename, $page);
40 return array('msg' => $msg, 'body' => $body);
43 if (!check_editable($page, true, true)){ // 編集不可のとき
44 $body = $title = str_replace('$1', make_pagelink($page), $_title_cannotedit);
45 if (is_freeze($page) && WikiConfig::isUserWithFreezeAuth()){ // 解凍・凍結権限ありの場合
46 $body .= '(<a href="' . $script . WikiParam::convQuery('?cmd=unfreeze&page=' . rawurlencode($page)) . '">' . $_msg_unfreeze . '</a>)';
48 return array('msg' => $title, 'body' => $body);
51 if (WikiParam::getVar('preview') != '' || WikiParam::getVar('template') != '') {
52 return plugin_edit_preview();
53 } else if (WikiParam::getVar('write') != '') {
54 return plugin_edit_write();
55 } else if (WikiParam::getVar('cancel') != '') { // キャンセルボタンが押されたとき
56 return plugin_edit_cancel();
59 $postdata = get_source($page, true);
60 if ($postdata == '') $postdata = auto_template($page);
61 return array('msg'=>$_title_edit, 'body'=>edit_form($page, $postdata));
65 function plugin_edit_preview()
67 global $_title_preview, $_msg_preview, $_msg_preview_delete;
69 $page = WikiParam::getPage();
72 $templatePage = WikiParam::getVar('template_page');
73 if ($templatePage != '' && WikiPage::isPage($templatePage)) {
74 /* $vars['msg'] = join('', get_source($vars['template_page']));
76 $vars['msg'] = preg_replace('/^(\*{1,3}.*)\[#[A-Za-z][\w-]+\](.*)$/m', '$1$2', $vars['msg']);*/
78 $msg = get_source($templatePage, true);
81 $msg = preg_replace('/^(\*{1,3}.*)\[#[A-Za-z][\w-]+\](.*)$/m', '$1$2', $msg);
82 // WikiParam::setMsg($msg); // tmp
84 $msg = WikiParam::getMsg();
87 /*$vars['msg'] = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', $vars['msg']);
88 $postdata = $vars['msg'];*/
89 // $msg = WikiParam::getMsg(); // tmp
90 //$msg = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', $msg); // not use freeze expression removed by magic3
91 // WikiParam::setMsg($msg); // tmp
94 if (WikiParam::getVar('add')) {
95 if (WikiParam::getVar('add_top')) {
96 //$postdata = $postdata . "\n\n" . @join('', get_source($page));
97 $postdata = $postdata . "\n\n" . get_source($page, true);
99 //$postdata = @join('', get_source($page)) . "\n\n" . $postdata;
100 $postdata = get_source($page, true) . "\n\n" . $postdata;
104 $body = $_msg_preview . '<br />' . "\n";
106 $body .= '<strong>' . $_msg_preview_delete . '</strong>';
107 $body .= '<br />' . "\n";
110 $postdata = make_str_rules($postdata);
111 $postdata = explode("\n", $postdata);
112 $postdata = drop_submit(convert_html($postdata));
113 $body .= '<div id="preview">' . $postdata . '</div>' . "\n";
115 //$body .= edit_form($page, $vars['msg'], $vars['digest'], FALSE);
116 $body .= edit_form($page, $msg, WikiParam::getVar('digest'), FALSE);
118 return array('msg'=>$_title_preview, 'body'=>$body);
121 // Inline: Show edit (or unfreeze text) link
122 function plugin_edit_inline()
124 static $usage = '&edit(pagename#anchor[[,noicon],nolabel])[{label}];';
125 global $script, $fixed_heading_anchor_edit;
128 $args = func_get_args();
130 // {label}. Strip anchor tags only
131 $s_label = strip_htmltag(array_pop($args), FALSE);
133 $page = array_shift($args);
134 if ($page == NULL) $page = '';
135 $_noicon = $_nolabel = FALSE;
136 foreach($args as $arg){
137 switch(strtolower($arg)){
139 case 'nolabel': $_nolabel = TRUE; break;
140 case 'noicon' : $_noicon = TRUE; break;
141 default : return $usage;
145 // Separate a page-name and a fixed anchor
146 list($s_page, $id, $editable) = anchor_explode($page, TRUE);
149 if ($s_page == '') $s_page = WikiParam::getPage();
152 $isfreeze = is_freeze($s_page);
153 $ispage = WikiPage::isPage($s_page);
155 // Paragraph edit enabled or not
156 $short = htmlspecialchars('Edit');
157 if ($fixed_heading_anchor_edit && $editable && $ispage && ! $isfreeze) {
159 $id = rawurlencode($id);
160 $title = htmlspecialchars(sprintf('Edit %s', $page));
161 $icon = '<img src="' . IMAGE_DIR . 'paraedit.png' .
162 '" width="9" height="9" alt="' .
163 $short . '" title="' . $title . '" /> ';
164 $class = ' class="anchor_super"';
166 // Normal editing / unfreeze
169 $title = 'Unfreeze %s';
170 $icon = 'unfreeze.png';
175 $title = htmlspecialchars(sprintf($title, $s_page));
176 $icon = '<img src="' . IMAGE_DIR . $icon .
177 '" width="20" height="20" alt="' .
178 $short . '" title="' . $title . '" />';
181 if ($_noicon) $icon = ''; // No more icon
184 $s_label = ''; // No label with an icon
186 $s_label = $short; // Short label without an icon
189 if ($s_label == '') $s_label = $title; // Rich label with an icon
193 // modified for Magic3 by naoki on 2008/10/6
195 //$url = $script . '?cmd=unfreeze&page=' . rawurlencode($s_page);
196 $url = $script . WikiParam::convQuery('?cmd=unfreeze&page=' . rawurlencode($s_page));
198 $s_id = ($id == '') ? '' : '&id=' . $id;
199 //$url = $script . '?cmd=edit&page=' . rawurlencode($s_page) . $s_id;
200 $url = $script . WikiParam::convQuery('?cmd=edit&page=' . rawurlencode($s_page) . $s_id);
202 $atag = '<a' . $class . ' href="' . $url . '" title="' . $title . '">';
203 static $atags = '</a>';
207 return $atag . $icon . $s_label . $atags;
209 // Dangling edit link
210 return '<span class="noexists">' . $atag . $icon . $atags .
211 $s_label . $atag . '?' . $atags . '</span>';
215 // Write, add, or insert new comment
216 function plugin_edit_write()
218 global $_title_collided, $_msg_collided_auto, $_msg_collided, $_title_deleted;
219 global $notimeupdate, $_msg_invalidpass, $do_update_diff_table;
220 global $gPageManager;
222 $page = WikiParam::getPage();
223 $add = WikiParam::getVar('add');
224 $digest = WikiParam::getVar('digest'); // POST値を取得
226 /*$vars['msg'] = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', $vars['msg']);
227 $msg = $vars['msg']; // Reference*/
228 //$msg = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', WikiParam::getMsg()); // removed for magic3
229 //WikiParam::setMsg($msg);
230 $msg = WikiParam::getMsg(); // 編集データ
234 // Collision Detection
235 //$oldpagesrc = join('', get_source($page));
236 // 変更データの元データが保存されているデータと同じかどうかのチェック
237 $oldpagesrc = get_source($page, true);
238 $oldpagemd5 = md5($oldpagesrc);
239 if ($digest != $oldpagemd5){ // 元データが異なるとき
240 //$vars['digest'] = $oldpagemd5; // Reset
241 WikiParam::setDigest($oldpagemd5); // Reset
243 $original = WikiParam::getOriginal(); // 編集前の元データ
244 list($postdata_input, $auto) = do_update_diff($oldpagesrc, $msg, $original);
246 $retvars['msg' ] = $_title_collided;
247 $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided) . "\n";
248 $retvars['body'] .= $do_update_diff_table;
249 $retvars['body'] .= edit_form($page, $postdata_input, $oldpagemd5, FALSE);
256 if (WikiParam::getVar('add_top')) {
257 //$postdata = $msg . "\n\n" . @join('', get_source($page));
258 $postdata = $msg . "\n\n" . get_source($page, true);
260 //$postdata = @join('', get_source($page)) . "\n\n" . $msg;
261 $postdata = get_source($page, true) . "\n\n" . $msg;
265 //$postdata = $msg; // Reference
269 // NULL POSTING, OR removing existing page
270 //if ($postdata == '') {
271 // スペースや改行のみのデータのときは、空データとしてページを削除
272 if (trim($postdata) == ''){
273 //page_write($page, $postdata);
274 page_write($page, '');
275 $retvars['msg' ] = $_title_deleted;
276 $retvars['body'] = str_replace('$1', htmlspecialchars($page), $_title_deleted);
278 // if ($trackback) tb_delete($page);
283 // $notimeupdate: Checkbox 'Do not change timestamp'
284 //$notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
285 $notimestamp = WikiParam::getVar('notimestamp') != '';
286 //if ($notimeupdate > 1 && $notimestamp && ! pkwk_login($vars['pass'])) {
287 if ($notimeupdate > 1 && $notimestamp && ! pkwk_login(WikiParam::getVar('pass'))) {
288 // Enable only administrator & password error
289 $retvars['body'] = '<p><strong>' . $_msg_invalidpass . '</strong></p>' . "\n";
290 $retvars['body'] .= edit_form($page, $msg, $digest, FALSE);
294 page_write($page, $postdata, $notimeupdate != 0 && $notimestamp);
295 // pkwk_headers_sent();
296 // modified for Magic3 by naoki on 2008/10/6
297 //header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
298 // header('Location: ' . get_script_uri() . WikiParam::convQuery('?' . rawurlencode($page), false));
300 // 編集権限がある場合はプレビューモードで画面を表示
302 if (WikiConfig::isUserWithEditAuth()) $urlOption = '&' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_PREVIEW;
304 $gPageManager->redirect(get_script_uri() . WikiParam::convQuery('?' . rawurlencode($page), false) . $urlOption);
312 function plugin_edit_cancel()
314 global $gPageManager;
316 $page = WikiParam::getPage();
318 // リファラがある場合はリファラのページへ遷移
319 $refer = WikiParam::getRefer();
320 if (!empty($refer)) $page = $refer;
322 // 編集権限がある場合はプレビューモードで画面を表示
324 if (WikiConfig::isUserWithEditAuth()) $urlOption = '&' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_PREVIEW;
326 $gPageManager->redirect(get_script_uri() . WikiParam::convQuery('?' . rawurlencode($page), false) . $urlOption);