xref: /dokuwiki/lib/plugins/extension/admin.php (revision 9b006b5f7a639fdac82aa93c148829099d044e3f)
1788f86d9SMichael Hamann<?php
2d4f83172SAndreas Gohr
38553d24dSAndreas Gohruse dokuwiki\Extension\AdminPlugin;
479ff0cd0SAndreas Gohruse dokuwiki\plugin\extension\Exception as RepoException;
580bc92fbSAndreas Gohruse dokuwiki\plugin\extension\Extension;
680bc92fbSAndreas Gohruse dokuwiki\plugin\extension\Gui;
7652715ccSAndreas Gohruse dokuwiki\plugin\extension\GuiAdmin;
880bc92fbSAndreas Gohruse dokuwiki\plugin\extension\Installer;
979ff0cd0SAndreas Gohruse dokuwiki\plugin\extension\Repository;
10d4f83172SAndreas Gohr
11788f86d9SMichael Hamann/**
12788f86d9SMichael Hamann * DokuWiki Plugin extension (Admin Component)
13788f86d9SMichael Hamann *
14788f86d9SMichael Hamann * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
1502779b18SMichael Hamann */
168553d24dSAndreas Gohrclass admin_plugin_extension extends AdminPlugin
1718b1e90aSAndreas Gohr{
18788f86d9SMichael Hamann    /**
1902779b18SMichael Hamann     * Execute the requested action(s) and initialize the plugin repository
20788f86d9SMichael Hamann     */
2118b1e90aSAndreas Gohr    public function handle()
2218b1e90aSAndreas Gohr    {
2302779b18SMichael Hamann        global $INPUT;
2480bc92fbSAndreas Gohr
2579ff0cd0SAndreas Gohr        // check access to the repository and SSL support
2679ff0cd0SAndreas Gohr        $repo = Repository::getInstance();
2779ff0cd0SAndreas Gohr        try {
2879ff0cd0SAndreas Gohr            $repo->checkAccess();
2979ff0cd0SAndreas Gohr        } catch (RepoException $e) {
3079ff0cd0SAndreas Gohr            msg($e->getMessage(), -1);
3179ff0cd0SAndreas Gohr        }
3279ff0cd0SAndreas Gohr
3379ff0cd0SAndreas Gohr        // Only continue if there is something to do
3480bc92fbSAndreas Gohr        if (!$INPUT->post->has('fn') && !$INPUT->post->str('installurl') && !isset($_FILES['installfile'])) {
3580bc92fbSAndreas Gohr            return; // nothing to do
3680bc92fbSAndreas Gohr        }
3780bc92fbSAndreas Gohr        if (!checkSecurityToken()) return;
3880bc92fbSAndreas Gohr
3979ff0cd0SAndreas Gohr        // Run actions on the installer
4080bc92fbSAndreas Gohr        $installer = new Installer($INPUT->post->bool('overwrite'));
4180bc92fbSAndreas Gohr        try {
4280bc92fbSAndreas Gohr            foreach ($INPUT->post->arr('fn') as $action => $extensions) {
4380bc92fbSAndreas Gohr                foreach ($extensions as $extension => $label) {
4480bc92fbSAndreas Gohr                    $ext = Extension::createFromId($extension);
4580bc92fbSAndreas Gohr                    switch ($action) {
4680bc92fbSAndreas Gohr                        case 'install':
4780bc92fbSAndreas Gohr                        case 'reinstall':
4880bc92fbSAndreas Gohr                        case 'update':
4980bc92fbSAndreas Gohr                            $installer->installExtension($ext);
5080bc92fbSAndreas Gohr                            break;
5180bc92fbSAndreas Gohr                        case 'uninstall':
5280bc92fbSAndreas Gohr                            $installer->uninstall($ext);
5380bc92fbSAndreas Gohr                            break;
5480bc92fbSAndreas Gohr                        case 'enable':
5580bc92fbSAndreas Gohr                            $ext->enable();
5680bc92fbSAndreas Gohr                            break;
5780bc92fbSAndreas Gohr                        case 'disable':
5880bc92fbSAndreas Gohr                            $ext->disable();
5980bc92fbSAndreas Gohr                            break;
6080bc92fbSAndreas Gohr                    }
6180bc92fbSAndreas Gohr                }
6280bc92fbSAndreas Gohr            }
6380bc92fbSAndreas Gohr            if ($INPUT->post->str('installurl')) {
6480bc92fbSAndreas Gohr                $installer->installFromURL($INPUT->post->str('installurl'));
65*9b006b5fSAndreas Gohr            } elseif (isset($_FILES['installfile']) && $_FILES['installfile']['error'] !== UPLOAD_ERR_NO_FILE) {
6680bc92fbSAndreas Gohr                $installer->installFromUpload('installfile');
6780bc92fbSAndreas Gohr            }
6880bc92fbSAndreas Gohr        } catch (Exception $e) {
6980bc92fbSAndreas Gohr            msg(hsc($e->getMessage()), -1);
7080bc92fbSAndreas Gohr        }
7180bc92fbSAndreas Gohr
7279ff0cd0SAndreas Gohr        // Report results of the installer
7380bc92fbSAndreas Gohr        $processed = $installer->getProcessed();
7480bc92fbSAndreas Gohr        foreach ($processed as $id => $status) {
7580bc92fbSAndreas Gohr            if ($status == Installer::STATUS_INSTALLED) {
7680bc92fbSAndreas Gohr                msg(sprintf($this->getLang('msg_install_success'), $id), 1);
7780bc92fbSAndreas Gohr            } elseif ($status == Installer::STATUS_UPDATED) {
7880bc92fbSAndreas Gohr                msg(sprintf($this->getLang('msg_update_success'), $id), 1);
7980bc92fbSAndreas Gohr            } elseif ($status == Installer::STATUS_SKIPPED) {
8080bc92fbSAndreas Gohr                msg(sprintf($this->getLang('msg_nooverwrite'), $id), 0);
8180bc92fbSAndreas Gohr            } elseif ($status == Installer::STATUS_REMOVED) {
8280bc92fbSAndreas Gohr                msg(sprintf($this->getLang('msg_delete_success'), $id), 1);
8380bc92fbSAndreas Gohr            }
8480bc92fbSAndreas Gohr        }
8580bc92fbSAndreas Gohr
86652715ccSAndreas Gohr        // Redirect to clear the POST data
87652715ccSAndreas Gohr        $gui = new Gui();
88652715ccSAndreas Gohr        send_redirect($gui->tabURL($gui->currentTab(), [], '&', true));
89788f86d9SMichael Hamann    }
90788f86d9SMichael Hamann
91788f86d9SMichael Hamann    /**
9202779b18SMichael Hamann     * Render HTML output
93788f86d9SMichael Hamann     */
9418b1e90aSAndreas Gohr    public function html()
9518b1e90aSAndreas Gohr    {
964fd6a1d7SAndreas Gohr        echo '<h1>' . $this->getLang('menu') . '</h1>';
974fd6a1d7SAndreas Gohr
98652715ccSAndreas Gohr        $gui = new GuiAdmin();
99981e70caSAndreas Gohr        echo $gui->render();
100788f86d9SMichael Hamann    }
101788f86d9SMichael Hamann}
102