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