1<?php
2
3class action_plugin_publish_start extends DokuWiki_Action_Plugin {
4
5    /**
6     * @var helper_plugin_publish
7     */
8    private $hlp;
9
10    function __construct() {
11        $this->hlp = plugin_load('helper','publish');
12    }
13
14    function register(Doku_Event_Handler $controller) {
15        $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handle_start', array());
16    }
17
18    function handle_start(Doku_Event $event) {
19        global $ACT;
20        global $REV;
21        global $INFO;
22        global $INPUT;
23        global $ID;
24
25        if ($ACT !== 'show') {
26            return;
27        }
28
29        if (!empty($REV)) {
30            return;
31        }
32
33        if ($INFO['perm'] != AUTH_READ) {
34            return;
35        }
36
37        if($INPUT->has('force_rev')) {
38            return;
39        }
40
41        if (!$this->hlp->isActive()) {
42            return;
43        }
44
45        if (!$this->hlp->isCurrentRevisionApproved()) {
46            $latestApproved = $this->hlp->getLatestApprovedRevision();
47            if ($latestApproved) {
48                $REV = $latestApproved;
49                $INFO['rev'] = $latestApproved;
50            }
51        }
52    }
53}
54