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