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 { 16 global $ACT; 17 global $INFO; 18 global $REV; 19 20 parent::__construct(); 21 22 if ($ACT === 'show') { 23 $this->method = 'post'; 24 if ($INFO['writable']) { 25 $this->accesskey = 'e'; 26 if (!empty($INFO['draft'])) { 27 $this->type = 'draft'; 28 $this->params['do'] = 'draft'; 29 } else { 30 $this->params['rev'] = $REV; 31 if (!$INFO['exists']) { 32 $this->type = 'create'; 33 } 34 } 35 } else { 36 if (!actionOK("source")) throw new \RuntimeException("action disabled: source"); 37 $params['rev'] = $REV; 38 $this->type = 'source'; 39 $this->accesskey = 'v'; 40 } 41 } else { 42 if (auth_quickaclcheck($INFO['id']) < AUTH_READ) throw new \RuntimeException("no permission to read"); 43 $this->params = ['do' => '']; 44 $this->type = 'show'; 45 $this->accesskey = 'v'; 46 } 47 48 $this->setIcon(); 49 } 50 51 /** 52 * change the icon according to what type the edit button has 53 */ 54 protected function setIcon() 55 { 56 $icons = [ 57 'edit' => '01-edit_pencil.svg', 58 'create' => '02-create_pencil.svg', 59 'draft' => '03-draft_android-studio.svg', 60 'show' => '04-show_file-document.svg', 61 'source' => '05-source_file-xml.svg' 62 ]; 63 if (isset($icons[$this->type])) { 64 $this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type]; 65 } 66 } 67} 68