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.
 
 
 
 
 

65 lines
1.6 KiB

  1. <?php
  2. namespace dokuwiki\Action;
  3. use dokuwiki\Action\Exception\ActionAbort;
  4. use dokuwiki\Extension\Event;
  5. /**
  6. * Class Redirect
  7. *
  8. * Used to redirect to the current page with the last edited section as a target if found
  9. *
  10. * @package dokuwiki\Action
  11. */
  12. class Redirect extends AbstractAliasAction
  13. {
  14. /**
  15. * Redirect to the show action, trying to jump to the previously edited section
  16. *
  17. * @triggers ACTION_SHOW_REDIRECT
  18. * @throws ActionAbort
  19. */
  20. public function preProcess()
  21. {
  22. global $PRE;
  23. global $TEXT;
  24. global $INPUT;
  25. global $ID;
  26. global $ACT;
  27. $opts = ['id' => $ID, 'preact' => $ACT];
  28. //get section name when coming from section edit
  29. if ($INPUT->has('hid')) {
  30. // Use explicitly transmitted header id
  31. $opts['fragment'] = $INPUT->str('hid');
  32. } elseif ($PRE && preg_match('/^\s*==+([^=\n]+)/', $TEXT, $match)) {
  33. // Fallback to old mechanism
  34. $check = false; //Byref
  35. $opts['fragment'] = sectionID($match[0], $check);
  36. }
  37. // execute the redirect
  38. Event::createAndTrigger('ACTION_SHOW_REDIRECT', $opts, [$this, 'redirect']);
  39. // should never be reached
  40. throw new ActionAbort('show');
  41. }
  42. /**
  43. * Execute the redirect
  44. *
  45. * Default action for ACTION_SHOW_REDIRECT
  46. *
  47. * @param array $opts id and fragment for the redirect and the preact
  48. */
  49. public function redirect($opts)
  50. {
  51. $go = wl($opts['id'], '', true, '&');
  52. if (isset($opts['fragment'])) $go .= '#' . $opts['fragment'];
  53. //show it
  54. send_redirect($go);
  55. }
  56. }