Edit.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace dokuwiki\Action;
  3. use dokuwiki\Action\Exception\ActionAbort;
  4. use dokuwiki\Ui;
  5. /**
  6. * Class Edit
  7. *
  8. * Handle editing
  9. *
  10. * @package dokuwiki\Action
  11. */
  12. class Edit extends AbstractAction
  13. {
  14. /** @inheritdoc */
  15. public function minimumPermission()
  16. {
  17. global $INFO;
  18. if ($INFO['exists']) {
  19. return AUTH_READ; // we check again below
  20. } else {
  21. return AUTH_CREATE;
  22. }
  23. }
  24. /**
  25. * @inheritdoc falls back to 'source' if page not writable
  26. */
  27. public function checkPreconditions()
  28. {
  29. parent::checkPreconditions();
  30. global $INFO;
  31. // no edit permission? view source
  32. if ($INFO['exists'] && !$INFO['writable']) {
  33. throw new ActionAbort('source');
  34. }
  35. }
  36. /** @inheritdoc */
  37. public function preProcess()
  38. {
  39. global $ID;
  40. global $INFO;
  41. global $TEXT;
  42. global $RANGE;
  43. global $PRE;
  44. global $SUF;
  45. global $REV;
  46. global $SUM;
  47. global $lang;
  48. global $DATE;
  49. if (!isset($TEXT)) {
  50. if ($INFO['exists']) {
  51. if ($RANGE) {
  52. list($PRE, $TEXT, $SUF) = rawWikiSlices($RANGE, $ID, $REV);
  53. } else {
  54. $TEXT = rawWiki($ID, $REV);
  55. }
  56. } else {
  57. $TEXT = pageTemplate($ID);
  58. }
  59. }
  60. //set summary default
  61. if (!$SUM) {
  62. if ($REV) {
  63. $SUM = sprintf($lang['restored'], dformat($REV));
  64. } elseif (!$INFO['exists']) {
  65. $SUM = $lang['created'];
  66. }
  67. }
  68. // Use the date of the newest revision, not of the revision we edit
  69. // This is used for conflict detection
  70. if (!$DATE) $DATE = @filemtime(wikiFN($ID));
  71. //check if locked by anyone - if not lock for my self
  72. $lockedby = checklock($ID);
  73. if ($lockedby) {
  74. throw new ActionAbort('locked');
  75. }
  76. lock($ID);
  77. }
  78. /** @inheritdoc */
  79. public function tplContent()
  80. {
  81. (new Ui\Editor)->show();
  82. }
  83. }