OSDN Git Service

BugTrack2/374 Record timestamp and edit user as author info
authorumorigu <umorigu@gmail.com>
Mon, 1 Feb 2016 14:14:31 +0000 (23:14 +0900)
committerumorigu <umorigu@gmail.com>
Mon, 1 Feb 2016 14:43:42 +0000 (23:43 +0900)
author plugin (plugin/author.inc.php) outputs empty string
for HTML text.

lib/file.php
plugin/author.inc.php [new file with mode: 0644]

index 03c872d..57737e0 100644 (file)
@@ -84,6 +84,7 @@ 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));
 
        // Create and write diff
        $oldpostdata = is_page($page) ? join('', get_source($page)) : '';
@@ -158,6 +159,30 @@ function make_str_rules($source)
        return implode("\n", $lines);
 }
 
+function add_author_info($wikitext)
+{
+       global $auth_user;
+       $author = preg_replace('/"/', '', $auth_user);
+       $displayname = preg_replace('/"/', '', $auth_user);
+       $author_text = sprintf('#author("%s","%s","%s")',
+               get_date_atom(UTIME + LOCALZONE), $author, $displayname) . "\n";
+       return $author_text . $wikitext;
+}
+
+function remove_author_info($wikitext)
+{
+       return preg_replace('/^\s*#author\([^\n]*(\n|$)/m', '', $wikitext);
+}
+
+function get_date_atom($timestamp)
+{
+       // Compatible with DATE_ATOM format
+       // return date(DATE_ATOM, $timestamp);
+       $zmin = abs(LOCALZONE / 60);
+       return date('Y-m-d\TH:i:s', $timestamp) . sprintf('%s%02d:%02d',
+               (LOCALZONE < 0 ? '-' : '+') , $zmin / 60, $zmin % 60);
+}
+
 // Generate ID
 function generate_fixed_heading_anchor_id($seed)
 {
diff --git a/plugin/author.inc.php b/plugin/author.inc.php
new file mode 100644 (file)
index 0000000..e91a4be
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+// PukiWiki - Yet another WikiWikiWeb clone.
+// author.inc.php
+// Copyright: 2016 PukiWiki Development Team
+// License: GPL v2 or (at your option) any later version
+//
+// author plugin
+
+function plugin_author_convert() { return ''; }