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