From 7b1d92d12c1e1bfb869be9f85582955ccfedda6e Mon Sep 17 00:00:00 2001
From: E <2974895+eduardomozart@users.noreply.github.com>
Date: Wed, 22 Jul 2026 17:03:21 -0300
Subject: [PATCH 1/3] Feature: @OLDREVISIONS@ placeholder
---
src/Template.php | 38 ++++++++++++++++++++++++++++++++++++++
tpl/default/README.txt | 1 +
2 files changed, 39 insertions(+)
diff --git a/src/Template.php b/src/Template.php
index 641ac1bd..0a26cc17 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -131,6 +131,7 @@ protected function replacePlaceholders(string $html): string
'@UPDATE@' => dformat(filemtime(wikiFN($this->context['id'], $this->context['rev'] ?? ''))),
'@PAGEURL@' => $url,
'@QRCODE@' => $this->generateQRCode($url),
+ '@OLDREVISIONS@' => $this->changesToHTML($this->changesToArray($this->context['id'] ?? '')),
];
// let other plugins define their own replacements
@@ -181,4 +182,41 @@ protected function generateQRCode($url): string
$this->qrScale
);
}
+
+ /**
+ * Get revisions for a page
+ *
+ * @param string $id Page ID
+ * @return array
+ */
+ protected function changesToArray(string $id): array
+ {
+ if (empty($id)) return [];
+ require_once DOKU_INC . 'inc/changelog.php';
+ $pagelog = new \PageChangeLog($id);
+ return $pagelog->getRevisions(-1, 50); // Get at most 50 revisions
+ }
+
+ /**
+ * Format revisions as HTML table
+ *
+ * @param array $changes
+ * @return string
+ */
+ protected function changesToHTML(array $changes): string
+ {
+ if (empty($changes)) return '';
+ $html = '
';
+ $html .= '| Date | Author | Summary |
';
+ foreach ($changes as $change) {
+ $html .= '';
+ $html .= '| ' . dformat($change['date']) . ' | ';
+ $html .= '' . hsc($change['user']) . ' | ';
+ $html .= '' . hsc($change['sum']) . ' | ';
+ $html .= '
';
+ }
+ $html .= '
';
+
+ return $html;
+ }
}
diff --git a/tpl/default/README.txt b/tpl/default/README.txt
index 60216e48..a27e94ce 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@'' -- A table with the changelog of the current page
===== Styles =====
From afbd147970b84e67dad950bafab0bdc0b7254222 Mon Sep 17 00:00:00 2001
From: E <2974895+eduardomozart@users.noreply.github.com>
Date: Wed, 22 Jul 2026 17:37:43 -0300
Subject: [PATCH 2/3] Add optional limit param to @OLDREVISIONS@
Replace the static @OLDREVISIONS@ placeholder with a dynamic version supporting an optional numeric limit: @OLDREVISIONS(N)@. Defaults to 50 if no limit is specified. Updated README to document the new syntax.
---
src/Template.php | 16 +++++++++++++---
tpl/default/README.txt | 2 +-
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/Template.php b/src/Template.php
index 0a26cc17..452b5911 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -131,7 +131,6 @@ protected function replacePlaceholders(string $html): string
'@UPDATE@' => dformat(filemtime(wikiFN($this->context['id'], $this->context['rev'] ?? ''))),
'@PAGEURL@' => $url,
'@QRCODE@' => $this->generateQRCode($url),
- '@OLDREVISIONS@' => $this->changesToHTML($this->changesToArray($this->context['id'] ?? '')),
];
// let other plugins define their own replacements
@@ -162,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;
}
@@ -187,14 +196,15 @@ protected function generateQRCode($url): string
* 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): array
+ protected function changesToArray(string $id, int $limit = 50): array
{
if (empty($id)) return [];
require_once DOKU_INC . 'inc/changelog.php';
$pagelog = new \PageChangeLog($id);
- return $pagelog->getRevisions(-1, 50); // Get at most 50 revisions
+ return $pagelog->getRevisions(-1, $limit); // Get at most $limit revisions
}
/**
diff --git a/tpl/default/README.txt b/tpl/default/README.txt
index a27e94ce..8d6b4428 100644
--- a/tpl/default/README.txt
+++ b/tpl/default/README.txt
@@ -57,7 +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@'' -- A table with the changelog of the current page
+ * ''@OLDREVISIONS@'' or ''@OLDREVISIONS(10)@'' -- A table with the changelog of the current page, optional parameter specifies the limit (default 50)
===== Styles =====
From 4e3798d71b569951e4c3b389f3acea5f7ca5f053 Mon Sep 17 00:00:00 2001
From: E <2974895+eduardomozart@users.noreply.github.com>
Date: Thu, 23 Jul 2026 18:08:27 -0300
Subject: [PATCH 3/3] Refactor OLDREVISIONS: fix autoloader, use real names and
core translations
---
.gitignore | 1 +
src/Template.php | 33 ++++++++++++++++++++++++++++-----
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
index f3916f2a..40c101f8 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 452b5911..af9b19fa 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -202,9 +202,17 @@ protected function generateQRCode($url): string
protected function changesToArray(string $id, int $limit = 50): array
{
if (empty($id)) return [];
- require_once DOKU_INC . 'inc/changelog.php';
- $pagelog = new \PageChangeLog($id);
- return $pagelog->getRevisions(-1, $limit); // Get at most $limit revisions
+ $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;
}
/**
@@ -216,12 +224,27 @@ protected function changesToArray(string $id, int $limit = 50): array
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 .= '| Date | Author | Summary |
';
+ $html .= '| ' . hsc($date) . ' | ' . hsc($userStr) . ' | ' . hsc($summary) . ' |
';
+ 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 .= '| ' . dformat($change['date']) . ' | ';
- $html .= '' . hsc($change['user']) . ' | ';
+ $html .= '' . hsc($user) . ' | ';
$html .= '' . hsc($change['sum']) . ' | ';
$html .= '
';
}