xref: /dokuwiki/lib/plugins/extension/admin.php (revision 519895b5625277197a88748c515919515f1113b8)
1<?php
2/**
3 * DokuWiki Plugin extension (Admin Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Hamann <michael@content-space.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12/**
13 * Admin part of the extension manager
14 */
15class admin_plugin_extension extends DokuWiki_Admin_Plugin {
16    protected $infoFor = null;
17    /** @var  helper_plugin_extension_gui */
18    protected $gui;
19
20    /**
21     * Constructor
22     *
23     * loads additional helpers
24     */
25    public function __construct(){
26        $this->gui = plugin_load('helper', 'extension_gui');
27    }
28
29    /**
30     * @return int sort number in admin menu
31     */
32    public function getMenuSort() {
33        return 0;
34    }
35
36    /**
37     * @return bool true if only access for superuser, false is for superusers and moderators
38     */
39    public function forAdminOnly() {
40        return true;
41    }
42
43    /**
44     * Execute the requested action(s) and initialize the plugin repository
45     */
46    public function handle() {
47        global $INPUT;
48        // initialize the remote repository
49        /* @var helper_plugin_extension_repository $repository */
50        $repository = $this->loadHelper('extension_repository');
51
52
53        if(!$repository->hasAccess()){
54            $url = $this->gui->tabURL('', array('purge'=>1));
55            msg($this->getLang('repo_error').' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1);
56        }
57
58        /* @var helper_plugin_extension_extension $extension */
59        $extension = $this->loadHelper('extension_extension');
60
61        if ($INPUT->post->has('fn')) {
62            $actions = $INPUT->post->arr('fn');
63            foreach ($actions as $action => $extensions) {
64                foreach ($extensions as $extname => $label) {
65                    switch ($action) {
66                        case 'info':
67                            $this->infoFor = $extname;
68                            break;
69                        case 'install':
70                        case 'reinstall':
71                        case 'update':
72                            $extension->setExtension($extname);
73                            $status = $extension->installOrUpdate();
74                            if ($status !== true) {
75                                msg($status, -1);
76                            } else {
77                                msg(sprintf($this->getLang('msg_update_success'), hsc($extension->getDisplayName())), 1);
78                            }
79                            break;
80                        case 'uninstall':
81                            $extension->setExtension($extname);
82                            $status = $extension->uninstall();
83                            if ($status !== true) {
84                                msg($status, -1);
85                            } else {
86                                msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getDisplayName())), 1);
87                            }
88                            break;
89                        case 'enable';
90                            $extension->setExtension($extname);
91                            $status = $extension->enable();
92                            if ($status !== true) {
93                                msg($status, -1);
94                            } else {
95                                msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1);
96                            }
97                            break;
98                        case 'disable';
99                            $extension->setExtension($extname);
100                            $status = $extension->disable();
101                            if ($status !== true) {
102                                msg($status, -1);
103                            } else {
104                                msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1);
105                            }
106                            break;
107                    }
108                }
109            }
110        }
111    }
112
113    /**
114     * Render HTML output
115     */
116    public function html() {
117        ptln('<h1>'.$this->getLang('menu').'</h1>');
118        ptln('<div id="extension__manager">');
119
120        $this->gui->tabNavigation();
121
122        switch($this->gui->currentTab()){
123            case 'search':
124                $this->gui->tabSearch();
125                break;
126            case 'templates':
127                $this->gui->tabTemplates();
128                break;
129            case 'install':
130                $this->gui->tabInstall();
131                break;
132            case 'plugins':
133            default:
134                $this->gui->tabPlugins();
135        }
136
137
138        ptln('</div>');
139    }
140}
141
142// vim:ts=4:sw=4:et: