116a367d4SAndreas Gohr<?php 216a367d4SAndreas Gohr 316a367d4SAndreas Gohrnamespace dokuwiki; 416a367d4SAndreas Gohr 50cba610bSSatoshi Saharause dokuwiki\Search\MetadataSearch; 62d85e841SAndreas Gohruse dokuwiki\Utf8\Sort; 70cba610bSSatoshi Sahara 816a367d4SAndreas Gohr/** 916a367d4SAndreas Gohr * Manage all builtin AJAX calls 1016a367d4SAndreas Gohr * 1116a367d4SAndreas Gohr * @todo The calls should be refactored out to their own proper classes 1216a367d4SAndreas Gohr * @package dokuwiki 1316a367d4SAndreas Gohr */ 149329b002SSatoshi Saharaclass Ajax 159329b002SSatoshi Sahara{ 1616a367d4SAndreas Gohr /** 1716a367d4SAndreas Gohr * Execute the given call 1816a367d4SAndreas Gohr * 1916a367d4SAndreas Gohr * @param string $call name of the ajax call 2016a367d4SAndreas Gohr */ 219329b002SSatoshi Sahara public function __construct($call) 229329b002SSatoshi Sahara { 232ed72d06SAndreas Gohr $callfn = 'call' . ucfirst($call); 2416a367d4SAndreas Gohr if (method_exists($this, $callfn)) { 2516a367d4SAndreas Gohr $this->$callfn(); 2616a367d4SAndreas Gohr } else { 27e1d9dcc8SAndreas Gohr $evt = new Extension\Event('AJAX_CALL_UNKNOWN', $call); 2816a367d4SAndreas Gohr if ($evt->advise_before()) { 2916a367d4SAndreas Gohr print "AJAX call '" . hsc($call) . "' unknown!\n"; 3016a367d4SAndreas Gohr } else { 3116a367d4SAndreas Gohr $evt->advise_after(); 3216a367d4SAndreas Gohr unset($evt); 3316a367d4SAndreas Gohr } 3416a367d4SAndreas Gohr } 3516a367d4SAndreas Gohr } 3616a367d4SAndreas Gohr 3716a367d4SAndreas Gohr /** 3816a367d4SAndreas Gohr * Searches for matching pagenames 3916a367d4SAndreas Gohr * 4016a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4116a367d4SAndreas Gohr */ 429329b002SSatoshi Sahara protected function callQsearch() 439329b002SSatoshi Sahara { 4416a367d4SAndreas Gohr global $lang; 4516a367d4SAndreas Gohr global $INPUT; 4616a367d4SAndreas Gohr 4716a367d4SAndreas Gohr $maxnumbersuggestions = 50; 4816a367d4SAndreas Gohr 4916a367d4SAndreas Gohr $query = $INPUT->post->str('q'); 5016a367d4SAndreas Gohr if (empty($query)) $query = $INPUT->get->str('q'); 5116a367d4SAndreas Gohr if (empty($query)) return; 5216a367d4SAndreas Gohr 5316a367d4SAndreas Gohr $query = urldecode($query); 54*cc3a3cdeSSatoshi Sahara $data = (new MetadataSearch)->pageLookup($query, true, useHeading('navigation')); 5516a367d4SAndreas Gohr 5616a367d4SAndreas Gohr if (!count($data)) return; 5716a367d4SAndreas Gohr 5816a367d4SAndreas Gohr print '<strong>' . $lang['quickhits'] . '</strong>'; 5916a367d4SAndreas Gohr print '<ul>'; 6016a367d4SAndreas Gohr $counter = 0; 6116a367d4SAndreas Gohr foreach ($data as $id => $title) { 6216a367d4SAndreas Gohr if (useHeading('navigation')) { 6316a367d4SAndreas Gohr $name = $title; 6416a367d4SAndreas Gohr } else { 6516a367d4SAndreas Gohr $ns = getNS($id); 6616a367d4SAndreas Gohr if ($ns) { 6716a367d4SAndreas Gohr $name = noNS($id) . ' (' . $ns . ')'; 6816a367d4SAndreas Gohr } else { 6916a367d4SAndreas Gohr $name = $id; 7016a367d4SAndreas Gohr } 7116a367d4SAndreas Gohr } 7216a367d4SAndreas Gohr echo '<li>' . html_wikilink(':' . $id, $name) . '</li>'; 7316a367d4SAndreas Gohr 7416a367d4SAndreas Gohr $counter++; 7516a367d4SAndreas Gohr if ($counter > $maxnumbersuggestions) { 7616a367d4SAndreas Gohr echo '<li>...</li>'; 7716a367d4SAndreas Gohr break; 7816a367d4SAndreas Gohr } 7916a367d4SAndreas Gohr } 8016a367d4SAndreas Gohr print '</ul>'; 8116a367d4SAndreas Gohr } 8216a367d4SAndreas Gohr 8316a367d4SAndreas Gohr /** 8416a367d4SAndreas Gohr * Support OpenSearch suggestions 8516a367d4SAndreas Gohr * 8616a367d4SAndreas Gohr * @link http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.0 8716a367d4SAndreas Gohr * @author Mike Frysinger <vapier@gentoo.org> 8816a367d4SAndreas Gohr */ 899329b002SSatoshi Sahara protected function callSuggestions() 909329b002SSatoshi Sahara { 9116a367d4SAndreas Gohr global $INPUT; 9216a367d4SAndreas Gohr 9316a367d4SAndreas Gohr $query = cleanID($INPUT->post->str('q')); 9416a367d4SAndreas Gohr if (empty($query)) $query = cleanID($INPUT->get->str('q')); 9516a367d4SAndreas Gohr if (empty($query)) return; 9616a367d4SAndreas Gohr 97*cc3a3cdeSSatoshi Sahara $data = (new MetadataSearch)->pageLookup($query); 9816a367d4SAndreas Gohr if (!count($data)) return; 9916a367d4SAndreas Gohr $data = array_keys($data); 10016a367d4SAndreas Gohr 10116a367d4SAndreas Gohr // limit results to 15 hits 10216a367d4SAndreas Gohr $data = array_slice($data, 0, 15); 10316a367d4SAndreas Gohr $data = array_map('trim', $data); 10416a367d4SAndreas Gohr $data = array_map('noNS', $data); 10516a367d4SAndreas Gohr $data = array_unique($data); 1062d85e841SAndreas Gohr Sort::sort($data); 10716a367d4SAndreas Gohr 10816a367d4SAndreas Gohr /* now construct a json */ 10916a367d4SAndreas Gohr $suggestions = array( 11016a367d4SAndreas Gohr $query, // the original query 11116a367d4SAndreas Gohr $data, // some suggestions 11216a367d4SAndreas Gohr array(), // no description 11316a367d4SAndreas Gohr array() // no urls 11416a367d4SAndreas Gohr ); 11516a367d4SAndreas Gohr 11616a367d4SAndreas Gohr header('Content-Type: application/x-suggestions+json'); 117d443762bSAndreas Gohr print json_encode($suggestions); 11816a367d4SAndreas Gohr } 11916a367d4SAndreas Gohr 12016a367d4SAndreas Gohr /** 12116a367d4SAndreas Gohr * Refresh a page lock and save draft 12216a367d4SAndreas Gohr * 12316a367d4SAndreas Gohr * Andreas Gohr <andi@splitbrain.org> 12416a367d4SAndreas Gohr */ 1252ed72d06SAndreas Gohr protected function callLock() { 12616a367d4SAndreas Gohr global $ID; 12716a367d4SAndreas Gohr global $INFO; 12816a367d4SAndreas Gohr global $INPUT; 12916a367d4SAndreas Gohr 13016a367d4SAndreas Gohr $ID = cleanID($INPUT->post->str('id')); 13116a367d4SAndreas Gohr if (empty($ID)) return; 13216a367d4SAndreas Gohr 13316a367d4SAndreas Gohr $INFO = pageinfo(); 13416a367d4SAndreas Gohr 135b16fbc3fSMichael Große $response = [ 136b16fbc3fSMichael Große 'errors' => [], 137b16fbc3fSMichael Große 'lock' => '0', 138b16fbc3fSMichael Große 'draft' => '', 139b16fbc3fSMichael Große ]; 14016a367d4SAndreas Gohr if (!$INFO['writable']) { 141b16fbc3fSMichael Große $response['errors'][] = 'Permission to write this page has been denied.'; 142b16fbc3fSMichael Große echo json_encode($response); 14316a367d4SAndreas Gohr return; 14416a367d4SAndreas Gohr } 14516a367d4SAndreas Gohr 14616a367d4SAndreas Gohr if (!checklock($ID)) { 14716a367d4SAndreas Gohr lock($ID); 148b16fbc3fSMichael Große $response['lock'] = '1'; 14916a367d4SAndreas Gohr } 15016a367d4SAndreas Gohr 1510aabe6f8SMichael Große $draft = new Draft($ID, $INFO['client']); 1520aabe6f8SMichael Große if ($draft->saveDraft()) { 153b16fbc3fSMichael Große $response['draft'] = $draft->getDraftMessage(); 154b16fbc3fSMichael Große } else { 155b16fbc3fSMichael Große $response['errors'] = array_merge($response['errors'], $draft->getErrors()); 15616a367d4SAndreas Gohr } 157b16fbc3fSMichael Große echo json_encode($response); 15816a367d4SAndreas Gohr } 15916a367d4SAndreas Gohr 16016a367d4SAndreas Gohr /** 16116a367d4SAndreas Gohr * Delete a draft 16216a367d4SAndreas Gohr * 16316a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 16416a367d4SAndreas Gohr */ 1659329b002SSatoshi Sahara protected function callDraftdel() 1669329b002SSatoshi Sahara { 16716a367d4SAndreas Gohr global $INPUT; 16816a367d4SAndreas Gohr $id = cleanID($INPUT->str('id')); 16916a367d4SAndreas Gohr if (empty($id)) return; 17016a367d4SAndreas Gohr 17116a367d4SAndreas Gohr $client = $_SERVER['REMOTE_USER']; 17216a367d4SAndreas Gohr if (!$client) $client = clientIP(true); 17316a367d4SAndreas Gohr 17416a367d4SAndreas Gohr $cname = getCacheName($client . $id, '.draft'); 17516a367d4SAndreas Gohr @unlink($cname); 17616a367d4SAndreas Gohr } 17716a367d4SAndreas Gohr 17816a367d4SAndreas Gohr /** 17916a367d4SAndreas Gohr * Return subnamespaces for the Mediamanager 18016a367d4SAndreas Gohr * 18116a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 18216a367d4SAndreas Gohr */ 1839329b002SSatoshi Sahara protected function callMedians() 1849329b002SSatoshi Sahara { 18516a367d4SAndreas Gohr global $conf; 18616a367d4SAndreas Gohr global $INPUT; 18716a367d4SAndreas Gohr 18816a367d4SAndreas Gohr // wanted namespace 18916a367d4SAndreas Gohr $ns = cleanID($INPUT->post->str('ns')); 19016a367d4SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 19116a367d4SAndreas Gohr 19216a367d4SAndreas Gohr $lvl = count(explode(':', $ns)); 19316a367d4SAndreas Gohr 19416a367d4SAndreas Gohr $data = array(); 19516a367d4SAndreas Gohr search($data, $conf['mediadir'], 'search_index', array('nofiles' => true), $dir); 19616a367d4SAndreas Gohr foreach (array_keys($data) as $item) { 19716a367d4SAndreas Gohr $data[$item]['level'] = $lvl + 1; 19816a367d4SAndreas Gohr } 19916a367d4SAndreas Gohr echo html_buildlist($data, 'idx', 'media_nstree_item', 'media_nstree_li'); 20016a367d4SAndreas Gohr } 20116a367d4SAndreas Gohr 20216a367d4SAndreas Gohr /** 20316a367d4SAndreas Gohr * Return list of files for the Mediamanager 20416a367d4SAndreas Gohr * 20516a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 20616a367d4SAndreas Gohr */ 2072ed72d06SAndreas Gohr protected function callMedialist() { 20816a367d4SAndreas Gohr global $NS; 20916a367d4SAndreas Gohr global $INPUT; 21016a367d4SAndreas Gohr 21116a367d4SAndreas Gohr $NS = cleanID($INPUT->post->str('ns')); 21216a367d4SAndreas Gohr $sort = $INPUT->post->bool('recent') ? 'date' : 'natural'; 21316a367d4SAndreas Gohr if ($INPUT->post->str('do') == 'media') { 21416a367d4SAndreas Gohr tpl_mediaFileList(); 21516a367d4SAndreas Gohr } else { 21616a367d4SAndreas Gohr tpl_mediaContent(true, $sort); 21716a367d4SAndreas Gohr } 21816a367d4SAndreas Gohr } 21916a367d4SAndreas Gohr 22016a367d4SAndreas Gohr /** 22116a367d4SAndreas Gohr * Return the content of the right column 22216a367d4SAndreas Gohr * (image details) for the Mediamanager 22316a367d4SAndreas Gohr * 22416a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 22516a367d4SAndreas Gohr */ 2262ed72d06SAndreas Gohr protected function callMediadetails() { 22716a367d4SAndreas Gohr global $IMG, $JUMPTO, $REV, $fullscreen, $INPUT; 22816a367d4SAndreas Gohr $fullscreen = true; 22916a367d4SAndreas Gohr require_once(DOKU_INC . 'lib/exe/mediamanager.php'); 23016a367d4SAndreas Gohr 23116a367d4SAndreas Gohr $image = ''; 23216a367d4SAndreas Gohr if ($INPUT->has('image')) $image = cleanID($INPUT->str('image')); 23316a367d4SAndreas Gohr if (isset($IMG)) $image = $IMG; 23416a367d4SAndreas Gohr if (isset($JUMPTO)) $image = $JUMPTO; 23516a367d4SAndreas Gohr $rev = false; 23616a367d4SAndreas Gohr if (isset($REV) && !$JUMPTO) $rev = $REV; 23716a367d4SAndreas Gohr 23816a367d4SAndreas Gohr html_msgarea(); 23916a367d4SAndreas Gohr tpl_mediaFileDetails($image, $rev); 24016a367d4SAndreas Gohr } 24116a367d4SAndreas Gohr 24216a367d4SAndreas Gohr /** 24316a367d4SAndreas Gohr * Returns image diff representation for mediamanager 24416a367d4SAndreas Gohr * 24516a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 24616a367d4SAndreas Gohr */ 2479329b002SSatoshi Sahara protected function callMediadiff() 2489329b002SSatoshi Sahara { 24916a367d4SAndreas Gohr global $NS; 25016a367d4SAndreas Gohr global $INPUT; 25116a367d4SAndreas Gohr 25216a367d4SAndreas Gohr $image = ''; 25316a367d4SAndreas Gohr if ($INPUT->has('image')) $image = cleanID($INPUT->str('image')); 25416a367d4SAndreas Gohr $NS = getNS($image); 25516a367d4SAndreas Gohr $auth = auth_quickaclcheck("$NS:*"); 25616a367d4SAndreas Gohr media_diff($image, $NS, $auth, true); 25716a367d4SAndreas Gohr } 25816a367d4SAndreas Gohr 25916a367d4SAndreas Gohr /** 26016a367d4SAndreas Gohr * Manages file uploads 26116a367d4SAndreas Gohr * 26216a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 26316a367d4SAndreas Gohr */ 2642ed72d06SAndreas Gohr protected function callMediaupload() { 26516a367d4SAndreas Gohr global $NS, $MSG, $INPUT; 26616a367d4SAndreas Gohr 26716a367d4SAndreas Gohr $id = ''; 268aac83cd4SPhy if (isset($_FILES['qqfile']['tmp_name'])) { 26916a367d4SAndreas Gohr $id = $INPUT->post->str('mediaid', $_FILES['qqfile']['name']); 27016a367d4SAndreas Gohr } elseif ($INPUT->get->has('qqfile')) { 27116a367d4SAndreas Gohr $id = $INPUT->get->str('qqfile'); 27216a367d4SAndreas Gohr } 27316a367d4SAndreas Gohr 27416a367d4SAndreas Gohr $id = cleanID($id); 27516a367d4SAndreas Gohr 27616a367d4SAndreas Gohr $NS = $INPUT->str('ns'); 27716a367d4SAndreas Gohr $ns = $NS . ':' . getNS($id); 27816a367d4SAndreas Gohr 27916a367d4SAndreas Gohr $AUTH = auth_quickaclcheck("$ns:*"); 28016a367d4SAndreas Gohr if ($AUTH >= AUTH_UPLOAD) { 28116a367d4SAndreas Gohr io_createNamespace("$ns:xxx", 'media'); 28216a367d4SAndreas Gohr } 28316a367d4SAndreas Gohr 284aac83cd4SPhy if (isset($_FILES['qqfile']['error']) && $_FILES['qqfile']['error']) unset($_FILES['qqfile']); 28516a367d4SAndreas Gohr 28616a367d4SAndreas Gohr $res = false; 28768491db9SPhy if (isset($_FILES['qqfile']['tmp_name'])) $res = media_upload($NS, $AUTH, $_FILES['qqfile']); 28816a367d4SAndreas Gohr if ($INPUT->get->has('qqfile')) $res = media_upload_xhr($NS, $AUTH); 28916a367d4SAndreas Gohr 29016a367d4SAndreas Gohr if ($res) { 29116a367d4SAndreas Gohr $result = array( 29216a367d4SAndreas Gohr 'success' => true, 29316a367d4SAndreas Gohr 'link' => media_managerURL(array('ns' => $ns, 'image' => $NS . ':' . $id), '&'), 29416a367d4SAndreas Gohr 'id' => $NS . ':' . $id, 29516a367d4SAndreas Gohr 'ns' => $NS 29616a367d4SAndreas Gohr ); 29716a367d4SAndreas Gohr } else { 29816a367d4SAndreas Gohr $error = ''; 29916a367d4SAndreas Gohr if (isset($MSG)) { 30016a367d4SAndreas Gohr foreach ($MSG as $msg) { 30116a367d4SAndreas Gohr $error .= $msg['msg']; 30216a367d4SAndreas Gohr } 30316a367d4SAndreas Gohr } 30416a367d4SAndreas Gohr $result = array( 30516a367d4SAndreas Gohr 'error' => $error, 30616a367d4SAndreas Gohr 'ns' => $NS 30716a367d4SAndreas Gohr ); 30816a367d4SAndreas Gohr } 309d443762bSAndreas Gohr 31016a367d4SAndreas Gohr header('Content-Type: application/json'); 311d443762bSAndreas Gohr echo json_encode($result); 31216a367d4SAndreas Gohr } 31316a367d4SAndreas Gohr 31416a367d4SAndreas Gohr /** 31516a367d4SAndreas Gohr * Return sub index for index view 31616a367d4SAndreas Gohr * 31716a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 31816a367d4SAndreas Gohr */ 3199329b002SSatoshi Sahara protected function callIndex() 3209329b002SSatoshi Sahara { 32116a367d4SAndreas Gohr global $conf; 32216a367d4SAndreas Gohr global $INPUT; 32316a367d4SAndreas Gohr 32416a367d4SAndreas Gohr // wanted namespace 32516a367d4SAndreas Gohr $ns = cleanID($INPUT->post->str('idx')); 32616a367d4SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 32716a367d4SAndreas Gohr 32816a367d4SAndreas Gohr $lvl = count(explode(':', $ns)); 32916a367d4SAndreas Gohr 33016a367d4SAndreas Gohr $data = array(); 33116a367d4SAndreas Gohr search($data, $conf['datadir'], 'search_index', array('ns' => $ns), $dir); 33216a367d4SAndreas Gohr foreach (array_keys($data) as $item) { 33316a367d4SAndreas Gohr $data[$item]['level'] = $lvl + 1; 33416a367d4SAndreas Gohr } 33516a367d4SAndreas Gohr echo html_buildlist($data, 'idx', 'html_list_index', 'html_li_index'); 33616a367d4SAndreas Gohr } 33716a367d4SAndreas Gohr 33816a367d4SAndreas Gohr /** 33916a367d4SAndreas Gohr * List matching namespaces and pages for the link wizard 34016a367d4SAndreas Gohr * 34116a367d4SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 34216a367d4SAndreas Gohr */ 3439329b002SSatoshi Sahara protected function callLinkwiz() 3449329b002SSatoshi Sahara { 34516a367d4SAndreas Gohr global $conf; 34616a367d4SAndreas Gohr global $lang; 34716a367d4SAndreas Gohr global $INPUT; 34816a367d4SAndreas Gohr 34916a367d4SAndreas Gohr $q = ltrim(trim($INPUT->post->str('q')), ':'); 35016a367d4SAndreas Gohr $id = noNS($q); 35116a367d4SAndreas Gohr $ns = getNS($q); 35216a367d4SAndreas Gohr 35316a367d4SAndreas Gohr $ns = cleanID($ns); 35416a367d4SAndreas Gohr $id = cleanID($id); 35516a367d4SAndreas Gohr 35616a367d4SAndreas Gohr $nsd = utf8_encodeFN(str_replace(':', '/', $ns)); 35716a367d4SAndreas Gohr 35816a367d4SAndreas Gohr $data = array(); 3595d27cd14SPhy if($q !== '' && $ns === '') { 36016a367d4SAndreas Gohr 36116a367d4SAndreas Gohr // use index to lookup matching pages 362*cc3a3cdeSSatoshi Sahara $pages = (new MetadataSearch)->pageLookup($id, true); 36316a367d4SAndreas Gohr 36416a367d4SAndreas Gohr // result contains matches in pages and namespaces 36516a367d4SAndreas Gohr // we now extract the matching namespaces to show 36616a367d4SAndreas Gohr // them seperately 36716a367d4SAndreas Gohr $dirs = array(); 36816a367d4SAndreas Gohr 36916a367d4SAndreas Gohr foreach ($pages as $pid => $title) { 37016a367d4SAndreas Gohr if (strpos(noNS($pid), $id) === false) { 37116a367d4SAndreas Gohr // match was in the namespace 37216a367d4SAndreas Gohr $dirs[getNS($pid)] = 1; // assoc array avoids dupes 37316a367d4SAndreas Gohr } else { 37416a367d4SAndreas Gohr // it is a matching page, add it to the result 37516a367d4SAndreas Gohr $data[] = array( 37616a367d4SAndreas Gohr 'id' => $pid, 37716a367d4SAndreas Gohr 'title' => $title, 37816a367d4SAndreas Gohr 'type' => 'f', 37916a367d4SAndreas Gohr ); 38016a367d4SAndreas Gohr } 38116a367d4SAndreas Gohr unset($pages[$pid]); 38216a367d4SAndreas Gohr } 38316a367d4SAndreas Gohr foreach ($dirs as $dir => $junk) { 38416a367d4SAndreas Gohr $data[] = array( 38516a367d4SAndreas Gohr 'id' => $dir, 38616a367d4SAndreas Gohr 'type' => 'd', 38716a367d4SAndreas Gohr ); 38816a367d4SAndreas Gohr } 38916a367d4SAndreas Gohr 39016a367d4SAndreas Gohr } else { 39116a367d4SAndreas Gohr 39216a367d4SAndreas Gohr $opts = array( 39316a367d4SAndreas Gohr 'depth' => 1, 39416a367d4SAndreas Gohr 'listfiles' => true, 39516a367d4SAndreas Gohr 'listdirs' => true, 39616a367d4SAndreas Gohr 'pagesonly' => true, 39716a367d4SAndreas Gohr 'firsthead' => true, 39816a367d4SAndreas Gohr 'sneakyacl' => $conf['sneaky_index'], 39916a367d4SAndreas Gohr ); 40016a367d4SAndreas Gohr if ($id) $opts['filematch'] = '^.*\/' . $id; 40116a367d4SAndreas Gohr if ($id) $opts['dirmatch'] = '^.*\/' . $id; 40216a367d4SAndreas Gohr search($data, $conf['datadir'], 'search_universal', $opts, $nsd); 40316a367d4SAndreas Gohr 40416a367d4SAndreas Gohr // add back to upper 40516a367d4SAndreas Gohr if ($ns) { 40616a367d4SAndreas Gohr array_unshift( 40716a367d4SAndreas Gohr $data, array( 40816a367d4SAndreas Gohr 'id' => getNS($ns), 40916a367d4SAndreas Gohr 'type' => 'u', 41016a367d4SAndreas Gohr ) 41116a367d4SAndreas Gohr ); 41216a367d4SAndreas Gohr } 41316a367d4SAndreas Gohr } 41416a367d4SAndreas Gohr 41516a367d4SAndreas Gohr // fixme sort results in a useful way ? 41616a367d4SAndreas Gohr 41716a367d4SAndreas Gohr if (!count($data)) { 41816a367d4SAndreas Gohr echo $lang['nothingfound']; 41916a367d4SAndreas Gohr exit; 42016a367d4SAndreas Gohr } 42116a367d4SAndreas Gohr 42216a367d4SAndreas Gohr // output the found data 42316a367d4SAndreas Gohr $even = 1; 42416a367d4SAndreas Gohr foreach ($data as $item) { 42516a367d4SAndreas Gohr $even *= -1; //zebra 42616a367d4SAndreas Gohr 42773f05217SPhy if (($item['type'] == 'd' || $item['type'] == 'u') && $item['id'] !== '') $item['id'] .= ':'; 42816a367d4SAndreas Gohr $link = wl($item['id']); 42916a367d4SAndreas Gohr 43016a367d4SAndreas Gohr echo '<div class="' . (($even > 0) ? 'even' : 'odd') . ' type_' . $item['type'] . '">'; 43116a367d4SAndreas Gohr 43216a367d4SAndreas Gohr if ($item['type'] == 'u') { 43316a367d4SAndreas Gohr $name = $lang['upperns']; 43416a367d4SAndreas Gohr } else { 43516a367d4SAndreas Gohr $name = hsc($item['id']); 43616a367d4SAndreas Gohr } 43716a367d4SAndreas Gohr 43816a367d4SAndreas Gohr echo '<a href="' . $link . '" title="' . hsc($item['id']) . '" class="wikilink1">' . $name . '</a>'; 43916a367d4SAndreas Gohr 44016a367d4SAndreas Gohr if (!blank($item['title'])) { 44116a367d4SAndreas Gohr echo '<span>' . hsc($item['title']) . '</span>'; 44216a367d4SAndreas Gohr } 44316a367d4SAndreas Gohr echo '</div>'; 44416a367d4SAndreas Gohr } 44516a367d4SAndreas Gohr 44616a367d4SAndreas Gohr } 44716a367d4SAndreas Gohr 44816a367d4SAndreas Gohr} 449