2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: backup.inc.php,v 1.7 2003/06/05 10:37:35 arino Exp $
8 function plugin_backup_action()
10 global $script,$vars,$do_backup,$hr;
11 global $_msg_backuplist,$_msg_diff,$_msg_nowdiff,$_msg_source,$_msg_backup;
12 global $_msg_view,$_msg_goto,$_msg_deleted,$_msg_addline,$_msg_delline;
13 global $_title_backupdiff,$_title_backupnowdiff,$_title_backupsource;
14 global $_title_backup,$_title_pagebackuplist,$_title_backuplist;
21 $page = $s_page = $r_page = '';
22 if (array_key_exists('page',$vars))
24 $page = $vars['page'];
25 $s_page = htmlspecialchars($page);
26 $r_page = rawurlencode($page);
28 $s_age = (array_key_exists('age',$vars) and is_numeric($vars['age'])) ? $vars['age'] : 0;
29 $action = $s_action = $r_action = '';
30 if (array_key_exists('action',$vars))
32 $action = $vars['action'];
33 $s_action = htmlspecialchars($action);
34 $r_action = rawurlencode($action);
41 return array('msg'=>$_title_backuplist,'body'=>get_backup_list_all());
43 if ($action == 'delete')
45 return plugin_backup_delete($page);
50 'msg' => $_title_pagebackuplist,
51 'body' => get_backup_list($page)
56 $body .= " <li><a href=\"$script?cmd=backup\">$_msg_backuplist</a></li>\n";
58 $href = "$script?cmd=backup&page=$r_page&age=$s_age";
60 if ($action != 'diff' and is_page($page))
62 $body .= " <li>".str_replace('$1',"<a href=\"$href&action=diff\">$_msg_diff</a>",$_msg_view)."</li>\n";
64 if ($action != 'nowdiff' and is_page($page))
66 $body .= " <li>".str_replace('$1',"<a href=\"$href&action=nowdiff\">$_msg_nowdiff</a>",$_msg_view)."</li>\n";
68 if ($action != 'source')
70 $body .= " <li>".str_replace('$1',"<a href=\"$href&action=source\">$_msg_source</a>",$_msg_view)."</li>\n";
74 $body .= " <li>".str_replace('$1',"<a href=\"$href\">$_msg_backup</a>",$_msg_view)."</li>\n";
79 $body .= " <li>".str_replace('$1',"<a href=\"$script?$r_page\">$s_page</a>",$_msg_goto)."</li>\n";
83 $body .= " <li>".str_replace('$1',$s_page,$_msg_deleted)."</li>\n";
86 $backups = get_backup($page);
87 if (count($backups) > 0)
90 foreach($backups as $age => $val)
92 $date = format_date($val['time'],TRUE);
93 $body .= ($age == $s_age) ?
94 " <li><em>$age $date</em></li>\n" :
95 " <li><a href=\"$script?cmd=backup&action=$r_action&page=$r_page&age=$age\">$age $date</a></li>\n";
102 if ($action == 'diff')
104 $old = ($s_age > 1) ? join('',$backups[$s_age - 1]['data']) : '';
105 $cur = join('',$backups[$s_age]['data']);
106 $body .= plugin_backup_diff(do_diff($old,$cur));
108 return array('msg'=>str_replace('$2',$s_age,$_title_backupdiff),'body'=>$body);
110 else if ($s_action == 'nowdiff')
112 $old = join('',$backups[$s_age]['data']);
113 $cur = join('',get_source($page));
114 $body .= plugin_backup_diff(do_diff($old,$cur));
116 return array('msg'=>str_replace('$2',$s_age,$_title_backupnowdiff),'body'=>$body);
118 else if ($s_action == 'source')
120 $body .= "<pre>".htmlspecialchars(join('',$backups[$s_age]['data']))."</pre>\n";
122 return array('msg'=>str_replace('$2',$s_age,$_title_backupsource),'body'=>$body);
125 $body .= "$hr\n".drop_submit(convert_html($backups[$s_age]['data']));
127 return array('msg'=>str_replace('$2',$s_age,$_title_backup),'body'=>$body);
129 // ¥Ð¥Ã¥¯¥¢¥Ã¥×¤òºï½ü
130 function plugin_backup_delete($page)
132 global $script,$post,$adminpass;
133 global $_title_backup_delete,$_msg_backup_deleted,$_msg_backup_delete;
134 global $_msg_backup_adminpass,$_btn_delete,$_msg_invalidpass;
136 if (!backup_file_exists($page))
140 $s_page = htmlspecialchars($page);
141 $pass = array_key_exists('pass',$post) ? $post['pass'] : NULL;
143 if (md5($pass) == $adminpass)
145 backup_delete($page);
147 'msg' => $_title_backup_delete,
148 'body' => str_replace('$1',make_pagelink($page),$_msg_backup_deleted)
151 $body = ($pass === NULL) ? '' : "<p><strong>$_msg_invalidpass</strong></p>\n";
153 $msg_delete = str_replace('$1',make_pagelink($page),$_msg_backup_delete);
155 <p>$_msg_backup_adminpass</p>
156 <form action="$script" method="post">
158 <input type="hidden" name="cmd" value="backup" />
159 <input type="hidden" name="page" value="$s_page" />
160 <input type="hidden" name="action" value="delete" />
161 <input type="password" name="pass" size="12" />
162 <input type="submit" name="ok" value="$_btn_delete" />
166 return array('msg'=>$_title_backup_delete,'body'=>$body);
168 function plugin_backup_diff($str)
170 global $_msg_addline,$_msg_delline,$hr;
172 $str = htmlspecialchars($str);
173 $str = preg_replace('/^(\-)(.*)$/m','<span class="diff_removed"> $2</span>',$str);
174 $str = preg_replace('/^(\+)(.*)$/m','<span class="diff_added"> $2</span>',$str);
179 <li>$_msg_addline</li>
180 <li>$_msg_delline</li>
188 // ¥Ð¥Ã¥¯¥¢¥Ã¥×°ìÍ÷¤ò¼èÆÀ
189 function get_backup_list($page)
192 global $_msg_backuplist,$_msg_diff,$_msg_nowdiff,$_msg_source,$_msg_nobackup;
193 global $_title_backup_delete;
195 $r_page = rawurlencode($page);
196 $s_page = htmlspecialchars($page);
200 <li><a href="$script?cmd=backup">$_msg_backuplist</a>
210 $backups = backup_file_exists($page) ? get_backup($page) : array();
211 if (count($backups) == 0)
213 $msg = str_replace('$1',make_pagelink($page),$_msg_nobackup);
214 $retval[1] .= " <li>$msg</li>\n";
215 return join('',$retval);
217 $retval[1] .= " <li><a href=\"$script?cmd=backup&action=delete&page=$r_page\">";
218 $retval[1] .= str_replace('$1',$s_page,$_title_backup_delete);
219 $retval[1] .= "</a></li>\n";
220 foreach ($backups as $age=>$data) {
221 $date = format_date($data['time'],TRUE);
222 $href = "$script?cmd=backup&page=$r_page&age=$age";
224 <li><a href="$href">$age $date</a>
225 [ <a href="$href&action=diff">$_msg_diff</a>
226 | <a href="$href&action=nowdiff">$_msg_nowdiff</a>
227 | <a href="$href&action=source">$_msg_source</a>
232 return join('',$retval);
234 // Á´¥Ú¡¼¥¸¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×°ìÍ÷¤ò¼èÆÀ
235 function get_backup_list_all($withfilename = FALSE)
239 $pages = array_diff(get_existpages(BACKUP_DIR,BACKUP_EXT),$cantedit);
241 if (count($pages) == 0)
246 return page_list($pages,'backup',$withfilename);