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