Revert.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace dokuwiki\Action;
  3. use dokuwiki\Action\Exception\ActionAbort;
  4. use dokuwiki\Action\Exception\ActionException;
  5. /**
  6. * Class Revert
  7. *
  8. * Quick revert to an old revision
  9. *
  10. * @package dokuwiki\Action
  11. */
  12. class Revert extends AbstractUserAction
  13. {
  14. /** @inheritdoc */
  15. public function minimumPermission()
  16. {
  17. return AUTH_EDIT;
  18. }
  19. /**
  20. *
  21. * @inheritdoc
  22. * @throws ActionAbort
  23. * @throws ActionException
  24. * @todo check for writability of the current page ($INFO might do it wrong and check the attic version)
  25. */
  26. public function preProcess()
  27. {
  28. if (!checkSecurityToken()) throw new ActionException();
  29. global $ID;
  30. global $REV;
  31. global $lang;
  32. // when no revision is given, delete current one
  33. // FIXME this feature is not exposed in the GUI currently
  34. $text = '';
  35. $sum = $lang['deleted'];
  36. if ($REV) {
  37. $text = rawWiki($ID, $REV);
  38. if (!$text) throw new ActionException(); //something went wrong
  39. $sum = sprintf($lang['restored'], dformat($REV));
  40. }
  41. // spam check
  42. if (checkwordblock($text)) {
  43. msg($lang['wordblock'], -1);
  44. throw new ActionException('edit');
  45. }
  46. saveWikiText($ID, $text, $sum, false);
  47. msg($sum, 1);
  48. $REV = '';
  49. // continue with draftdel -> redirect -> show
  50. throw new ActionAbort('draftdel');
  51. }
  52. }