xref: /plugin/structpublish/action/show.php (revision 8d2065f7b2b1f3b8d189ad26587e4daa79a85afd)
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('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleShow');
16    }
17
18    public function handleShow(Doku_Event $event)
19    {
20        if ($event->data != 'show') return;
21
22        global $ID;
23        global $REV;
24        global $INFO;
25
26        $this->permissionsHelper = plugin_load('helper', 'structpublish_permissions');
27        /** @var helper_plugin_structpublish_db $dbHelper */
28        $dbHelper = plugin_load('helper', 'structpublish_db');
29
30        if (!$this->permissionsHelper->isPublishable()) return;
31
32        $currentRevision = new Revision($dbHelper->getDB(), $ID, $INFO['currentrev']);
33        if (
34            $currentRevision->getStatus() !== Revision::STATUS_PUBLISHED
35            && !$dbHelper->IS_PUBLISHER($ID)
36        ) {
37            $latestPublishedRev = $currentRevision->getLatestPublished('revision');
38            if (!$latestPublishedRev) {
39                $event->data = 'denied';
40                $event->preventDefault();
41                $event->stopPropagation();
42                print p_locale_xhtml('denied');
43            }
44
45            $REV = $latestPublishedRev;
46            $INFO['rev'] = $latestPublishedRev;
47        }
48    }
49}
50