xref: /dokuwiki/lib/plugins/extension/admin.php (revision 1dd40c86eb47f24a2e7c7022592fd9cd25ff07f2)
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        $repository->init();
52
53        if(!$repository->hasAccess()){
54            $url = $this->gui->tabURL('', array('purge'=>1));
55
56            msg('The DokuWiki extension repository can not be reached currently.
57                 Online Features are not available. [<a href="'.$url.'">retry</a>]', -1);
58        }
59
60        /* @var helper_plugin_extension_extension $extension */
61        $extension = $this->loadHelper('extension_extension');
62
63        if ($INPUT->post->has('fn')) {
64            $actions = $INPUT->post->arr('fn');
65            foreach ($actions as $action => $extensions) {
66                foreach ($extensions as $extname => $label) {
67                    switch ($action) {
68                        case 'info':
69                            $this->infoFor = $extname;
70                            break;
71                        case 'install':
72                            msg('Not implemented');
73                            break;
74                        case 'reinstall':
75                        case 'update':
76                            $extension->setExtension($extname, false);
77                            $status = $extension->installOrUpdate();
78                            if ($status !== true) {
79                                msg($status, -1);
80                            } else {
81                                msg(sprintf($this->getLang('msg_update_success'), hsc($extension->getName())), 1);
82                            }
83                            break;
84                        case 'uninstall':
85                            $extension->setExtension($extname, false);
86                            $status = $extension->uninstall();
87                            if ($status !== true) {
88                                msg($status, -1);
89                            } else {
90                                msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getName())), 1);
91                            }
92                            break;
93                        case 'enable';
94                            $extension->setExtension($extname, false);
95                            $status = $extension->enable();
96                            if ($status !== true) {
97                                msg($status, -1);
98                            } else {
99                                msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getName())), 1);
100                            }
101                            break;
102                        case 'disable';
103                            $extension->setExtension($extname, false);
104                            $status = $extension->disable();
105                            if ($status !== true) {
106                                msg($status, -1);
107                            } else {
108                                msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getName())), 1);
109                            }
110                            break;
111                    }
112                }
113            }
114        }
115    }
116
117    /**
118     * Render HTML output
119     */
120    public function html() {
121        ptln('<h1>'.$this->getLang('menu').'</h1>');
122        ptln('<div id="extension__manager">');
123
124        $this->gui->tabNavigation();
125
126        switch($this->gui->currentTab()){
127            case 'search':
128                $this->gui->tabSearch();
129                break;
130            case 'templates':
131                $this->gui->tabTemplates();
132                break;
133            case 'plugins':
134            default:
135                $this->gui->tabPlugins();
136        }
137
138
139        ptln('</div>');
140    }
141}
142
143// vim:ts=4:sw=4:et: