3 namespace dokuwiki\Action
;
5 use dokuwiki\Action\Exception\ActionAbort
;
6 use dokuwiki\Extension\Event
;
11 * Used to redirect to the current page with the last edited section as a target if found
13 * @package dokuwiki\Action
15 class Redirect
extends AbstractAliasAction
18 * Redirect to the show action, trying to jump to the previously edited section
20 * @triggers ACTION_SHOW_REDIRECT
23 public function preProcess()
31 $opts = ['id' => $ID, 'preact' => $ACT];
32 //get section name when coming from section edit
33 if ($INPUT->has('hid')) {
34 // Use explicitly transmitted header id
35 $opts['fragment'] = $INPUT->str('hid');
36 } elseif ($PRE && preg_match('/^\s*==+([^=\n]+)/', $TEXT, $match)) {
37 // Fallback to old mechanism
38 $check = false; //Byref
39 $opts['fragment'] = sectionID($match[0], $check);
42 // execute the redirect
43 Event
::createAndTrigger('ACTION_SHOW_REDIRECT', $opts, [$this, 'redirect']);
45 // should never be reached
46 throw new ActionAbort('show');
50 * Execute the redirect
52 * Default action for ACTION_SHOW_REDIRECT
54 * @param array $opts id and fragment for the redirect and the preact
56 public function redirect($opts)
58 $go = wl($opts['id'], '', true, '&');
59 if (isset($opts['fragment'])) $go .= '#' . $opts['fragment'];