1<?php 2 3use dokuwiki\Extension\AdminPlugin; 4use dokuwiki\plugin\extension\Extension; 5use dokuwiki\plugin\extension\Gui; 6use dokuwiki\plugin\extension\Installer; 7 8/** 9 * DokuWiki Plugin extension (Admin Component) 10 * 11 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 12 * @author Michael Hamann <michael@content-space.de> 13 */ 14 15/** 16 * Admin part of the extension manager 17 */ 18class admin_plugin_extension extends AdminPlugin 19{ 20 protected $infoFor; 21 /** @var helper_plugin_extension_gui */ 22 protected $gui; 23 24 /** 25 * Constructor 26 * 27 * loads additional helpers 28 */ 29 public function __construct() 30 { 31 $this->gui = plugin_load('helper', 'extension_gui'); 32 } 33 34 /** 35 * @return int sort number in admin menu 36 */ 37 public function getMenuSort() 38 { 39 return 0; 40 } 41 42 /** 43 * @return bool true if only access for superuser, false is for superusers and moderators 44 */ 45 public function forAdminOnly() 46 { 47 return true; 48 } 49 50 /** 51 * Execute the requested action(s) and initialize the plugin repository 52 * 53 * @todo repo init and ssl check still missing 54 */ 55 public function handle() 56 { 57 global $INPUT; 58 59 if (!$INPUT->post->has('fn') && !$INPUT->post->str('installurl') && !isset($_FILES['installfile'])) { 60 return; // nothing to do 61 } 62 if (!checkSecurityToken()) return; 63 64 $installer = new Installer($INPUT->post->bool('overwrite')); 65 try { 66 foreach ($INPUT->post->arr('fn') as $action => $extensions) { 67 foreach ($extensions as $extension => $label) { 68 $ext = Extension::createFromId($extension); 69 switch ($action) { 70 case 'install': 71 case 'reinstall': 72 case 'update': 73 $installer->installExtension($ext); 74 break; 75 case 'uninstall': 76 $installer->uninstall($ext); 77 break; 78 case 'enable': 79 $ext->enable(); 80 break; 81 case 'disable': 82 $ext->disable(); 83 break; 84 } 85 } 86 } 87 if ($INPUT->post->str('installurl')) { 88 $installer->installFromURL($INPUT->post->str('installurl')); 89 } 90 if (isset($_FILES['installfile'])) { 91 $installer->installFromUpload('installfile'); 92 } 93 } catch (Exception $e) { 94 msg(hsc($e->getMessage()), -1); 95 } 96 97 $processed = $installer->getProcessed(); 98 foreach ($processed as $id => $status) { 99 if ($status == Installer::STATUS_INSTALLED) { 100 msg(sprintf($this->getLang('msg_install_success'), $id), 1); 101 } else if ($status == Installer::STATUS_UPDATED) { 102 msg(sprintf($this->getLang('msg_update_success'), $id), 1); 103 } else if ($status == Installer::STATUS_SKIPPED) { 104 msg(sprintf($this->getLang('msg_nooverwrite'), $id), 0); 105 } else if ($status == Installer::STATUS_REMOVED) { 106 msg(sprintf($this->getLang('msg_delete_success'), $id), 1); 107 } 108 } 109 110 send_redirect((new Gui())->tabURL('', [], '&', true)); 111 return; 112 113 // FIXME old stuff below 114 115 // initialize the remote repository 116 /* @var helper_plugin_extension_repository $repository */ 117 $repository = $this->loadHelper('extension_repository'); 118 119 if (!$repository->hasAccess(!$INPUT->bool('purge'))) { 120 $url = $this->gui->tabURL('', ['purge' => 1], '&'); 121 msg($this->getLang('repo_error') . 122 ' [<a href="' . $url . '" rel="noreferrer">' . $this->getLang('repo_retry') . '</a>]', -1); 123 } 124 125 if (!in_array('ssl', stream_get_transports())) { 126 msg($this->getLang('nossl'), -1); 127 } 128 } 129 130 /** 131 * Render HTML output 132 */ 133 public function html() 134 { 135 echo '<h1>' . $this->getLang('menu') . '</h1>'; 136 137 $gui = new \dokuwiki\plugin\extension\GuiAdmin(); 138 echo $gui->render(); 139 } 140} 141 142// vim:ts=4:sw=4:et: 143