summaryrefslogtreecommitdiff
path: root/lib/exe
diff options
context:
space:
mode:
authorAndreas Gohr <gohr@cosmocode.de>2009-08-12 12:23:02 +0200
committerAndreas Gohr <gohr@cosmocode.de>2009-08-12 12:23:02 +0200
commit56dfcc12d4d4b326fc393a8271da0cf8374d3a11 (patch)
tree54d69021fb2167f0b501e967539cfe14d141bf9f /lib/exe
parent050f4a944248d0ceb6888477ea6b1367bb1bdf47 (diff)
downloadrpg-56dfcc12d4d4b326fc393a8271da0cf8374d3a11.tar.gz
rpg-56dfcc12d4d4b326fc393a8271da0cf8374d3a11.tar.bz2
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
Diffstat (limited to 'lib/exe')
-rw-r--r--lib/exe/ajax.php111
-rw-r--r--lib/exe/js.php1
2 files changed, 111 insertions, 1 deletions
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 '<div class="'.(($even > 0)?'even':'odd').' type_'.$item['type'].'">';
+
+
+ if($item['type'] == 'u'){
+ $name = 'back to upper';
+ }else{
+ $name = htmlspecialchars($item['id']);
+ }
+
+ echo '<a href="'.$link.'" title="'.htmlspecialchars($item['id']).'" class="wikilink1">'.$name.'</a>';
+
+ if($item['title']){
+ echo '<span>'.htmlspecialchars($item['title']).'</span>';
+ }
+ echo '</div>';
+ }
+
+}
+
//Setup VIM: ex: et ts=2 enc=utf-8 :
-?>
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 96c7c6e77..9bf392e4c 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -55,6 +55,7 @@ function js_out(){
$files[] = DOKU_INC.'lib/scripts/textselection.js';
$files[] = DOKU_INC.'lib/scripts/toolbar.js';
$files[] = DOKU_INC.'lib/scripts/edit.js';
+ $files[] = DOKU_INC.'lib/scripts/linkwiz.js';
}
$files[] = DOKU_INC.'lib/scripts/media.js';
}