193b8c351SAndreas Gohr<?php 293b8c351SAndreas Gohr 393b8c351SAndreas Gohrnamespace dokuwiki\Menu\Item; 493b8c351SAndreas Gohr 5*368ce258SAndreas Gohr/** 6*368ce258SAndreas Gohr * Class Edit 7*368ce258SAndreas Gohr * 8*368ce258SAndreas Gohr * Most complex item. Shows the edit button but mutates to show, draft and create based on 9*368ce258SAndreas Gohr * current state. 10*368ce258SAndreas Gohr */ 1193b8c351SAndreas Gohrclass Edit extends AbstractItem { 1293b8c351SAndreas Gohr 1393b8c351SAndreas Gohr /** @inheritdoc */ 1493b8c351SAndreas Gohr public function __construct() { 1593b8c351SAndreas Gohr global $ACT; 1693b8c351SAndreas Gohr global $INFO; 1793b8c351SAndreas Gohr global $REV; 1893b8c351SAndreas Gohr 1993b8c351SAndreas Gohr parent::__construct(); 2093b8c351SAndreas Gohr 2193b8c351SAndreas Gohr if($ACT == 'show' || $ACT == 'search') { 2293b8c351SAndreas Gohr $this->method = 'post'; 2393b8c351SAndreas Gohr if($INFO['writable']) { 2493b8c351SAndreas Gohr $this->accesskey = 'e'; 2593b8c351SAndreas Gohr if(!empty($INFO['draft'])) { 2693b8c351SAndreas Gohr $this->type = 'draft'; 2793b8c351SAndreas Gohr $this->params['do'] = 'draft'; 2893b8c351SAndreas Gohr } else { 2993b8c351SAndreas Gohr $this->params['rev'] = $REV; 3093b8c351SAndreas Gohr if(!$INFO['exists']) { 3193b8c351SAndreas Gohr $this->type = 'create'; 3293b8c351SAndreas Gohr } 3393b8c351SAndreas Gohr } 3493b8c351SAndreas Gohr } else { 3593b8c351SAndreas Gohr if(!actionOK($this->type)) throw new \RuntimeException("action disabled: source"); 3693b8c351SAndreas Gohr $params['rev'] = $REV; 3793b8c351SAndreas Gohr $this->type = 'source'; 3893b8c351SAndreas Gohr $this->accesskey = 'v'; 3993b8c351SAndreas Gohr } 4093b8c351SAndreas Gohr } else { 4193b8c351SAndreas Gohr $this->params = array('do' => ''); 4293b8c351SAndreas Gohr $this->type = 'show'; 4393b8c351SAndreas Gohr $this->accesskey = 'v'; 4493b8c351SAndreas Gohr } 4593b8c351SAndreas Gohr 467c844e0eSAndreas Gohr $this->setIcon(); 4793b8c351SAndreas Gohr } 4893b8c351SAndreas Gohr 4993b8c351SAndreas Gohr /** 5093b8c351SAndreas Gohr * change the icon according to what type the edit button has 5193b8c351SAndreas Gohr */ 5293b8c351SAndreas Gohr protected function setIcon() { 5393b8c351SAndreas Gohr $icons = array( 5493b8c351SAndreas Gohr 'edit' => '01-edit_pencil.svg', 5593b8c351SAndreas Gohr 'create' => '02-create_pencil.svg', 5693b8c351SAndreas Gohr 'draft' => '03-draft_android-studio.svg', 5793b8c351SAndreas Gohr 'show' => '04-show_file-document.svg', 5893b8c351SAndreas Gohr 'source' => '05-source_file-xml.svg', 5993b8c351SAndreas Gohr ); 6093b8c351SAndreas Gohr if(isset($icons[$this->type])) { 61c2b9771aSAndreas Gohr $this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type]; 6293b8c351SAndreas Gohr } 6393b8c351SAndreas Gohr } 6493b8c351SAndreas Gohr 6593b8c351SAndreas Gohr} 66