Failed Conditions
Push — interwiki-remove-golucky ( 52fcdb...768be5 )
by Henry
12:48 queued 09:48
created

admin_plugin_extension::getMenuSort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 <[email protected]>
7
 */
8
9
/**
10
 * Admin part of the extension manager
11
 */
12
class admin_plugin_extension extends DokuWiki_Admin_Plugin
13
{
14
    protected $infoFor = null;
15
    /** @var  helper_plugin_extension_gui */
16
    protected $gui;
17
18
    /**
19
     * Constructor
20
     *
21
     * loads additional helpers
22
     */
23
    public function __construct()
24
    {
25
        $this->gui = plugin_load('helper', 'extension_gui');
0 ignored issues
show
Documentation Bug introduced by
It seems like plugin_load('helper', 'extension_gui') can also be of type object<dokuwiki\Extension\PluginInterface>. However, the property $gui is declared as type object<helper_plugin_extension_gui>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
26
    }
27
28
    /**
29
     * @return int sort number in admin menu
30
     */
31
    public function getMenuSort()
32
    {
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
    {
41
        return true;
42
    }
43
44
    /**
45
     * Execute the requested action(s) and initialize the plugin repository
46
     */
47
    public function handle()
48
    {
49
        global $INPUT;
50
        // initialize the remote repository
51
        /* @var helper_plugin_extension_repository $repository */
52
        $repository = $this->loadHelper('extension_repository');
53
54
        if(!$repository->hasAccess(!$INPUT->bool('purge'))) {
55
            $url = $this->gui->tabURL('', array('purge' => 1));
56
            msg($this->getLang('repo_error').' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1);
57
        }
58
59
        if (!in_array('ssl', stream_get_transports())) {
60
            msg($this->getLang('nossl'), -1);
61
        }
62
63
        /* @var helper_plugin_extension_extension $extension */
64
        $extension = $this->loadHelper('extension_extension');
65
66
        try {
67
            if ($INPUT->post->has('fn') && checkSecurityToken()) {
68
                $actions = $INPUT->post->arr('fn');
69
                foreach ($actions as $action => $extensions) {
70
                    foreach ($extensions as $extname => $label) {
71
                        switch ($action) {
72
                            case 'install':
73
                            case 'reinstall':
74
                            case 'update':
75
                                $extension->setExtension($extname);
76
                                $installed = $extension->installOrUpdate();
77
                                foreach ($installed as $ext => $info) {
78
                                    msg(
79
                                        sprintf(
80
                                            $this->getLang('msg_' . $info['type'] . '_' . $info['action'] . '_success'),
81
                                            $info['base']
82
                                        ),
83
                                        1
84
                                    );
85
                                }
86
                                break;
87
                            case 'uninstall':
88
                                $extension->setExtension($extname);
89
                                $status = $extension->uninstall();
90
                                if ($status) {
91
                                    msg(
92
                                        sprintf(
93
                                            $this->getLang('msg_delete_success'),
94
                                            hsc($extension->getDisplayName())
95
                                        ),
96
                                        1
97
                                    );
98
                                } else {
99
                                    msg(
100
                                        sprintf(
101
                                            $this->getLang('msg_delete_failed'),
102
                                            hsc($extension->getDisplayName())
103
                                        ),
104
                                        -1
105
                                    );
106
                                }
107
                                break;
108
                            case 'enable':
109
                                $extension->setExtension($extname);
110
                                $status = $extension->enable();
111
                                if ($status !== true) {
112
                                    msg($status, -1);
113
                                } else {
114
                                    msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1);
115
                                }
116
                                break;
117
                            case 'disable':
118
                                $extension->setExtension($extname);
119
                                $status = $extension->disable();
120
                                if ($status !== true) {
121
                                    msg($status, -1);
122
                                } else {
123
                                    msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1);
124
                                }
125
                                break;
126
                        }
127
                    }
128
                }
129
                send_redirect($this->gui->tabURL('', array(), '&', true));
130
            } elseif ($INPUT->post->str('installurl') && checkSecurityToken()) {
131
                $installed = $extension->installFromURL($INPUT->post->str('installurl'));
132
                foreach ($installed as $ext => $info) {
133
                    msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1);
134
                }
135
                send_redirect($this->gui->tabURL('', array(), '&', true));
136
            } elseif (isset($_FILES['installfile']) && checkSecurityToken()) {
137
                $installed = $extension->installFromUpload('installfile');
138
                foreach ($installed as $ext => $info) {
139
                    msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1);
140
                }
141
                send_redirect($this->gui->tabURL('', array(), '&', true));
142
            }
143
        } catch (Exception $e) {
144
            msg($e->getMessage(), -1);
145
            send_redirect($this->gui->tabURL('', array(), '&', true));
146
        }
147
    }
148
149
    /**
150
     * Render HTML output
151
     */
152
    public function html()
153
    {
154
        ptln('<h1>'.$this->getLang('menu').'</h1>');
155
        ptln('<div id="extension__manager">');
156
157
        $this->gui->tabNavigation();
158
159
        switch ($this->gui->currentTab()) {
160
            case 'search':
161
                $this->gui->tabSearch();
162
                break;
163
            case 'templates':
164
                $this->gui->tabTemplates();
165
                break;
166
            case 'install':
167
                $this->gui->tabInstall();
168
                break;
169
            case 'plugins':
170
            default:
171
                $this->gui->tabPlugins();
172
        }
173
174
        ptln('</div>');
175
    }
176
}
177
178
// vim:ts=4:sw=4:et:
179