1788f86d9SMichael Hamann<?php 2d4f83172SAndreas Gohr 38553d24dSAndreas Gohruse dokuwiki\Extension\AdminPlugin; 4*79ff0cd0SAndreas Gohruse dokuwiki\plugin\extension\Exception as RepoException; 580bc92fbSAndreas Gohruse dokuwiki\plugin\extension\Extension; 680bc92fbSAndreas Gohruse dokuwiki\plugin\extension\Gui; 780bc92fbSAndreas Gohruse dokuwiki\plugin\extension\Installer; 8*79ff0cd0SAndreas Gohruse dokuwiki\plugin\extension\Repository; 9d4f83172SAndreas Gohr 10788f86d9SMichael Hamann/** 11788f86d9SMichael Hamann * DokuWiki Plugin extension (Admin Component) 12788f86d9SMichael Hamann * 13788f86d9SMichael Hamann * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 14788f86d9SMichael Hamann * @author Michael Hamann <michael@content-space.de> 15788f86d9SMichael Hamann */ 16788f86d9SMichael Hamann 1702779b18SMichael Hamann/** 1802779b18SMichael Hamann * Admin part of the extension manager 1902779b18SMichael Hamann */ 208553d24dSAndreas Gohrclass admin_plugin_extension extends AdminPlugin 2118b1e90aSAndreas Gohr{ 22fe2dcfd5SAndreas Gohr protected $infoFor; 23d7410643SAndreas Gohr /** @var helper_plugin_extension_gui */ 24d7410643SAndreas Gohr protected $gui; 25d7410643SAndreas Gohr 26d7410643SAndreas Gohr /** 27d7410643SAndreas Gohr * Constructor 28d7410643SAndreas Gohr * 29d7410643SAndreas Gohr * loads additional helpers 30d7410643SAndreas Gohr */ 3118b1e90aSAndreas Gohr public function __construct() 3218b1e90aSAndreas Gohr { 33d7410643SAndreas Gohr $this->gui = plugin_load('helper', 'extension_gui'); 34d7410643SAndreas Gohr } 35788f86d9SMichael Hamann 36788f86d9SMichael Hamann /** 37788f86d9SMichael Hamann * @return int sort number in admin menu 38788f86d9SMichael Hamann */ 3918b1e90aSAndreas Gohr public function getMenuSort() 4018b1e90aSAndreas Gohr { 41788f86d9SMichael Hamann return 0; 42788f86d9SMichael Hamann } 43788f86d9SMichael Hamann 44788f86d9SMichael Hamann /** 45788f86d9SMichael Hamann * @return bool true if only access for superuser, false is for superusers and moderators 46788f86d9SMichael Hamann */ 4718b1e90aSAndreas Gohr public function forAdminOnly() 4818b1e90aSAndreas Gohr { 49788f86d9SMichael Hamann return true; 50788f86d9SMichael Hamann } 51788f86d9SMichael Hamann 52788f86d9SMichael Hamann /** 5302779b18SMichael Hamann * Execute the requested action(s) and initialize the plugin repository 54788f86d9SMichael Hamann */ 5518b1e90aSAndreas Gohr public function handle() 5618b1e90aSAndreas Gohr { 5702779b18SMichael Hamann global $INPUT; 5880bc92fbSAndreas Gohr 59*79ff0cd0SAndreas Gohr // check access to the repository and SSL support 60*79ff0cd0SAndreas Gohr $repo = Repository::getInstance(); 61*79ff0cd0SAndreas Gohr try { 62*79ff0cd0SAndreas Gohr $repo->checkAccess(); 63*79ff0cd0SAndreas Gohr } catch (RepoException $e) { 64*79ff0cd0SAndreas Gohr msg($e->getMessage(), -1); 65*79ff0cd0SAndreas Gohr } 66*79ff0cd0SAndreas Gohr 67*79ff0cd0SAndreas Gohr // Only continue if there is something to do 6880bc92fbSAndreas Gohr if (!$INPUT->post->has('fn') && !$INPUT->post->str('installurl') && !isset($_FILES['installfile'])) { 6980bc92fbSAndreas Gohr return; // nothing to do 7080bc92fbSAndreas Gohr } 7180bc92fbSAndreas Gohr if (!checkSecurityToken()) return; 7280bc92fbSAndreas Gohr 73*79ff0cd0SAndreas Gohr // Run actions on the installer 7480bc92fbSAndreas Gohr $installer = new Installer($INPUT->post->bool('overwrite')); 7580bc92fbSAndreas Gohr try { 7680bc92fbSAndreas Gohr foreach ($INPUT->post->arr('fn') as $action => $extensions) { 7780bc92fbSAndreas Gohr foreach ($extensions as $extension => $label) { 7880bc92fbSAndreas Gohr $ext = Extension::createFromId($extension); 7980bc92fbSAndreas Gohr switch ($action) { 8080bc92fbSAndreas Gohr case 'install': 8180bc92fbSAndreas Gohr case 'reinstall': 8280bc92fbSAndreas Gohr case 'update': 8380bc92fbSAndreas Gohr $installer->installExtension($ext); 8480bc92fbSAndreas Gohr break; 8580bc92fbSAndreas Gohr case 'uninstall': 8680bc92fbSAndreas Gohr $installer->uninstall($ext); 8780bc92fbSAndreas Gohr break; 8880bc92fbSAndreas Gohr case 'enable': 8980bc92fbSAndreas Gohr $ext->enable(); 9080bc92fbSAndreas Gohr break; 9180bc92fbSAndreas Gohr case 'disable': 9280bc92fbSAndreas Gohr $ext->disable(); 9380bc92fbSAndreas Gohr break; 9480bc92fbSAndreas Gohr } 9580bc92fbSAndreas Gohr } 9680bc92fbSAndreas Gohr } 9780bc92fbSAndreas Gohr if ($INPUT->post->str('installurl')) { 9880bc92fbSAndreas Gohr $installer->installFromURL($INPUT->post->str('installurl')); 9980bc92fbSAndreas Gohr } 10080bc92fbSAndreas Gohr if (isset($_FILES['installfile'])) { 10180bc92fbSAndreas Gohr $installer->installFromUpload('installfile'); 10280bc92fbSAndreas Gohr } 10380bc92fbSAndreas Gohr } catch (Exception $e) { 10480bc92fbSAndreas Gohr msg(hsc($e->getMessage()), -1); 10580bc92fbSAndreas Gohr } 10680bc92fbSAndreas Gohr 107*79ff0cd0SAndreas Gohr // Report results of the installer 10880bc92fbSAndreas Gohr $processed = $installer->getProcessed(); 10980bc92fbSAndreas Gohr foreach ($processed as $id => $status) { 11080bc92fbSAndreas Gohr if ($status == Installer::STATUS_INSTALLED) { 11180bc92fbSAndreas Gohr msg(sprintf($this->getLang('msg_install_success'), $id), 1); 11280bc92fbSAndreas Gohr } else if ($status == Installer::STATUS_UPDATED) { 11380bc92fbSAndreas Gohr msg(sprintf($this->getLang('msg_update_success'), $id), 1); 11480bc92fbSAndreas Gohr } else if ($status == Installer::STATUS_SKIPPED) { 11580bc92fbSAndreas Gohr msg(sprintf($this->getLang('msg_nooverwrite'), $id), 0); 11680bc92fbSAndreas Gohr } else if ($status == Installer::STATUS_REMOVED) { 11780bc92fbSAndreas Gohr msg(sprintf($this->getLang('msg_delete_success'), $id), 1); 11880bc92fbSAndreas Gohr } 11980bc92fbSAndreas Gohr } 12080bc92fbSAndreas Gohr 12180bc92fbSAndreas Gohr send_redirect((new Gui())->tabURL('', [], '&', true)); 122788f86d9SMichael Hamann } 123788f86d9SMichael Hamann 124788f86d9SMichael Hamann /** 12502779b18SMichael Hamann * Render HTML output 126788f86d9SMichael Hamann */ 12718b1e90aSAndreas Gohr public function html() 12818b1e90aSAndreas Gohr { 1294fd6a1d7SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 1304fd6a1d7SAndreas Gohr 131981e70caSAndreas Gohr $gui = new \dokuwiki\plugin\extension\GuiAdmin(); 132981e70caSAndreas Gohr echo $gui->render(); 133788f86d9SMichael Hamann } 134788f86d9SMichael Hamann} 135788f86d9SMichael Hamann 136788f86d9SMichael Hamann// vim:ts=4:sw=4:et: 137