1<?php 2/** 3 * DokuWiki Plugin singlesearchresult (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Matthias Schulte <dokuwiki@lupo49.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12if(!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if(!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); 15 16require_once DOKU_PLUGIN.'action.php'; 17 18class action_plugin_singlesearchresult extends DokuWiki_Action_Plugin { 19 20 public function register(Doku_Event_Handler $controller) { 21 $controller->register_hook('SEARCH_QUERY_FULLPAGE', 'AFTER', $this, 'handle_search_query_pagelookup'); 22 } 23 24 public function handle_search_query_pagelookup(Doku_Event &$event, $param) { 25 global $conf; 26 $result = $event->result; 27 28 // Only one page found, skip result overview and open the found page 29 if(count($result) == 1) { 30 $pageid = key($result); 31 32 if($_SERVER['REMOTE_USER']) { 33 $perm = auth_quickaclcheck($pageid); 34 } else { 35 $perm = auth_aclcheck($pageid, '', null); 36 } 37 38 if($perm > AUTH_NONE) { 39 if($conf['allowdebug']) { 40 msg("Only one page found, skipping result overview. Redirect to: ".$pageid); 41 } 42 $link = wl($pageid, '', true); 43 print "<script type='text/javascript'>window.location.href='$link'</script>"; 44 } 45 } 46 } 47} 48 49// vim:ts=4:sw=4:et: 50