11413d607SAndreas Gohr<?php 2*1da41c8bSAndreas Gohr 3*1da41c8bSAndreas Gohruse dokuwiki\Extension\ActionPlugin; 4*1da41c8bSAndreas Gohruse dokuwiki\Extension\EventHandler; 5*1da41c8bSAndreas Gohruse dokuwiki\Extension\Event; 6*1da41c8bSAndreas Gohruse dokuwiki\Extension\PluginController; 7*1da41c8bSAndreas Gohr 81413d607SAndreas Gohr/** 91413d607SAndreas Gohr * DokuWiki Plugin farmer (Action Component) 101413d607SAndreas Gohr * 11*1da41c8bSAndreas Gohr * Disable Plugins on install 12*1da41c8bSAndreas Gohr * 131413d607SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 141413d607SAndreas Gohr * @author Michael Große <grosse@cosmocode.de> 151413d607SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 161413d607SAndreas Gohr */ 17*1da41c8bSAndreas Gohrclass action_plugin_farmer_disable extends ActionPlugin 18*1da41c8bSAndreas Gohr{ 191413d607SAndreas Gohr /** 201413d607SAndreas Gohr * plugin should use this method to register its handlers with the DokuWiki's event controller 211413d607SAndreas Gohr * 22*1da41c8bSAndreas Gohr * @param EventHandler $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER 231413d607SAndreas Gohr */ 24*1da41c8bSAndreas Gohr public function register(EventHandler $controller) 25*1da41c8bSAndreas Gohr { 261413d607SAndreas Gohr /** @var helper_plugin_farmer $farmer */ 271413d607SAndreas Gohr $farmer = plugin_load('helper', 'farmer'); 281413d607SAndreas Gohr if ($farmer->getAnimal()) return; 291413d607SAndreas Gohr 301413d607SAndreas Gohr if ($this->getConf('disable_new_plugins')) { 31*1da41c8bSAndreas Gohr $controller->register_hook('PLUGIN_EXTENSION_CHANGE', 'AFTER', $this, 'handleInstall'); 321413d607SAndreas Gohr } 331413d607SAndreas Gohr } 341413d607SAndreas Gohr 351413d607SAndreas Gohr /** 361413d607SAndreas Gohr * handle install of new plugin 371413d607SAndreas Gohr * 38*1da41c8bSAndreas Gohr * @param Event $event 391413d607SAndreas Gohr * @param $param 401413d607SAndreas Gohr */ 41*1da41c8bSAndreas Gohr public function handleInstall(Event $event, $param) 42*1da41c8bSAndreas Gohr { 431413d607SAndreas Gohr if ($event->data['action'] != 'install') return; 441413d607SAndreas Gohr 451413d607SAndreas Gohr /* @var Doku_Plugin_Controller $plugin_controller */ 461413d607SAndreas Gohr global $plugin_controller; 47*1da41c8bSAndreas Gohr $plugin_controller = new PluginController(); // we need to refresh the status 481413d607SAndreas Gohr 491413d607SAndreas Gohr /** @var helper_plugin_extension_extension $ext */ 501413d607SAndreas Gohr $ext = $event->data['extension']; 511413d607SAndreas Gohr $disabled = $ext->disable(); 521413d607SAndreas Gohr if ($disabled === true) { 531413d607SAndreas Gohr msg($this->getLang('disable_new_plugins')); 541413d607SAndreas Gohr } else { 551413d607SAndreas Gohr msg(hsc($disabled), -1); 561413d607SAndreas Gohr } 571413d607SAndreas Gohr } 581413d607SAndreas Gohr} 59