OSDN Git Service

BugTrack2/378 Record delete action history and its user
authorumorigu <umorigu@gmail.com>
Wed, 3 Feb 2016 14:33:28 +0000 (23:33 +0900)
committerumorigu <umorigu@gmail.com>
Wed, 3 Feb 2016 14:33:28 +0000 (23:33 +0900)
lib/backup.php
lib/file.php

index a15e848..cd90652 100644 (file)
@@ -11,7 +11,6 @@
  * @access  public
  * @author
  * @create
- * @version $Id: backup.php,v 1.13 2011/01/25 15:01:01 henoheno Exp $
  * Copyright (C)
  *   2002-2016 PukiWiki Development Team
  *   2001-2002 Originally written by yu-ji
@@ -29,7 +28,7 @@
  * @return    Void
  */
 
-function make_backup($page, $delete = FALSE)
+function make_backup($page, $is_delete, $wikitext)
 {
        global $cycle, $maxage;
        global $do_backup, $del_backup;
@@ -37,7 +36,7 @@ function make_backup($page, $delete = FALSE)
 
        if (PKWK_READONLY || ! $do_backup) return;
 
-       if ($del_backup && $delete) {
+       if ($del_backup && $is_delete) {
                _backup_delete($page);
                return;
        }
@@ -60,11 +59,10 @@ function make_backup($page, $delete = FALSE)
                        }
                }
        }
-       if ($need_backup_by_time || $is_author_differ)
+       if ($need_backup_by_time || $is_author_differ || $is_delete)
        {
                $backups = get_backup($page);
                $count   = count($backups) + 1;
-
                // 直後に1件追加するので、(最大件数 - 1)を超える要素を捨てる
                if ($count > $maxage)
                        array_splice($backups, 0, $count - $maxage);
@@ -81,12 +79,17 @@ function make_backup($page, $delete = FALSE)
                $body = preg_replace('/^(' . preg_quote(PKWK_SPLITTER) . "\s\d+)$/", '$1 ', get_source($page));
                $body = PKWK_SPLITTER . ' ' . get_filetime($page) . "\n" . join('', $body);
                $body = preg_replace("/\n*$/", "\n", $body);
-
+               $body_on_delete = '';
+               if ($is_delete) {
+                       $body_on_delete = PKWK_SPLITTER . ' ' . UTIME . "\n" . $wikitext;
+                       $body_on_delete = preg_replace("/\n*$/", "\n", $body_on_delete);
+               }
                $fp = _backup_fopen($page, 'wb')
                        or die_message('Cannot open ' . htmlsc(_backup_get_filename($page)) .
                        '<br />Maybe permission is not writable or filename is too long');
                _backup_fputs($fp, $strout);
                _backup_fputs($fp, $body);
+               _backup_fputs($fp, $body_on_delete);
                _backup_fclose($fp);
        }
 }
index 1d70c23..a950ff0 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: file.php,v 1.95 2011/01/25 15:01:01 henoheno Exp $
+// file.php
 // Copyright (C)
-//   2002-2006 PukiWiki Developers Team
+//   2002-2016 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -84,7 +84,9 @@ function page_write($page, $postdata, $notimestamp = FALSE)
        if (PKWK_READONLY) return; // Do nothing
 
        $postdata = make_str_rules($postdata);
-       $postdata = add_author_info(remove_author_info($postdata));
+       $text_without_author = remove_author_info($postdata);
+       $postdata = add_author_info($text_without_author);
+       $is_delete = empty($text_without_author);
 
        // Create and write diff
        $oldpostdata = is_page($page) ? join('', get_source($page)) : '';
@@ -92,10 +94,10 @@ function page_write($page, $postdata, $notimestamp = FALSE)
        file_write(DIFF_DIR, $page, $diffdata);
 
        // Create backup
-       make_backup($page, $postdata == ''); // Is $postdata null?
+       make_backup($page, $is_delete, $postdata); // Is $postdata null?
 
        // Create wiki text
-       file_write(DATA_DIR, $page, $postdata, $notimestamp);
+       file_write(DATA_DIR, $page, $postdata, $notimestamp, $is_delete);
 
        links_update($page);
 }
@@ -236,7 +238,7 @@ function file_head($file, $count = 1, $lock = TRUE, $buffer = 8192)
 }
 
 // Output to a file
-function file_write($dir, $page, $str, $notimestamp = FALSE)
+function file_write($dir, $page, $str, $notimestamp = FALSE, $is_delete = FALSE)
 {
        global $_msg_invalidiwn, $notify, $notify_diff_only, $notify_subject;
        global $whatsdeleted, $maxshow_deleted;
@@ -251,7 +253,7 @@ function file_write($dir, $page, $str, $notimestamp = FALSE)
        // ----
        // Delete?
 
-       if ($dir == DATA_DIR && $str === '') {
+       if ($dir == DATA_DIR && $is_delete) {
                // Page deletion
                if (! $file_exists) return; // Ignore null posting for DATA_DIR
 
@@ -845,4 +847,3 @@ function pkwk_touch_file($filename, $time = FALSE, $atime = FALSE)
                        htmlsc(basename($filename)));
        }
 }
-