2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: backup.inc.php,v 1.1 2003/01/27 05:38:44 panda Exp $
8 function plugin_backup_action()
10 global $script,$get,$do_backup,$hr;
11 global $_msg_backuplist,$_msg_diff,$_msg_nowdiff,$_msg_source,$_msg_backup;
12 global $_msg_view,$_msg_goto,$_msg_deleleted,$_msg_addline,$_msg_delline;
13 global $_title_backupdiff,$_title_backupnowdiff,$_title_backupsource;
14 global $_title_backup,$_title_pagebackuplist,$_title_backuplist;
16 if (!$do_backup) { return; }
18 $name = $s_page = $s_name = $r_page = '';
19 if (array_key_exists('page',$get)) {
20 $s_page = htmlspecialchars($get['page']);
21 $r_page = rawurlencode($get['page']);
22 // $name = strip_bracket($get['page']);
23 // $s_name = htmlspecialchars($name);
25 $s_age = (array_key_exists('age',$get) and is_numeric($get['age'])) ? $get['age'] : 0;
26 $s_action = $r_action = '';
27 if (array_key_exists('action',$get)) {
28 $s_action = htmlspecialchars($get['action']);
29 $r_action = rawurlencode($get['action']);
34 if (!array_key_exists('page',$get) or $get['page'] == '') {
35 return array('msg'=>$_title_backuplist,'body'=>get_backup_list_all());
39 return array('msg'=>$_title_pagebackuplist,'body'=>get_backup_list($get['page']));
43 $body .= " <li><a href=\"$script?cmd=backup\">$_msg_backuplist</a></li>\n";
45 $href = "$script?cmd=backup&page=$r_page&age=$s_age";
47 if (is_page($get['page'])) {
48 if ($s_action != 'diff') {
49 $body .= " <li>".str_replace('$1',"<a href=\"$href&action=diff\">$_msg_diff</a>",$_msg_view)."</li>\n";
51 if ($s_action != 'nowdiff') {
52 $body .= " <li>".str_replace('$1',"<a href=\"$href&action=nowdiff\">$_msg_nowdiff</a>",$_msg_view)."</li>\n";
56 if ($s_action != 'source') {
57 $body .= " <li>".str_replace('$1',"<a href=\"$href&action=source\">$_msg_source</a>",$_msg_view)."</li>\n";
59 if ($s_action != '') {
60 $body .= " <li>".str_replace('$1',"<a href=\"$href\">$_msg_backup</a>",$_msg_view)."</li>\n";
63 if (is_page($get['page'])) {
64 $body .= " <li>".str_replace('$1',"<a href=\"$script?$r_page\">$s_page</a>",$_msg_goto)."</li>\n";
67 $body .= " <li>".str_replace('$1',$s_page,$_msg_deleleted)."</li>\n";
70 $backups = get_backup($get['page']);
71 if (count($backups) > 0) {
73 foreach($backups as $age => $val) {
74 $date = format_date($val['time'],TRUE);
75 if ($age == $get['age']) {
76 $body .= " <li><em>$age $date</em></li>\n";
79 $body .= " <li><a href=\"$script?cmd={$get['cmd']}&action=$r_action&page=$r_page&age=$age\">$age $date</a></li>\n";
87 if ($s_action == 'diff') {
88 $old = join('',$backups[$get['age']-1]['data']);
89 $cur = join('',$backups[$get['age']]['data']);
90 $body .= backup_diff(do_diff($old,$cur));
92 return array('msg'=>str_replace('$2',$s_age,$_title_backupdiff),'body'=>$body);
94 else if ($s_action == 'nowdiff') {
95 $old = join('',$backups[$get['age']]['data']);
96 $cur = join('',get_source($get['page']));
97 $body .= backup_diff(do_diff($old,$cur));
99 return array('msg'=>str_replace('$2',$s_age,$_title_backupnowdiff),'body'=>$body);
101 else if ($s_action == 'source') {
102 $body .= "<pre>".htmlspecialchars(join('',$backups[$get['age']]['data']))."</pre>\n";
104 return array('msg'=>str_replace('$2',$s_age,$_title_backupsource),'body'=>$body);
108 drop_submit(convert_html(join('',$backups[$get['age']]['data'])));
110 return array('msg'=>str_replace('$2',$s_age,$_title_backup),'body'=>$body);
112 function backup_diff($str)
114 global $_msg_addline,$_msg_delline,$hr;
116 $str = htmlspecialchars($str);
117 $str = preg_replace('/^(\-)(.*)$/m','<span class="diff_removed"> $2</span>',$str);
118 $str = preg_replace('/^(\+)(.*)$/m','<span class="diff_added"> $2</span>',$str);
123 <li>$_msg_addline</li>
124 <li>$_msg_delline</li>
132 // ¥Ð¥Ã¥¯¥¢¥Ã¥×°ìÍ÷¤ò¼èÆÀ
133 function get_backup_list($page)
136 global $_msg_backuplist,$_msg_diff,$_msg_nowdiff,$_msg_source,$_msg_nobackup;
138 $r_page = rawurlencode($page);
139 $s_page = htmlspecialchars($page);
141 $retval .= " <li><a href=\"$script?cmd=backup\">$_msg_backuplist</a>\n";
143 $backups = get_backup($page);
144 $retval .= " <ul>\n";
145 if (count($backups) > 0) {
146 foreach ($backups as $age=>$data) {
147 $date = format_date($data['time'],TRUE);
148 $href = "$script?cmd=backup&page=$r_page&age=$age";
150 <li><a href="$href">$age $date</a>
151 [ <a href="$href&action=diff">$_msg_diff</a>
152 | <a href="$href&action=nowdiff">$_msg_nowdiff</a>
153 | <a href="$href&action=source">$_msg_source</a>
160 $title = $s_page . get_pg_passage($page,FALSE);
161 $link = "<a href=\"$script?cmd=read&page=$r_page\" title=\"$title\">$s_page</a>";
162 $msg = str_replace('$1',$link,$_msg_nobackup);
163 $retval .= " <li>$msg</li>\n";
165 $retval .= " </ul>\n </li>\n</ul>\n";
169 // Á´¥Ú¡¼¥¸¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×°ìÍ÷¤ò¼èÆÀ
170 function get_backup_list_all($withfilename = FALSE)
172 global $script,$list_index,$top,$cantedit;
173 global $_msg_symbol,$_msg_other;
175 $_pages = get_existpages(BACKUP_DIR);
176 if (count($_pages) == 0) {
181 foreach($_pages as $page) {
182 if (!in_array($page,$cantedit)) {
187 return page_list($pages,'backup');