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