Codestyle + check trustedproxies
[dokuwiki.git] / inc / Menu / Item / Edit.php
blobc063ca28afe37e80b5a3998ad6ad6bd8af650159
1 <?php
3 namespace dokuwiki\Menu\Item;
5 /**
6 * Class Edit
8 * Most complex item. Shows the edit button but mutates to show, draft and create based on
9 * current state.
11 class Edit extends AbstractItem
13 /** @inheritdoc */
14 public function __construct()
16 global $ACT;
17 global $INFO;
18 global $REV;
20 parent::__construct();
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';
35 } else {
36 if (!actionOK("source")) throw new \RuntimeException("action disabled: source");
37 $params['rev'] = $REV;
38 $this->type = 'source';
39 $this->accesskey = 'v';
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';
48 $this->setIcon();
51 /**
52 * change the icon according to what type the edit button has
54 protected function setIcon()
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'
63 if (isset($icons[$this->type])) {
64 $this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type];