summaryrefslogtreecommitdiff
path: root/lib/plugins/extension/admin.php
blob: 373f90183efaf5ae0398794c71fc953f8eae7ebd (plain)
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
<?php
/**
 * DokuWiki Plugin extension (Admin Component)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Michael Hamann <michael@content-space.de>
 */

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

/**
 * Admin part of the extension manager
 */
class admin_plugin_extension extends DokuWiki_Admin_Plugin {
    protected $infoFor = null;

    /**
     * @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
     */
    public function handle() {
        global $INPUT;
        // initialize the remote repository
        /* @var helper_plugin_extension_repository $repository */
        $repository = $this->loadHelper('extension_repository');
        $repository->init();

        /* @var helper_plugin_extension_extension $extension */
        $extension = $this->loadHelper('extension_extension');

        if ($INPUT->post->has('fn')) {
            $actions = $INPUT->post->arr('fn');
            foreach ($actions as $action => $extensions) {
                foreach ($extensions as $extname => $label) {
                    switch ($action) {
                        case 'info':
                            $this->infoFor = $extname;
                            break;
                        case 'install':
                            msg('Not implemented');
                            break;
                        case 'reinstall':
                        case 'update':
                            $extension->setExtension($extname, false);
                            $status = $extension->installOrUpdate();
                            if ($status !== true) {
                                msg($status, -1);
                            } else {
                                msg(sprintf($this->getLang('msg_update_success'), hsc($extension->getName())), 1);
                            }
                            break;
                        case 'uninstall':
                            $extension->setExtension($extname, false);
                            $status = $extension->uninstall();
                            if ($status !== true) {
                                msg($status, -1);
                            } else {
                                msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getName())), 1);
                            }
                            break;
                        case 'enable';
                            $extension->setExtension($extname, false);
                            $status = $extension->enable();
                            if ($status !== true) {
                                msg($status, -1);
                            } else {
                                msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getName())), 1);
                            }
                            break;
                        case 'disable';
                            $extension->setExtension($extname, false);
                            $status = $extension->disable();
                            if ($status !== true) {
                                msg($status, -1);
                            } else {
                                msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getName())), 1);
                            }
                            break;
                    }
                }
            }
        }
    }

    /**
     * Render HTML output
     */
    public function html() {
        /* @var Doku_Plugin_Controller $plugin_controller */
        global $plugin_controller;
        ptln('<h1>'.$this->getLang('menu').'</h1>');
        ptln('<div id="extension__manager">');

        $pluginlist = $plugin_controller->getList('', true);
        /* @var helper_plugin_extension_extension $extension */
        $extension = $this->loadHelper('extension_extension');
        /* @var helper_plugin_extension_list $list */
        $list = $this->loadHelper('extension_list');
        $list->start_form();
        foreach ($pluginlist as $name) {
            $extension->setExtension($name, false);
            $list->add_row($extension, $name == $this->infoFor);
        }
        $list->end_form();
        $list->render();
        ptln('</div>');
    }
}

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