xref: /dokuwiki/inc/Menu/Item/Edit.php (revision c2b9771a2c4f3934d170bc387b7fd0137cdb2c93)
193b8c351SAndreas Gohr<?php
293b8c351SAndreas Gohr
393b8c351SAndreas Gohrnamespace dokuwiki\Menu\Item;
493b8c351SAndreas Gohr
593b8c351SAndreas Gohrclass Edit extends AbstractItem {
693b8c351SAndreas Gohr
793b8c351SAndreas Gohr    /** @inheritdoc */
893b8c351SAndreas Gohr    public function __construct() {
993b8c351SAndreas Gohr        global $ACT;
1093b8c351SAndreas Gohr        global $INFO;
1193b8c351SAndreas Gohr        global $REV;
1293b8c351SAndreas Gohr
1393b8c351SAndreas Gohr        parent::__construct();
1493b8c351SAndreas Gohr
1593b8c351SAndreas Gohr        if($ACT == 'show' || $ACT == 'search') {
1693b8c351SAndreas Gohr            $this->method = 'post';
1793b8c351SAndreas Gohr            if($INFO['writable']) {
1893b8c351SAndreas Gohr                $this->accesskey = 'e';
1993b8c351SAndreas Gohr                if(!empty($INFO['draft'])) {
2093b8c351SAndreas Gohr                    $this->type = 'draft';
2193b8c351SAndreas Gohr                    $this->params['do'] = 'draft';
2293b8c351SAndreas Gohr                } else {
2393b8c351SAndreas Gohr                    $this->params['rev'] = $REV;
2493b8c351SAndreas Gohr                    if(!$INFO['exists']) {
2593b8c351SAndreas Gohr                        $this->type = 'create';
2693b8c351SAndreas Gohr                    }
2793b8c351SAndreas Gohr                }
2893b8c351SAndreas Gohr            } else {
2993b8c351SAndreas Gohr                if(!actionOK($this->type)) throw new \RuntimeException("action disabled: source");
3093b8c351SAndreas Gohr                $params['rev'] = $REV;
3193b8c351SAndreas Gohr                $this->type = 'source';
3293b8c351SAndreas Gohr                $this->accesskey = 'v';
3393b8c351SAndreas Gohr            }
3493b8c351SAndreas Gohr        } else {
3593b8c351SAndreas Gohr            $this->params = array('do' => '');
3693b8c351SAndreas Gohr            $this->type = 'show';
3793b8c351SAndreas Gohr            $this->accesskey = 'v';
3893b8c351SAndreas Gohr        }
3993b8c351SAndreas Gohr
4093b8c351SAndreas Gohr        $this->svg = $this->setIcon();
4193b8c351SAndreas Gohr    }
4293b8c351SAndreas Gohr
4393b8c351SAndreas Gohr    /**
4493b8c351SAndreas Gohr     * change the icon according to what type the edit button has
4593b8c351SAndreas Gohr     */
4693b8c351SAndreas Gohr    protected function setIcon() {
4793b8c351SAndreas Gohr        $icons = array(
4893b8c351SAndreas Gohr            'edit' => '01-edit_pencil.svg',
4993b8c351SAndreas Gohr            'create' => '02-create_pencil.svg',
5093b8c351SAndreas Gohr            'draft' => '03-draft_android-studio.svg',
5193b8c351SAndreas Gohr            'show' => '04-show_file-document.svg',
5293b8c351SAndreas Gohr            'source' => '05-source_file-xml.svg',
5393b8c351SAndreas Gohr        );
5493b8c351SAndreas Gohr        if(isset($icons[$this->type])) {
55*c2b9771aSAndreas Gohr            $this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type];
5693b8c351SAndreas Gohr        }
5793b8c351SAndreas Gohr    }
5893b8c351SAndreas Gohr
5993b8c351SAndreas Gohr}
60