1<?php 2/** 3 * DokuWiki Plugin extension (Admin Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Michael Hamann <michael@content-space.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12/** 13 * Admin part of the extension manager 14 */ 15class admin_plugin_extension extends DokuWiki_Admin_Plugin { 16 protected $infoFor = null; 17 18 /** 19 * @return int sort number in admin menu 20 */ 21 public function getMenuSort() { 22 return 0; 23 } 24 25 /** 26 * @return bool true if only access for superuser, false is for superusers and moderators 27 */ 28 public function forAdminOnly() { 29 return true; 30 } 31 32 /** 33 * Execute the requested action(s) and initialize the plugin repository 34 */ 35 public function handle() { 36 global $INPUT; 37 // initialize the remote repository 38 /* @var helper_plugin_extension_repository $repository */ 39 $repository = $this->loadHelper('extension_repository'); 40 $repository->init(); 41 42 /* @var helper_plugin_extension_extension $extension */ 43 $extension = $this->loadHelper('extension_extension'); 44 45 if ($INPUT->post->has('fn')) { 46 $actions = $INPUT->post->arr('fn'); 47 foreach ($actions as $action => $extensions) { 48 foreach ($extensions as $extname => $label) { 49 switch ($action) { 50 case 'info': 51 $this->infoFor = $extname; 52 break; 53 case 'install': 54 msg('Not implemented'); 55 break; 56 case 'reinstall': 57 case 'update': 58 $extension->setExtension($extname, false); 59 $status = $extension->installOrUpdate(); 60 if ($status !== true) { 61 msg($status, -1); 62 } else { 63 msg(sprintf($this->getLang('msg_update_success'), hsc($extension->getName())), 1); 64 } 65 break; 66 case 'uninstall': 67 $extension->setExtension($extname, false); 68 $status = $extension->uninstall(); 69 if ($status !== true) { 70 msg($status, -1); 71 } else { 72 msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getName())), 1); 73 } 74 break; 75 case 'enable'; 76 $extension->setExtension($extname, false); 77 $status = $extension->enable(); 78 if ($status !== true) { 79 msg($status, -1); 80 } else { 81 msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getName())), 1); 82 } 83 break; 84 case 'disable'; 85 $extension->setExtension($extname, false); 86 $status = $extension->disable(); 87 if ($status !== true) { 88 msg($status, -1); 89 } else { 90 msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getName())), 1); 91 } 92 break; 93 } 94 } 95 } 96 } 97 } 98 99 /** 100 * Render HTML output 101 */ 102 public function html() { 103 /* @var Doku_Plugin_Controller $plugin_controller */ 104 global $plugin_controller; 105 ptln('<h1>'.$this->getLang('menu').'</h1>'); 106 ptln('<div id="extension__manager">'); 107 108 $pluginlist = $plugin_controller->getList('', true); 109 /* @var helper_plugin_extension_extension $extension */ 110 $extension = $this->loadHelper('extension_extension'); 111 /* @var helper_plugin_extension_list $list */ 112 $list = $this->loadHelper('extension_list'); 113 $list->start_form(); 114 foreach ($pluginlist as $name) { 115 $extension->setExtension($name, false); 116 $list->add_row($extension, $name == $this->infoFor); 117 } 118 $list->end_form(); 119 $list->render(); 120 ptln('</div>'); 121 } 122} 123 124// vim:ts=4:sw=4:et: