aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/plugins/extension/admin.php
blob: 4e0ab9340f1de71012058808b11f08a27206df20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php

use dokuwiki\Extension\AdminPlugin;
use dokuwiki\plugin\extension\Extension;
use dokuwiki\plugin\extension\Gui;
use dokuwiki\plugin\extension\Installer;

/**
 * DokuWiki Plugin extension (Admin Component)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Michael Hamann <michael@content-space.de>
 */

/**
 * Admin part of the extension manager
 */
class admin_plugin_extension extends AdminPlugin
{
    protected $infoFor;
    /** @var  helper_plugin_extension_gui */
    protected $gui;

    /**
     * Constructor
     *
     * loads additional helpers
     */
    public function __construct()
    {
        $this->gui = plugin_load('helper', 'extension_gui');
    }

    /**
     * @return int sort number in admin menu
     */
    public function getMenuSort()
    {
        return 0;
    }

    /**
     * @return bool true if only access for superuser, false is for superusers and moderators
     */
    public function forAdminOnly()
    {
        return true;
    }

    /**
     * Execute the requested action(s) and initialize the plugin repository
     *
     * @todo repo init and ssl check still missing
     */
    public function handle()
    {
        global $INPUT;

        if (!$INPUT->post->has('fn') && !$INPUT->post->str('installurl') && !isset($_FILES['installfile'])) {
            return; // nothing to do
        }
        if (!checkSecurityToken()) return;

        $installer = new Installer($INPUT->post->bool('overwrite'));
        try {
            foreach ($INPUT->post->arr('fn') as $action => $extensions) {
                foreach ($extensions as $extension => $label) {
                    $ext = Extension::createFromId($extension);
                    switch ($action) {
                        case 'install':
                        case 'reinstall':
                        case 'update':
                            $installer->installExtension($ext);
                            break;
                        case 'uninstall':
                            $installer->uninstall($ext);
                            break;
                        case 'enable':
                            $ext->enable();
                            break;
                        case 'disable':
                            $ext->disable();
                            break;
                    }
                }
            }
            if ($INPUT->post->str('installurl')) {
                $installer->installFromURL($INPUT->post->str('installurl'));
            }
            if (isset($_FILES['installfile'])) {
                $installer->installFromUpload('installfile');
            }
        } catch (Exception $e) {
            msg(hsc($e->getMessage()), -1);
        }

        $processed = $installer->getProcessed();
        foreach ($processed as $id => $status) {
            if ($status == Installer::STATUS_INSTALLED) {
                msg(sprintf($this->getLang('msg_install_success'), $id), 1);
            } else if ($status == Installer::STATUS_UPDATED) {
                msg(sprintf($this->getLang('msg_update_success'), $id), 1);
            } else if ($status == Installer::STATUS_SKIPPED) {
                msg(sprintf($this->getLang('msg_nooverwrite'), $id), 0);
            } else if ($status == Installer::STATUS_REMOVED) {
                msg(sprintf($this->getLang('msg_delete_success'), $id), 1);
            }
        }

        send_redirect((new Gui())->tabURL('', [], '&', true));
        return;

        // FIXME old stuff below

        // initialize the remote repository
        /* @var helper_plugin_extension_repository $repository */
        $repository = $this->loadHelper('extension_repository');

        if (!$repository->hasAccess(!$INPUT->bool('purge'))) {
            $url = $this->gui->tabURL('', ['purge' => 1], '&');
            msg($this->getLang('repo_error') .
                ' [<a href="' . $url . '" rel="noreferrer">' . $this->getLang('repo_retry') . '</a>]', -1);
        }

        if (!in_array('ssl', stream_get_transports())) {
            msg($this->getLang('nossl'), -1);
        }
    }

    /**
     * Render HTML output
     */
    public function html()
    {
        echo '<h1>' . $this->getLang('menu') . '</h1>';

        $gui = new \dokuwiki\plugin\extension\GuiAdmin();
        echo $gui->render();
    }
}

// vim:ts=4:sw=4:et: