From 14f6540fe0436ed2fa56b0b8683d1f071a0c799f Mon Sep 17 00:00:00 2001
From: "Simon Coffey spc03@doc.ic.ac.uk" <andi@splitbrain.org>
Date: Wed, 13 Feb 2008 15:57:34 +0100
Subject: [PATCH] Importoldchangelog: Added metadata support

Added function savePerPageMetadata() to populate creator and contributor fields
of metadata array from old-style changes.log.

darcs-hash:20080213145734-31360-226e84e11c5a95d2bcafd8d29abca24f76b25482.gz
---
 lib/plugins/importoldchangelog/action.php | 25 +++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/lib/plugins/importoldchangelog/action.php b/lib/plugins/importoldchangelog/action.php
index 8effe4ec9..29cea06c1 100644
--- a/lib/plugins/importoldchangelog/action.php
+++ b/lib/plugins/importoldchangelog/action.php
@@ -116,6 +116,30 @@ class action_plugin_importoldchangelog extends DokuWiki_Action_Plugin {
         io_saveFile(metaFN($id, '.changes'), implode('', $changes));
     }
 
+    function savePerPageMetadata($id, &$changes) {
+        global $auth;
+        ksort($changes); // order by date
+        $meta = array();
+        // Run through history and populate the metadata array
+        foreach ($changes as $date => $tmp) {
+            $user = $tmp['user'];
+            if ($tmp['type'] === DOKU_CHANGE_TYPE_CREATE) {
+                $meta['date']['created'] = $tmp['date'];
+                if ($user) {
+                    $userinfo = $auth->getUserData($user);
+                    $meta['creator'] = $userinfo['name'];
+                }
+            } else if ($tmp['type'] === DOKU_CHANGE_TYPE_EDIT) {
+                $meta['date']['modified'] = $tmp['date'];
+                if ($user) {
+                    $userinfo = $auth->getUserData($user);
+                    $meta['contributor'][$user] = $userinfo['name'];
+                }
+            }
+        }
+        p_set_metadata($id, $meta, true);
+    }
+
     function resetTimer() {
         // Add 5 minutes to the script execution timer...
         // This should be much more than needed.
@@ -144,6 +168,7 @@ class action_plugin_importoldchangelog extends DokuWiki_Action_Plugin {
         $this->resetTimer();
         $recent = array();
         foreach ($log as $id => $page) {
+            $this->savePerPageMetadata($id, $page);
             $this->savePerPageChanges($id, $page, $recent);
         }
         // save recent changes cache
-- 
GitLab