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