1<?php 2 3use dokuwiki\Extension\AdminPlugin; 4use dokuwiki\plugin\extension\Exception as RepoException; 5use dokuwiki\plugin\extension\Extension; 6use dokuwiki\plugin\extension\Gui; 7use dokuwiki\plugin\extension\GuiAdmin; 8use dokuwiki\plugin\extension\Installer; 9use dokuwiki\plugin\extension\Repository; 10 11/** 12 * DokuWiki Plugin extension (Admin Component) 13 * 14 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 15 */ 16class admin_plugin_extension extends AdminPlugin 17{ 18 /** 19 * Execute the requested action(s) and initialize the plugin repository 20 */ 21 public function handle() 22 { 23 global $INPUT; 24 25 // check access to the repository and SSL support 26 $repo = Repository::getInstance(); 27 try { 28 $repo->checkAccess(); 29 } catch (RepoException $e) { 30 msg($e->getMessage(), -1); 31 } 32 33 // Only continue if there is something to do 34 if (!$INPUT->post->has('fn') && !$INPUT->post->str('installurl') && !isset($_FILES['installfile'])) { 35 return; // nothing to do 36 } 37 if (!checkSecurityToken()) return; 38 39 // Run actions on the installer 40 $installer = new Installer($INPUT->post->bool('overwrite')); 41 try { 42 foreach ($INPUT->post->arr('fn') as $action => $extensions) { 43 foreach ($extensions as $extension => $label) { 44 $ext = Extension::createFromId($extension); 45 switch ($action) { 46 case 'install': 47 case 'reinstall': 48 case 'update': 49 $installer->installExtension($ext); 50 break; 51 case 'uninstall': 52 $installer->uninstall($ext); 53 break; 54 case 'enable': 55 $ext->enable(); 56 break; 57 case 'disable': 58 $ext->disable(); 59 break; 60 } 61 } 62 } 63 if ($INPUT->post->str('installurl')) { 64 $installer->installFromURL($INPUT->post->str('installurl')); 65 } 66 if (isset($_FILES['installfile'])) { 67 $installer->installFromUpload('installfile'); 68 } 69 } catch (Exception $e) { 70 msg(hsc($e->getMessage()), -1); 71 } 72 73 // Report results of the installer 74 $processed = $installer->getProcessed(); 75 foreach ($processed as $id => $status) { 76 if ($status == Installer::STATUS_INSTALLED) { 77 msg(sprintf($this->getLang('msg_install_success'), $id), 1); 78 } elseif ($status == Installer::STATUS_UPDATED) { 79 msg(sprintf($this->getLang('msg_update_success'), $id), 1); 80 } elseif ($status == Installer::STATUS_SKIPPED) { 81 msg(sprintf($this->getLang('msg_nooverwrite'), $id), 0); 82 } elseif ($status == Installer::STATUS_REMOVED) { 83 msg(sprintf($this->getLang('msg_delete_success'), $id), 1); 84 } 85 } 86 87 // Redirect to clear the POST data 88 $gui = new Gui(); 89 send_redirect($gui->tabURL($gui->currentTab(), [], '&', true)); 90 } 91 92 /** 93 * Render HTML output 94 */ 95 public function html() 96 { 97 echo '<h1>' . $this->getLang('menu') . '</h1>'; 98 99 $gui = new GuiAdmin(); 100 echo $gui->render(); 101 } 102} 103