You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

68 lines
1.9 KiB

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