Edit.php 1.8 KB

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