1<?php
2
3use dokuwiki\Extension\ActionPlugin;
4use dokuwiki\Extension\EventHandler;
5use dokuwiki\Extension\Event;
6use dokuwiki\Extension\PluginController;
7
8/**
9 * DokuWiki Plugin farmer (Action Component)
10 *
11 * Disable Plugins on install
12 *
13 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
14 * @author  Michael Große <grosse@cosmocode.de>
15 * @author  Andreas Gohr <gohr@cosmocode.de>
16 */
17class action_plugin_farmer_disable extends ActionPlugin
18{
19    /**
20     * plugin should use this method to register its handlers with the DokuWiki's event controller
21     *
22     * @param EventHandler $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER
23     */
24    public function register(EventHandler $controller)
25    {
26        /** @var helper_plugin_farmer $farmer */
27        $farmer = plugin_load('helper', 'farmer');
28        if ($farmer->getAnimal()) return;
29
30        if ($this->getConf('disable_new_plugins')) {
31            $controller->register_hook('PLUGIN_EXTENSION_CHANGE', 'AFTER', $this, 'handleInstall');
32        }
33    }
34
35    /**
36     * handle install of new plugin
37     *
38     * @param Event $event
39     * @param $param
40     */
41    public function handleInstall(Event $event, $param)
42    {
43        if ($event->data['action'] != 'install') return;
44
45        /* @var Doku_Plugin_Controller $plugin_controller */
46        global $plugin_controller;
47        $plugin_controller = new PluginController(); // we need to refresh the status
48
49        /** @var helper_plugin_extension_extension $ext */
50        $ext = $event->data['extension'];
51        $disabled = $ext->disable();
52        if ($disabled === true) {
53            msg($this->getLang('disable_new_plugins'));
54        } else {
55            msg(hsc($disabled), -1);
56        }
57    }
58}
59