158528803SAndreas Gohr<?php 258528803SAndreas Gohr 358528803SAndreas Gohrnamespace dokuwiki\Action; 458528803SAndreas Gohr 558528803SAndreas Gohruse dokuwiki\Action\Exception\ActionAbort; 658528803SAndreas Gohr 758528803SAndreas Gohr/** 858528803SAndreas Gohr * Class Redirect 958528803SAndreas Gohr * 1058528803SAndreas Gohr * Used to redirect to the current page with the last edited section as a target if found 1158528803SAndreas Gohr * 1258528803SAndreas Gohr * @package dokuwiki\Action 1358528803SAndreas Gohr */ 1458528803SAndreas Gohrclass Redirect extends AbstractAliasAction { 1558528803SAndreas Gohr 1658528803SAndreas Gohr /** 1758528803SAndreas Gohr * Redirect to the show action, trying to jump to the previously edited section 1858528803SAndreas Gohr * 1958528803SAndreas Gohr * @triggers ACTION_SHOW_REDIRECT 2058528803SAndreas Gohr * @throws ActionAbort 2158528803SAndreas Gohr */ 2258528803SAndreas Gohr public function preProcess() { 2358528803SAndreas Gohr global $PRE; 2458528803SAndreas Gohr global $TEXT; 2558528803SAndreas Gohr global $INPUT; 2658528803SAndreas Gohr global $ID; 2758528803SAndreas Gohr global $ACT; 2858528803SAndreas Gohr 2958528803SAndreas Gohr $opts = array( 3058528803SAndreas Gohr 'id' => $ID, 3158528803SAndreas Gohr 'preact' => $ACT 3258528803SAndreas Gohr ); 3358528803SAndreas Gohr //get section name when coming from section edit 3458528803SAndreas Gohr if($INPUT->has('hid')) { 3558528803SAndreas Gohr // Use explicitly transmitted header id 3658528803SAndreas Gohr $opts['fragment'] = $INPUT->str('hid'); 3758528803SAndreas Gohr } else if($PRE && preg_match('/^\s*==+([^=\n]+)/', $TEXT, $match)) { 3858528803SAndreas Gohr // Fallback to old mechanism 3958528803SAndreas Gohr $check = false; //Byref 4058528803SAndreas Gohr $opts['fragment'] = sectionID($match[0], $check); 4158528803SAndreas Gohr } 4258528803SAndreas Gohr 4358528803SAndreas Gohr // execute the redirect 4458528803SAndreas Gohr trigger_event('ACTION_SHOW_REDIRECT', $opts, array($this, 'redirect')); 4558528803SAndreas Gohr 4658528803SAndreas Gohr // should never be reached 47d3d3f39aSAndreas Gohr throw new ActionAbort('show'); 4858528803SAndreas Gohr } 4958528803SAndreas Gohr 5058528803SAndreas Gohr /** 5158528803SAndreas Gohr * Execute the redirect 5258528803SAndreas Gohr * 5358528803SAndreas Gohr * Default action for ACTION_SHOW_REDIRECT 5458528803SAndreas Gohr * 5558528803SAndreas Gohr * @param array $opts id and fragment for the redirect and the preact 5658528803SAndreas Gohr */ 5758528803SAndreas Gohr public function redirect($opts) { 58*e9fede20SPhy $go = wl($opts['id'], '', true, '&'); 5958528803SAndreas Gohr if(isset($opts['fragment'])) $go .= '#' . $opts['fragment']; 6058528803SAndreas Gohr 6158528803SAndreas Gohr //show it 6258528803SAndreas Gohr send_redirect($go); 6358528803SAndreas Gohr } 6458528803SAndreas Gohr} 65