xref: /dokuwiki/inc/Menu/Item/Edit.php (revision e44b94a4bd0679ff22e14add34b60590fe7077d3)
193b8c351SAndreas Gohr<?php
293b8c351SAndreas Gohr
393b8c351SAndreas Gohrnamespace dokuwiki\Menu\Item;
493b8c351SAndreas Gohr
5368ce258SAndreas Gohr/**
6368ce258SAndreas Gohr * Class Edit
7368ce258SAndreas Gohr *
8368ce258SAndreas Gohr * Most complex item. Shows the edit button but mutates to show, draft and create based on
9368ce258SAndreas Gohr * current state.
10368ce258SAndreas Gohr */
1133b91513SAndreas Gohrclass Edit extends AbstractItem
1233b91513SAndreas Gohr{
1393b8c351SAndreas Gohr    /** @inheritdoc */
1433b91513SAndreas Gohr    public function __construct()
1533b91513SAndreas Gohr    {
1693b8c351SAndreas Gohr        global $ACT;
1793b8c351SAndreas Gohr        global $INFO;
1893b8c351SAndreas Gohr        global $REV;
1993b8c351SAndreas Gohr
2093b8c351SAndreas Gohr        parent::__construct();
2193b8c351SAndreas Gohr
22220966d3SMichael Große        if ($ACT === 'show') {
2393b8c351SAndreas Gohr            $this->method = 'post';
2493b8c351SAndreas Gohr            if ($INFO['writable']) {
2593b8c351SAndreas Gohr                $this->accesskey = 'e';
2693b8c351SAndreas Gohr                if (!empty($INFO['draft'])) {
2793b8c351SAndreas Gohr                    $this->type = 'draft';
2893b8c351SAndreas Gohr                    $this->params['do'] = 'draft';
2993b8c351SAndreas Gohr                } else {
3093b8c351SAndreas Gohr                    $this->params['rev'] = $REV;
3193b8c351SAndreas Gohr                    if (!$INFO['exists']) {
3293b8c351SAndreas Gohr                        $this->type = 'create';
3393b8c351SAndreas Gohr                    }
3493b8c351SAndreas Gohr                }
3593b8c351SAndreas Gohr            } else {
36792cbafaSeiroca                if (!actionOK("source")) throw new \RuntimeException("action disabled: source");
3793b8c351SAndreas Gohr                $params['rev'] = $REV;
3893b8c351SAndreas Gohr                $this->type = 'source';
3993b8c351SAndreas Gohr                $this->accesskey = 'v';
4093b8c351SAndreas Gohr            }
4193b8c351SAndreas Gohr        } else {
420877de15SAndreas Gohr            if (auth_quickaclcheck($INFO['id']) < AUTH_READ) throw new \RuntimeException("no permission to read");
4333b91513SAndreas Gohr            $this->params = ['do' => ''];
4493b8c351SAndreas Gohr            $this->type = 'show';
4593b8c351SAndreas Gohr            $this->accesskey = 'v';
4693b8c351SAndreas Gohr        }
4793b8c351SAndreas Gohr
487c844e0eSAndreas Gohr        $this->setIcon();
4993b8c351SAndreas Gohr    }
5093b8c351SAndreas Gohr
5193b8c351SAndreas Gohr    /**
5293b8c351SAndreas Gohr     * change the icon according to what type the edit button has
5393b8c351SAndreas Gohr     */
5433b91513SAndreas Gohr    protected function setIcon()
5533b91513SAndreas Gohr    {
5633b91513SAndreas Gohr        $icons = [
5793b8c351SAndreas Gohr            'edit' => '01-edit_pencil.svg',
5893b8c351SAndreas Gohr            'create' => '02-create_pencil.svg',
5993b8c351SAndreas Gohr            'draft' => '03-draft_android-studio.svg',
6093b8c351SAndreas Gohr            'show' => '04-show_file-document.svg',
6133b91513SAndreas Gohr            'source' => '05-source_file-xml.svg'
6233b91513SAndreas Gohr        ];
6393b8c351SAndreas Gohr        if (isset($icons[$this->type])) {
64*e44b94a4SAndreas Gohr            $this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type];
6593b8c351SAndreas Gohr        }
6693b8c351SAndreas Gohr    }
6793b8c351SAndreas Gohr}
68