xref: /dokuwiki/inc/Menu/Item/Edit.php (revision d868eb89f182718a31113373a6272670bd7f8012)
1<?php
2
3namespace dokuwiki\Menu\Item;
4
5/**
6 * Class Edit
7 *
8 * Most complex item. Shows the edit button but mutates to show, draft and create based on
9 * current state.
10 */
11class Edit extends AbstractItem
12{
13
14    /** @inheritdoc */
15    public function __construct()
16    {
17        global $ACT;
18        global $INFO;
19        global $REV;
20
21        parent::__construct();
22
23        if ($ACT === 'show') {
24            $this->method = 'post';
25            if ($INFO['writable']) {
26                $this->accesskey = 'e';
27                if (!empty($INFO['draft'])) {
28                    $this->type = 'draft';
29                    $this->params['do'] = 'draft';
30                } else {
31                    $this->params['rev'] = $REV;
32                    if (!$INFO['exists']) {
33                        $this->type = 'create';
34                    }
35                }
36            } else {
37                if (!actionOK("source")) throw new \RuntimeException("action disabled: source");
38                $params['rev'] = $REV;
39                $this->type = 'source';
40                $this->accesskey = 'v';
41            }
42        } else {
43            if (auth_quickaclcheck($INFO['id']) < AUTH_READ) throw new \RuntimeException("no permission to read");
44            $this->params = ['do' => ''];
45            $this->type = 'show';
46            $this->accesskey = 'v';
47        }
48
49        $this->setIcon();
50    }
51
52    /**
53     * change the icon according to what type the edit button has
54     */
55    protected function setIcon()
56    {
57        $icons = [
58            'edit' => '01-edit_pencil.svg',
59            'create' => '02-create_pencil.svg',
60            'draft' => '03-draft_android-studio.svg',
61            'show' => '04-show_file-document.svg',
62            'source' => '05-source_file-xml.svg'
63        ];
64        if (isset($icons[$this->type])) {
65            $this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type];
66        }
67    }
68}
69