xref: /dokuwiki/lib/plugins/extension/admin.php (revision 5c0b30bf48d7f8e5f3d5764cfab94d0d09c0a8b1)
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                            try {
73                                $extension->setExtension($extname);
74                                $installed = $extension->installOrUpdate();
75                                foreach($installed as $extension => $info){
76                                    msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1);
77                                }
78                            }catch (Exception $e){
79                                msg($e->getMessage(), -1);
80                            }
81                            break;
82                        case 'uninstall':
83                            $extension->setExtension($extname);
84                            $status = $extension->uninstall();
85                            if ($status !== true) {
86                                msg($status, -1);
87                            } else {
88                                msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getDisplayName())), 1);
89                            }
90                            break;
91                        case 'enable';
92                            $extension->setExtension($extname);
93                            $status = $extension->enable();
94                            if ($status !== true) {
95                                msg($status, -1);
96                            } else {
97                                msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1);
98                            }
99                            break;
100                        case 'disable';
101                            $extension->setExtension($extname);
102                            $status = $extension->disable();
103                            if ($status !== true) {
104                                msg($status, -1);
105                            } else {
106                                msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1);
107                            }
108                            break;
109                    }
110                }
111            }
112        }
113    }
114
115    /**
116     * Render HTML output
117     */
118    public function html() {
119        ptln('<h1>'.$this->getLang('menu').'</h1>');
120        ptln('<div id="extension__manager">');
121
122        $this->gui->tabNavigation();
123
124        switch($this->gui->currentTab()){
125            case 'search':
126                $this->gui->tabSearch();
127                break;
128            case 'templates':
129                $this->gui->tabTemplates();
130                break;
131            case 'install':
132                $this->gui->tabInstall();
133                break;
134            case 'plugins':
135            default:
136                $this->gui->tabPlugins();
137        }
138
139
140        ptln('</div>');
141    }
142}
143
144// vim:ts=4:sw=4:et: