From 56dfcc12d4d4b326fc393a8271da0cf8374d3a11 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 12 Aug 2009 12:23:02 +0200 Subject: Link Wizard added Ignore-this: c15561aa909f921f7845576378851b93 This adds a new link wizard to the toolbar which helps users to find the page the want to link to. Pages can be found by a simple page name search or by browsing the existing namespaces. This is the first checkin. Some cleanup and MSIE compatibility checks remain. note: development was part of the ICKE 2.0 project see http://www.icke-projekt.de for info darcs-hash:20090812102302-6e07b-fcc564fcaf2ed6aa832918870dd0f92607748687.gz --- lib/exe/ajax.php | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) (limited to 'lib/exe/ajax.php') diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 4a30b0349..53ff3882c 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -240,5 +240,114 @@ function ajax_index(){ } } +/** + * List matching namespaces and pages for the link wizard + */ +function ajax_linkwiz(){ + global $conf; + global $lang; + require_once(DOKU_INC.'inc/html.php'); + + $q = ltrim($_POST['q'],':'); + $id = noNS($q); + $ns = getNS($q); + + $ns = cleanID($ns); + $id = cleanID($id); + + $nsd = utf8_encodeFN(str_replace(':','/',$ns)); + $idd = utf8_encodeFN(str_replace(':','/',$id)); + + $data = array(); + if($q && !$ns){ + + // use index to lookup matching pages + require_once(DOKU_INC.'inc/fulltext.php'); + require_once(DOKU_INC.'inc/parserutils.php'); + $pages = array(); + $pages = ft_pageLookup($id,false); + + // result contains matches in pages and namespaces + // we now extract the matching namespaces to show + // them seperately + $dirs = array(); + $count = count($pages); + for($i=0; $i<$count; $i++){ + if(strpos(noNS($pages[$i]),$id) === false){ + // match was in the namespace + $dirs[getNS($pages[$i])] = 1; // assoc array avoids dupes + }else{ + // it is a matching page, add it to the result + $data[] = array( + 'id' => $pages[$i], + 'title' => p_get_first_heading($pages[$i],false), + 'type' => 'f', + ); + } + unset($pages[$i]); + } + foreach($dirs as $dir => $junk){ + $data[] = array( + 'id' => $dir, + 'type' => 'd', + ); + } + + }else{ + + require_once(DOKU_INC.'inc/search.php'); + $opts = array( + 'depth' => 1, + 'listfiles' => true, + 'listdirs' => true, + 'pagesonly' => true, + 'firsthead' => true, + ); + if($id) $opts['filematch'] = '^.*\/'.$id; + if($id) $opts['dirmatch'] = '^.*\/'.$id; + search($data,$conf['datadir'],'search_universal',$opts,$nsd); + + // add back to upper + if($ns){ + array_unshift($data,array( + 'id' => getNS($ns), + 'type' => 'u', + )); + } + } + + // fixme sort results in a useful way ? + + if(!count($data)){ + echo $lang['nothingfound']; + exit; + } + + // output the found data + $even = 1; + foreach($data as $item){ + $even *= -1; //zebra + + if(($item['type'] == 'd' || $item['type'] == 'u') && $item['id']) $item['id'] .= ':'; + $link = wl($item['id']); + + echo '
'; + + + if($item['type'] == 'u'){ + $name = 'back to upper'; + }else{ + $name = htmlspecialchars($item['id']); + } + + echo ''.$name.''; + + if($item['title']){ + echo ''.htmlspecialchars($item['title']).''; + } + echo '
'; + } + +} + //Setup VIM: ex: et ts=2 enc=utf-8 : -?> -- cgit v1.2.3