xref: /dokuwiki/inc/Menu/Item/Edit.php (revision 33b91513e25639a6c7eb35668484d29098f7c9b4)
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 */
11*33b91513SAndreas Gohrclass Edit extends AbstractItem
12*33b91513SAndreas Gohr{
1393b8c351SAndreas Gohr
1493b8c351SAndreas Gohr    /** @inheritdoc */
15*33b91513SAndreas Gohr    public function __construct()
16*33b91513SAndreas Gohr    {
1793b8c351SAndreas Gohr        global $ACT;
1893b8c351SAndreas Gohr        global $INFO;
1993b8c351SAndreas Gohr        global $REV;
2093b8c351SAndreas Gohr
2193b8c351SAndreas Gohr        parent::__construct();
2293b8c351SAndreas Gohr
23220966d3SMichael Große        if ($ACT === 'show') {
2493b8c351SAndreas Gohr            $this->method = 'post';
2593b8c351SAndreas Gohr            if ($INFO['writable']) {
2693b8c351SAndreas Gohr                $this->accesskey = 'e';
2793b8c351SAndreas Gohr                if (!empty($INFO['draft'])) {
2893b8c351SAndreas Gohr                    $this->type = 'draft';
2993b8c351SAndreas Gohr                    $this->params['do'] = 'draft';
3093b8c351SAndreas Gohr                } else {
3193b8c351SAndreas Gohr                    $this->params['rev'] = $REV;
3293b8c351SAndreas Gohr                    if (!$INFO['exists']) {
3393b8c351SAndreas Gohr                        $this->type = 'create';
3493b8c351SAndreas Gohr                    }
3593b8c351SAndreas Gohr                }
3693b8c351SAndreas Gohr            } else {
37792cbafaSeiroca                if (!actionOK("source")) throw new \RuntimeException("action disabled: source");
3893b8c351SAndreas Gohr                $params['rev'] = $REV;
3993b8c351SAndreas Gohr                $this->type = 'source';
4093b8c351SAndreas Gohr                $this->accesskey = 'v';
4193b8c351SAndreas Gohr            }
4293b8c351SAndreas Gohr        } else {
430877de15SAndreas Gohr            if (auth_quickaclcheck($INFO['id']) < AUTH_READ) throw new \RuntimeException("no permission to read");
44*33b91513SAndreas Gohr            $this->params = ['do' => ''];
4593b8c351SAndreas Gohr            $this->type = 'show';
4693b8c351SAndreas Gohr            $this->accesskey = 'v';
4793b8c351SAndreas Gohr        }
4893b8c351SAndreas Gohr
497c844e0eSAndreas Gohr        $this->setIcon();
5093b8c351SAndreas Gohr    }
5193b8c351SAndreas Gohr
5293b8c351SAndreas Gohr    /**
5393b8c351SAndreas Gohr     * change the icon according to what type the edit button has
5493b8c351SAndreas Gohr     */
55*33b91513SAndreas Gohr    protected function setIcon()
56*33b91513SAndreas Gohr    {
57*33b91513SAndreas Gohr        $icons = [
5893b8c351SAndreas Gohr            'edit' => '01-edit_pencil.svg',
5993b8c351SAndreas Gohr            'create' => '02-create_pencil.svg',
6093b8c351SAndreas Gohr            'draft' => '03-draft_android-studio.svg',
6193b8c351SAndreas Gohr            'show' => '04-show_file-document.svg',
62*33b91513SAndreas Gohr            'source' => '05-source_file-xml.svg'
63*33b91513SAndreas Gohr        ];
6493b8c351SAndreas Gohr        if (isset($icons[$this->type])) {
65c2b9771aSAndreas Gohr            $this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type];
6693b8c351SAndreas Gohr        }
6793b8c351SAndreas Gohr    }
6893b8c351SAndreas Gohr
6993b8c351SAndreas Gohr}
70