diff --git a/.gitignore b/.gitignore index f3916f2..40c101f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ vendor/*/*/test/* vendor/*/*/doc/* vendor/*/*/docs/* vendor/*/*/contrib/* +.DS_Store diff --git a/src/Template.php b/src/Template.php index 641ac1b..af9b19f 100644 --- a/src/Template.php +++ b/src/Template.php @@ -161,6 +161,16 @@ function ($match) { $html ); + // @OLDREVISIONS[()]@ + $html = preg_replace_callback( + '/@OLDREVISIONS(?:\((\d+)\))?@/', + function ($match) { + $limit = isset($match[1]) && is_numeric($match[1]) ? (int)$match[1] : 50; + return $this->changesToHTML($this->changesToArray($this->context['id'] ?? '', $limit)); + }, + $html + ); + return $html; } @@ -181,4 +191,65 @@ protected function generateQRCode($url): string $this->qrScale ); } + + /** + * Get revisions for a page + * + * @param string $id Page ID + * @param int $limit Max number of revisions to return + * @return array + */ + protected function changesToArray(string $id, int $limit = 50): array + { + if (empty($id)) return []; + $pagelog = new \dokuwiki\ChangeLog\PageChangeLog($id); + $revisions = $pagelog->getRevisions(-1, $limit); // Get at most $limit revisions + + $changes = []; + foreach ($revisions as $rev) { + $change = $pagelog->getRevisionInfo($rev); + if ($change !== false) { + $changes[] = $change; + } + } + return $changes; + } + + /** + * Format revisions as HTML table + * + * @param array $changes + * @return string + */ + protected function changesToHTML(array $changes): string + { + if (empty($changes)) return ''; + + global $lang; + $date = $lang['media_sort_date'] ?? 'Date'; + $userStr = $lang['media_sort_name'] ?? 'Name'; + $summary = $lang['summary'] ?? 'Edit summary'; + + $html = ''; + $html .= ''; + global $auth; + foreach ($changes as $change) { + $user = $change['user']; + if ($auth && $user) { + $userData = $auth->getUserData($user); + if ($userData && !empty($userData['name'])) { + $user = $userData['name']; + } + } + + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + } + $html .= '
' . hsc($date) . '' . hsc($userStr) . '' . hsc($summary) . '
' . dformat($change['date']) . '' . hsc($user) . '' . hsc($change['sum']) . '
'; + + return $html; + } } diff --git a/tpl/default/README.txt b/tpl/default/README.txt index 60216e4..8d6b442 100644 --- a/tpl/default/README.txt +++ b/tpl/default/README.txt @@ -57,6 +57,7 @@ In the headers and footers the ID of the bookmanager page of the Bookcreator is * ''@PAGEURL@'' -- URL to the article * ''@UPDATE@'' -- Time of the last update of the article * ''@QRCODE@'' -- QR code image pointing to the original page url (requires an online generator, see config setting) + * ''@OLDREVISIONS@'' or ''@OLDREVISIONS(10)@'' -- A table with the changelog of the current page, optional parameter specifies the limit (default 50) ===== Styles =====