-
Notifications
You must be signed in to change notification settings - Fork 1
/
show.php
91 lines (76 loc) · 2.72 KB
/
show.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use dokuwiki\plugin\structpublish\meta\Constants;
use dokuwiki\plugin\structpublish\meta\Revision;
class action_plugin_structpublish_show extends DokuWiki_Action_Plugin
{
/** @var int */
protected static $latestPublishedRev;
/** @inheritDoc */
public function register(Doku_Event_Handler $controller)
{
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleShow');
$controller->register_hook('HTML_SHOWREV_OUTPUT', 'BEFORE', $this, 'handleShowrev');
}
/**
* Decide which revision to show based on role assignments
*
* @param Doku_Event $event
* @return void
*/
public function handleShow(Doku_Event $event)
{
if ($event->data != 'show') {
return;
}
global $ID;
global $REV;
global $INFO;
/** @var helper_plugin_structpublish_db $dbHelper */
$dbHelper = plugin_load('helper', 'structpublish_db');
if (
!$dbHelper->isPublishable() ||
(auth_isadmin() && !$this->getConf('restrict_admin'))
) {
return;
}
$currentRevision = new Revision($ID, $REV ?: $INFO['currentrev']);
$isPublished = $currentRevision->getStatus() === Constants::STATUS_PUBLISHED;
if (!$dbHelper->isPublisher($ID)) {
$latestPublished = $currentRevision->getLatestPublishedRevision();
// there is no published revision, show nothing
if (!$isPublished && is_null($latestPublished)) {
$event->data = 'denied';
// FIXME we could add our own action to display a custom message instead of standard denied action
return;
}
self::$latestPublishedRev = $latestPublished->getRev();
// show either the explicitly requested or the latest published revision
if (!$isPublished) {
$REV = self::$latestPublishedRev;
$INFO['rev'] = self::$latestPublishedRev;
}
}
}
/**
* Suppress message about viewing an old revision if it is the latest one
* that the current user is allowed to see.
*
* @param Doku_Event $event
* @return void
*/
public function handleShowrev(Doku_Event $event)
{
/** @var helper_plugin_structpublish_db $dbHelper */
$dbHelper = plugin_load('helper', 'structpublish_db');
if (
!$dbHelper->isPublishable() ||
(auth_isadmin() && !$this->getConf('restrict_admin'))
) {
return;
}
global $INFO;
if (self::$latestPublishedRev && self::$latestPublishedRev == $INFO['rev']) {
$event->preventDefault();
}
}
}