Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ vendor/*/*/test/*
vendor/*/*/doc/*
vendor/*/*/docs/*
vendor/*/*/contrib/*
.DS_Store
71 changes: 71 additions & 0 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ function ($match) {
$html
);

// @OLDREVISIONS[(<limit>)]@
$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;
}

Expand All @@ -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 = '<table class="changelog"><tbody>';
$html .= '<tr><th>' . hsc($date) . '</th><th>' . hsc($userStr) . '</th><th>' . hsc($summary) . '</th></tr>';
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 .= '<tr>';
Comment thread
eduardomozart marked this conversation as resolved.
$html .= '<td>' . dformat($change['date']) . '</td>';
$html .= '<td>' . hsc($user) . '</td>';
$html .= '<td>' . hsc($change['sum']) . '</td>';
$html .= '</tr>';
}
$html .= '</tbody></table>';

return $html;
}
}
1 change: 1 addition & 0 deletions tpl/default/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =====

Expand Down