Codestyle + check trustedproxies
[dokuwiki.git] / inc / Action / Redirect.php
blob5a8309f4494ecd72e74ef78dbeb65cc0689b4596
1 <?php
3 namespace dokuwiki\Action;
5 use dokuwiki\Action\Exception\ActionAbort;
6 use dokuwiki\Extension\Event;
8 /**
9 * Class Redirect
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
17 /**
18 * Redirect to the show action, trying to jump to the previously edited section
20 * @triggers ACTION_SHOW_REDIRECT
21 * @throws ActionAbort
23 public function preProcess()
25 global $PRE;
26 global $TEXT;
27 global $INPUT;
28 global $ID;
29 global $ACT;
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');
49 /**
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'];
61 //show it
62 send_redirect($go);