OSDN Git Service

BugTrack2/374 Show authors on backup list
authorumorigu <umorigu@gmail.com>
Mon, 1 Feb 2016 16:39:40 +0000 (01:39 +0900)
committerumorigu <umorigu@gmail.com>
Tue, 2 Feb 2016 16:55:41 +0000 (01:55 +0900)
lib/backup.php
plugin/backup.inc.php

index 9dcb3ca..a15e848 100644 (file)
@@ -13,7 +13,7 @@
  * @create
  * @version $Id: backup.php,v 1.13 2011/01/25 15:01:01 henoheno Exp $
  * 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
  **/
@@ -33,6 +33,7 @@ function make_backup($page, $delete = FALSE)
 {
        global $cycle, $maxage;
        global $do_backup, $del_backup;
+       global $auth_user;
 
        if (PKWK_READONLY || ! $do_backup) return;
 
@@ -44,7 +45,22 @@ function make_backup($page, $delete = FALSE)
        if (! is_page($page)) return;
 
        $lastmod = _backup_get_filetime($page);
-       if ($lastmod == 0 || UTIME - $lastmod > 60 * 60 * $cycle)
+       $backups = get_backup($page);
+       $is_author_differ = false;
+       $need_backup_by_time = $lastmod == 0 || UTIME - $lastmod > 60 * 60 * $cycle;
+       if (!$need_backup_by_time) {
+               // Backup file is saved recently, but the author may differ.
+               $last_content = get_source($page, FALSE, TRUE);
+               $m = array();
+               if (preg_match('/^\s*#author\("([^"]+)","([^"]+)","([^"]*)"\)/m', $last_content, $m)) {
+                       $prev_author = $m[2];
+                       $simple_author =preg_replace('/^[^:]:/', '', $prev_author);
+                       if ($simple_author !== $auth_user) {
+                               $is_author_differ = true;
+                       }
+               }
+       }
+       if ($need_backup_by_time || $is_author_differ)
        {
                $backups = get_backup($page);
                $count   = count($backups) + 1;
@@ -105,6 +121,11 @@ function get_backup($page, $age = 0)
 
                        // Allocate
                        $retvars[$_age] = array('time'=>$match[1], 'data'=>array());
+               } else if (preg_match('/^\s*#author\("([^"]+)","([^"]+)","([^"]*)"\)/', $line, $match)) {
+                       $retvars[$_age]['author_datetime'] = $match[1];
+                       $retvars[$_age]['author'] = $match[2];
+                       $retvars[$_age]['author_fullname'] = $match[3];
+                       $retvars[$_age]['data'][] = $line;
                } else {
                        // The first ... the last line of the data
                        $retvars[$_age]['data'][] = $line;
@@ -306,4 +327,3 @@ else
                        array();
        }
 }
-?>
index 91befe7..f3c1557 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: backup.inc.php,v 1.29 2011/01/25 15:01:01 henoheno Exp $
+// backup.inc.php
 // Copyright (C)
-//   2002-2005 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
 //
@@ -218,12 +218,17 @@ EOD;
                        $_anchor_to   = '</a>';
                }
                $date = format_date($data['time'], TRUE);
+               $author_info = '';
+               if (isset($data['author'])) {
+                       $author_info = htmlsc('by ' . $data['author_fullname']
+                               . '(' . $data['author'] . ')');
+               }
                $retval[1] .= <<<EOD
    <li>$_anchor_from$age $date$_anchor_to
      [ <a href="$href$age&amp;action=diff">$_msg_diff</a>
      | <a href="$href$age&amp;action=nowdiff">$_msg_nowdiff</a>
      | <a href="$href$age&amp;action=source">$_msg_source</a>
-     ]
+     ] $author_info
    </li>
 EOD;
        }
@@ -244,4 +249,3 @@ function plugin_backup_get_list_all($withfilename = FALSE)
                return page_list($pages, 'backup', $withfilename);
        }
 }
-?>