xref: /plugin/structpublish/action/show.php (revision e394901a0f7c5b3f8d056c0f4d754d974f4f8413)
1<?php
2
3use dokuwiki\plugin\structpublish\meta\Revision;
4
5class action_plugin_structpublish_show extends DokuWiki_Action_Plugin
6{
7    /** @var \helper_plugin_structpublish_permissions */
8    protected $permissionsHelper;
9
10    /**
11     * @inheritDoc
12     */
13    public function register(Doku_Event_Handler $controller)
14    {
15        $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handleShow');
16    }
17
18    public function handleShow(Doku_Event $event)
19    {
20        if ($event->data != 'show') return;
21
22        $this->permissionsHelper = plugin_load('helper', 'structpublish_permissions');
23
24        global $ID;
25        global $INFO;
26        global $REV;
27
28        $sqlite = $this->permissionsHelper->getDb();
29
30        $currentRevision = new Revision($sqlite, $ID, $INFO['currentrev']);
31        if ($currentRevision->getStatus() !== Revision::STATUS_PUBLISHED) {
32            /** @var Revision $latestPublished */
33            $latestPublished = $this->permissionsHelper->getLatestPublished();
34            if (!$latestPublished) {
35                $event->data = 'denied';
36
37                $event->preventDefault();
38                $event->stopPropagation();
39
40                print p_locale_xhtml('denied');
41            }
42
43                $REV = $latestPublished->getRev();
44        }
45    }
46}
47