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