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