116a367d4SAndreas Gohr<?php 216a367d4SAndreas Gohr 316a367d4SAndreas Gohrnamespace dokuwiki; 416a367d4SAndreas Gohr 5*24870174SAndreas Gohruse dokuwiki\Extension\Event; 6*24870174SAndreas Gohruse dokuwiki\Ui\MediaDiff; 7*24870174SAndreas Gohruse dokuwiki\Ui\Index; 89c8632b4SSatoshi Saharause dokuwiki\Ui; 92d85e841SAndreas Gohruse dokuwiki\Utf8\Sort; 109c8632b4SSatoshi Sahara 1116a367d4SAndreas Gohr/** 1216a367d4SAndreas Gohr * Manage all builtin AJAX calls 1316a367d4SAndreas Gohr * 1416a367d4SAndreas Gohr * @todo The calls should be refactored out to their own proper classes 1516a367d4SAndreas Gohr * @package dokuwiki 1616a367d4SAndreas Gohr */ 1716a367d4SAndreas Gohrclass Ajax { 1816a367d4SAndreas Gohr 1916a367d4SAndreas Gohr /** 2016a367d4SAndreas Gohr * Execute the given call 2116a367d4SAndreas Gohr * 2216a367d4SAndreas Gohr * @param string $call name of the ajax call 2316a367d4SAndreas Gohr */ 2416a367d4SAndreas Gohr public function __construct($call) { 252ed72d06SAndreas Gohr $callfn = 'call' . ucfirst($call); 2616a367d4SAndreas Gohr if(method_exists($this, $callfn)) { 2716a367d4SAndreas Gohr $this->$callfn(); 2816a367d4SAndreas Gohr } else { 29*24870174SAndreas Gohr $evt = new Event('AJAX_CALL_UNKNOWN', $call); 3016a367d4SAndreas Gohr if($evt->advise_before()) { 3116a367d4SAndreas Gohr print "AJAX call '" . hsc($call) . "' unknown!\n"; 3216a367d4SAndreas Gohr } else { 3316a367d4SAndreas Gohr $evt->advise_after(); 3416a367d4SAndreas Gohr unset($evt); 3516a367d4SAndreas Gohr } 3616a367d4SAndreas Gohr } 3716a367d4SAndreas Gohr } 3816a367d4SAndreas Gohr 3916a367d4SAndreas Gohr /** 4016a367d4SAndreas Gohr * Searches for matching pagenames 4116a367d4SAndreas Gohr * 4216a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4316a367d4SAndreas Gohr */ 442ed72d06SAndreas Gohr protected function callQsearch() { 4516a367d4SAndreas Gohr global $lang; 4616a367d4SAndreas Gohr global $INPUT; 4716a367d4SAndreas Gohr 4816a367d4SAndreas Gohr $maxnumbersuggestions = 50; 4916a367d4SAndreas Gohr 5016a367d4SAndreas Gohr $query = $INPUT->post->str('q'); 5116a367d4SAndreas Gohr if(empty($query)) $query = $INPUT->get->str('q'); 5216a367d4SAndreas Gohr if(empty($query)) return; 5316a367d4SAndreas Gohr 5416a367d4SAndreas Gohr $query = urldecode($query); 5516a367d4SAndreas Gohr 5616a367d4SAndreas Gohr $data = ft_pageLookup($query, true, useHeading('navigation')); 5716a367d4SAndreas Gohr 58*24870174SAndreas Gohr if($data === []) return; 5916a367d4SAndreas Gohr 6016a367d4SAndreas Gohr print '<strong>' . $lang['quickhits'] . '</strong>'; 6116a367d4SAndreas Gohr print '<ul>'; 6216a367d4SAndreas Gohr $counter = 0; 6316a367d4SAndreas Gohr foreach($data as $id => $title) { 6416a367d4SAndreas Gohr if(useHeading('navigation')) { 6516a367d4SAndreas Gohr $name = $title; 6616a367d4SAndreas Gohr } else { 6716a367d4SAndreas Gohr $ns = getNS($id); 6816a367d4SAndreas Gohr if($ns) { 6916a367d4SAndreas Gohr $name = noNS($id) . ' (' . $ns . ')'; 7016a367d4SAndreas Gohr } else { 7116a367d4SAndreas Gohr $name = $id; 7216a367d4SAndreas Gohr } 7316a367d4SAndreas Gohr } 7416a367d4SAndreas Gohr echo '<li>' . html_wikilink(':' . $id, $name) . '</li>'; 7516a367d4SAndreas Gohr 7616a367d4SAndreas Gohr $counter++; 7716a367d4SAndreas Gohr if($counter > $maxnumbersuggestions) { 7816a367d4SAndreas Gohr echo '<li>...</li>'; 7916a367d4SAndreas Gohr break; 8016a367d4SAndreas Gohr } 8116a367d4SAndreas Gohr } 8216a367d4SAndreas Gohr print '</ul>'; 8316a367d4SAndreas Gohr } 8416a367d4SAndreas Gohr 8516a367d4SAndreas Gohr /** 8616a367d4SAndreas Gohr * Support OpenSearch suggestions 8716a367d4SAndreas Gohr * 8816a367d4SAndreas Gohr * @link http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.0 8916a367d4SAndreas Gohr * @author Mike Frysinger <vapier@gentoo.org> 9016a367d4SAndreas Gohr */ 912ed72d06SAndreas Gohr protected function callSuggestions() { 9216a367d4SAndreas Gohr global $INPUT; 9316a367d4SAndreas Gohr 9416a367d4SAndreas Gohr $query = cleanID($INPUT->post->str('q')); 9516a367d4SAndreas Gohr if(empty($query)) $query = cleanID($INPUT->get->str('q')); 9616a367d4SAndreas Gohr if(empty($query)) return; 9716a367d4SAndreas Gohr 9816a367d4SAndreas Gohr $data = ft_pageLookup($query); 99*24870174SAndreas Gohr if($data === []) return; 10016a367d4SAndreas Gohr $data = array_keys($data); 10116a367d4SAndreas Gohr 10216a367d4SAndreas Gohr // limit results to 15 hits 10316a367d4SAndreas Gohr $data = array_slice($data, 0, 15); 10416a367d4SAndreas Gohr $data = array_map('trim', $data); 10516a367d4SAndreas Gohr $data = array_map('noNS', $data); 10616a367d4SAndreas Gohr $data = array_unique($data); 1072d85e841SAndreas Gohr Sort::sort($data); 10816a367d4SAndreas Gohr 10916a367d4SAndreas Gohr /* now construct a json */ 110*24870174SAndreas Gohr $suggestions = [ 11116a367d4SAndreas Gohr $query, // the original query 11216a367d4SAndreas Gohr $data, // some suggestions 113*24870174SAndreas Gohr [], // no description 114*24870174SAndreas Gohr [], // no urls 115*24870174SAndreas Gohr ]; 11616a367d4SAndreas Gohr 11716a367d4SAndreas Gohr header('Content-Type: application/x-suggestions+json'); 118*24870174SAndreas Gohr print json_encode($suggestions, JSON_THROW_ON_ERROR); 11916a367d4SAndreas Gohr } 12016a367d4SAndreas Gohr 12116a367d4SAndreas Gohr /** 12216a367d4SAndreas Gohr * Refresh a page lock and save draft 12316a367d4SAndreas Gohr * 12416a367d4SAndreas Gohr * Andreas Gohr <andi@splitbrain.org> 12516a367d4SAndreas Gohr */ 1262ed72d06SAndreas Gohr protected function callLock() { 12716a367d4SAndreas Gohr global $ID; 12816a367d4SAndreas Gohr global $INFO; 12916a367d4SAndreas Gohr global $INPUT; 13016a367d4SAndreas Gohr 13116a367d4SAndreas Gohr $ID = cleanID($INPUT->post->str('id')); 13216a367d4SAndreas Gohr if(empty($ID)) return; 13316a367d4SAndreas Gohr 13416a367d4SAndreas Gohr $INFO = pageinfo(); 13516a367d4SAndreas Gohr 136b16fbc3fSMichael Große $response = [ 137b16fbc3fSMichael Große 'errors' => [], 138b16fbc3fSMichael Große 'lock' => '0', 139b16fbc3fSMichael Große 'draft' => '', 140b16fbc3fSMichael Große ]; 14116a367d4SAndreas Gohr if(!$INFO['writable']) { 142b16fbc3fSMichael Große $response['errors'][] = 'Permission to write this page has been denied.'; 143b16fbc3fSMichael Große echo json_encode($response); 14416a367d4SAndreas Gohr return; 14516a367d4SAndreas Gohr } 14616a367d4SAndreas Gohr 14716a367d4SAndreas Gohr if(!checklock($ID)) { 14816a367d4SAndreas Gohr lock($ID); 149b16fbc3fSMichael Große $response['lock'] = '1'; 15016a367d4SAndreas Gohr } 15116a367d4SAndreas Gohr 1520aabe6f8SMichael Große $draft = new Draft($ID, $INFO['client']); 1530aabe6f8SMichael Große if ($draft->saveDraft()) { 154b16fbc3fSMichael Große $response['draft'] = $draft->getDraftMessage(); 155b16fbc3fSMichael Große } else { 156b16fbc3fSMichael Große $response['errors'] = array_merge($response['errors'], $draft->getErrors()); 15716a367d4SAndreas Gohr } 158*24870174SAndreas Gohr echo json_encode($response, JSON_THROW_ON_ERROR); 15916a367d4SAndreas Gohr } 16016a367d4SAndreas Gohr 16116a367d4SAndreas Gohr /** 16216a367d4SAndreas Gohr * Delete a draft 16316a367d4SAndreas Gohr * 16416a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 16516a367d4SAndreas Gohr */ 1662ed72d06SAndreas Gohr protected function callDraftdel() { 16716a367d4SAndreas Gohr global $INPUT; 16816a367d4SAndreas Gohr $id = cleanID($INPUT->str('id')); 16916a367d4SAndreas Gohr if(empty($id)) return; 17016a367d4SAndreas Gohr 1712b9be456SAndreas Gohr $client = $INPUT->server->str('REMOTE_USER'); 17216a367d4SAndreas Gohr if(!$client) $client = clientIP(true); 17316a367d4SAndreas Gohr 17424201594SAndreas Gohr $draft = new Draft($id, $client); 17524201594SAndreas Gohr if ($draft->isDraftAvailable() && checkSecurityToken()) { 17624201594SAndreas Gohr $draft->deleteDraft(); 17724201594SAndreas Gohr } 17816a367d4SAndreas Gohr } 17916a367d4SAndreas Gohr 18016a367d4SAndreas Gohr /** 18116a367d4SAndreas Gohr * Return subnamespaces for the Mediamanager 18216a367d4SAndreas Gohr * 18316a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 18416a367d4SAndreas Gohr */ 1852ed72d06SAndreas Gohr protected function callMedians() { 18616a367d4SAndreas Gohr global $conf; 18716a367d4SAndreas Gohr global $INPUT; 18816a367d4SAndreas Gohr 18916a367d4SAndreas Gohr // wanted namespace 19016a367d4SAndreas Gohr $ns = cleanID($INPUT->post->str('ns')); 19116a367d4SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 19216a367d4SAndreas Gohr 19316a367d4SAndreas Gohr $lvl = count(explode(':', $ns)); 19416a367d4SAndreas Gohr 195*24870174SAndreas Gohr $data = []; 196*24870174SAndreas Gohr search($data, $conf['mediadir'], 'search_index', ['nofiles' => true], $dir); 19716a367d4SAndreas Gohr foreach(array_keys($data) as $item) { 19816a367d4SAndreas Gohr $data[$item]['level'] = $lvl + 1; 19916a367d4SAndreas Gohr } 20016a367d4SAndreas Gohr echo html_buildlist($data, 'idx', 'media_nstree_item', 'media_nstree_li'); 20116a367d4SAndreas Gohr } 20216a367d4SAndreas Gohr 20316a367d4SAndreas Gohr /** 20416a367d4SAndreas Gohr * Return list of files for the Mediamanager 20516a367d4SAndreas Gohr * 20616a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 20716a367d4SAndreas Gohr */ 2082ed72d06SAndreas Gohr protected function callMedialist() { 20916a367d4SAndreas Gohr global $NS; 21016a367d4SAndreas Gohr global $INPUT; 21116a367d4SAndreas Gohr 21216a367d4SAndreas Gohr $NS = cleanID($INPUT->post->str('ns')); 21316a367d4SAndreas Gohr $sort = $INPUT->post->bool('recent') ? 'date' : 'natural'; 21416a367d4SAndreas Gohr if($INPUT->post->str('do') == 'media') { 21516a367d4SAndreas Gohr tpl_mediaFileList(); 21616a367d4SAndreas Gohr } else { 21716a367d4SAndreas Gohr tpl_mediaContent(true, $sort); 21816a367d4SAndreas Gohr } 21916a367d4SAndreas Gohr } 22016a367d4SAndreas Gohr 22116a367d4SAndreas Gohr /** 22216a367d4SAndreas Gohr * Return the content of the right column 22316a367d4SAndreas Gohr * (image details) for the Mediamanager 22416a367d4SAndreas Gohr * 22516a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 22616a367d4SAndreas Gohr */ 2272ed72d06SAndreas Gohr protected function callMediadetails() { 22816a367d4SAndreas Gohr global $IMG, $JUMPTO, $REV, $fullscreen, $INPUT; 22916a367d4SAndreas Gohr $fullscreen = true; 23016a367d4SAndreas Gohr require_once(DOKU_INC . 'lib/exe/mediamanager.php'); 23116a367d4SAndreas Gohr 23216a367d4SAndreas Gohr $image = ''; 23316a367d4SAndreas Gohr if($INPUT->has('image')) $image = cleanID($INPUT->str('image')); 23416a367d4SAndreas Gohr if(isset($IMG)) $image = $IMG; 23516a367d4SAndreas Gohr if(isset($JUMPTO)) $image = $JUMPTO; 23616a367d4SAndreas Gohr $rev = false; 23716a367d4SAndreas Gohr if(isset($REV) && !$JUMPTO) $rev = $REV; 23816a367d4SAndreas Gohr 23916a367d4SAndreas Gohr html_msgarea(); 24016a367d4SAndreas Gohr tpl_mediaFileDetails($image, $rev); 24116a367d4SAndreas Gohr } 24216a367d4SAndreas Gohr 24316a367d4SAndreas Gohr /** 24416a367d4SAndreas Gohr * Returns image diff representation for mediamanager 24516a367d4SAndreas Gohr * 24616a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 24716a367d4SAndreas Gohr */ 2482ed72d06SAndreas Gohr protected function callMediadiff() { 24916a367d4SAndreas Gohr global $INPUT; 25016a367d4SAndreas Gohr 25116a367d4SAndreas Gohr $image = ''; 25216a367d4SAndreas Gohr if($INPUT->has('image')) $image = cleanID($INPUT->str('image')); 253*24870174SAndreas Gohr (new MediaDiff($image))->preference('fromAjax', true)->show(); 25416a367d4SAndreas Gohr } 25516a367d4SAndreas Gohr 25616a367d4SAndreas Gohr /** 25716a367d4SAndreas Gohr * Manages file uploads 25816a367d4SAndreas Gohr * 25916a367d4SAndreas Gohr * @author Kate Arzamastseva <pshns@ukr.net> 26016a367d4SAndreas Gohr */ 2612ed72d06SAndreas Gohr protected function callMediaupload() { 26216a367d4SAndreas Gohr global $NS, $MSG, $INPUT; 26316a367d4SAndreas Gohr 26416a367d4SAndreas Gohr $id = ''; 265aac83cd4SPhy if(isset($_FILES['qqfile']['tmp_name'])) { 26616a367d4SAndreas Gohr $id = $INPUT->post->str('mediaid', $_FILES['qqfile']['name']); 26716a367d4SAndreas Gohr } elseif($INPUT->get->has('qqfile')) { 26816a367d4SAndreas Gohr $id = $INPUT->get->str('qqfile'); 26916a367d4SAndreas Gohr } 27016a367d4SAndreas Gohr 27116a367d4SAndreas Gohr $id = cleanID($id); 27216a367d4SAndreas Gohr 27316a367d4SAndreas Gohr $NS = $INPUT->str('ns'); 27416a367d4SAndreas Gohr $ns = $NS . ':' . getNS($id); 27516a367d4SAndreas Gohr 27616a367d4SAndreas Gohr $AUTH = auth_quickaclcheck("$ns:*"); 27716a367d4SAndreas Gohr if($AUTH >= AUTH_UPLOAD) { 27816a367d4SAndreas Gohr io_createNamespace("$ns:xxx", 'media'); 27916a367d4SAndreas Gohr } 28016a367d4SAndreas Gohr 281aac83cd4SPhy if(isset($_FILES['qqfile']['error']) && $_FILES['qqfile']['error']) unset($_FILES['qqfile']); 28216a367d4SAndreas Gohr 28316a367d4SAndreas Gohr $res = false; 28468491db9SPhy if(isset($_FILES['qqfile']['tmp_name'])) $res = media_upload($NS, $AUTH, $_FILES['qqfile']); 28516a367d4SAndreas Gohr if($INPUT->get->has('qqfile')) $res = media_upload_xhr($NS, $AUTH); 28616a367d4SAndreas Gohr 28716a367d4SAndreas Gohr if($res) { 288*24870174SAndreas Gohr $result = [ 28916a367d4SAndreas Gohr 'success' => true, 290*24870174SAndreas Gohr 'link' => media_managerURL(['ns' => $ns, 'image' => $NS . ':' . $id], '&'), 29116a367d4SAndreas Gohr 'id' => $NS . ':' . $id, 29216a367d4SAndreas Gohr 'ns' => $NS 293*24870174SAndreas Gohr ]; 29416a367d4SAndreas Gohr } else { 29516a367d4SAndreas Gohr $error = ''; 29616a367d4SAndreas Gohr if(isset($MSG)) { 29716a367d4SAndreas Gohr foreach($MSG as $msg) { 29816a367d4SAndreas Gohr $error .= $msg['msg']; 29916a367d4SAndreas Gohr } 30016a367d4SAndreas Gohr } 301*24870174SAndreas Gohr $result = ['error' => $error, 'ns' => $NS]; 30216a367d4SAndreas Gohr } 303d443762bSAndreas Gohr 30416a367d4SAndreas Gohr header('Content-Type: application/json'); 305*24870174SAndreas Gohr echo json_encode($result, JSON_THROW_ON_ERROR); 30616a367d4SAndreas Gohr } 30716a367d4SAndreas Gohr 30816a367d4SAndreas Gohr /** 30916a367d4SAndreas Gohr * Return sub index for index view 31016a367d4SAndreas Gohr * 31116a367d4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 31216a367d4SAndreas Gohr */ 3132ed72d06SAndreas Gohr protected function callIndex() { 31416a367d4SAndreas Gohr global $conf; 31516a367d4SAndreas Gohr global $INPUT; 31616a367d4SAndreas Gohr 31716a367d4SAndreas Gohr // wanted namespace 31816a367d4SAndreas Gohr $ns = cleanID($INPUT->post->str('idx')); 31916a367d4SAndreas Gohr $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 32016a367d4SAndreas Gohr 32116a367d4SAndreas Gohr $lvl = count(explode(':', $ns)); 32216a367d4SAndreas Gohr 323*24870174SAndreas Gohr $data = []; 324*24870174SAndreas Gohr search($data, $conf['datadir'], 'search_index', ['ns' => $ns], $dir); 32516a367d4SAndreas Gohr foreach (array_keys($data) as $item) { 32616a367d4SAndreas Gohr $data[$item]['level'] = $lvl + 1; 32716a367d4SAndreas Gohr } 328*24870174SAndreas Gohr $idx = new Index; 329d11e205cSSatoshi Sahara echo html_buildlist($data, 'idx', [$idx,'formatListItem'], [$idx,'tagListItem']); 33016a367d4SAndreas Gohr } 33116a367d4SAndreas Gohr 33216a367d4SAndreas Gohr /** 33316a367d4SAndreas Gohr * List matching namespaces and pages for the link wizard 33416a367d4SAndreas Gohr * 33516a367d4SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 33616a367d4SAndreas Gohr */ 3372ed72d06SAndreas Gohr protected function callLinkwiz() { 33816a367d4SAndreas Gohr global $conf; 33916a367d4SAndreas Gohr global $lang; 34016a367d4SAndreas Gohr global $INPUT; 34116a367d4SAndreas Gohr 34216a367d4SAndreas Gohr $q = ltrim(trim($INPUT->post->str('q')), ':'); 34316a367d4SAndreas Gohr $id = noNS($q); 34416a367d4SAndreas Gohr $ns = getNS($q); 34516a367d4SAndreas Gohr 34616a367d4SAndreas Gohr $ns = cleanID($ns); 347*24870174SAndreas Gohr 34816a367d4SAndreas Gohr $id = cleanID($id); 34916a367d4SAndreas Gohr 35016a367d4SAndreas Gohr $nsd = utf8_encodeFN(str_replace(':', '/', $ns)); 35116a367d4SAndreas Gohr 352*24870174SAndreas Gohr $data = []; 3535d27cd14SPhy if($q !== '' && $ns === '') { 35416a367d4SAndreas Gohr 35516a367d4SAndreas Gohr // use index to lookup matching pages 35616a367d4SAndreas Gohr $pages = ft_pageLookup($id, true); 35716a367d4SAndreas Gohr 3582aa917afSalexdraconian // If 'useheading' option is 'always' or 'content', 3592aa917afSalexdraconian // search page titles with original query as well. 360fd260edfSalexdraconian if ($conf['useheading'] == '1' || $conf['useheading'] == 'content') { 3612aa917afSalexdraconian $pages = array_merge($pages, ft_pageLookup($q, true, true)); 3622aa917afSalexdraconian asort($pages, SORT_STRING); 3634668fa19Salexdraconian } 36416a367d4SAndreas Gohr 36516a367d4SAndreas Gohr // result contains matches in pages and namespaces 36616a367d4SAndreas Gohr // we now extract the matching namespaces to show 36716a367d4SAndreas Gohr // them seperately 368*24870174SAndreas Gohr $dirs = []; 36916a367d4SAndreas Gohr 37016a367d4SAndreas Gohr foreach($pages as $pid => $title) { 3713c4b22e8Salexdraconian if(strpos(getNS($pid), $id) !== false) { 37216a367d4SAndreas Gohr // match was in the namespace 37316a367d4SAndreas Gohr $dirs[getNS($pid)] = 1; // assoc array avoids dupes 37416a367d4SAndreas Gohr } else { 37516a367d4SAndreas Gohr // it is a matching page, add it to the result 376*24870174SAndreas Gohr $data[] = ['id' => $pid, 'title' => $title, 'type' => 'f']; 37716a367d4SAndreas Gohr } 37816a367d4SAndreas Gohr unset($pages[$pid]); 37916a367d4SAndreas Gohr } 380*24870174SAndreas Gohr foreach(array_keys($dirs) as $dir) { 381*24870174SAndreas Gohr $data[] = ['id' => $dir, 'type' => 'd']; 38216a367d4SAndreas Gohr } 38316a367d4SAndreas Gohr 38416a367d4SAndreas Gohr } else { 38516a367d4SAndreas Gohr 386*24870174SAndreas Gohr $opts = [ 38716a367d4SAndreas Gohr 'depth' => 1, 38816a367d4SAndreas Gohr 'listfiles' => true, 38916a367d4SAndreas Gohr 'listdirs' => true, 39016a367d4SAndreas Gohr 'pagesonly' => true, 39116a367d4SAndreas Gohr 'firsthead' => true, 392*24870174SAndreas Gohr 'sneakyacl' => $conf['sneaky_index'] 393*24870174SAndreas Gohr ]; 39416a367d4SAndreas Gohr if($id) $opts['filematch'] = '^.*\/' . $id; 39516a367d4SAndreas Gohr if($id) $opts['dirmatch'] = '^.*\/' . $id; 39616a367d4SAndreas Gohr search($data, $conf['datadir'], 'search_universal', $opts, $nsd); 39716a367d4SAndreas Gohr 39816a367d4SAndreas Gohr // add back to upper 39916a367d4SAndreas Gohr if($ns) { 40016a367d4SAndreas Gohr array_unshift( 401*24870174SAndreas Gohr $data, ['id' => getNS($ns), 'type' => 'u'] 40216a367d4SAndreas Gohr ); 40316a367d4SAndreas Gohr } 40416a367d4SAndreas Gohr } 40516a367d4SAndreas Gohr 40616a367d4SAndreas Gohr // fixme sort results in a useful way ? 40716a367d4SAndreas Gohr 40816a367d4SAndreas Gohr if(!count($data)) { 40916a367d4SAndreas Gohr echo $lang['nothingfound']; 41016a367d4SAndreas Gohr exit; 41116a367d4SAndreas Gohr } 41216a367d4SAndreas Gohr 41316a367d4SAndreas Gohr // output the found data 41416a367d4SAndreas Gohr $even = 1; 41516a367d4SAndreas Gohr foreach($data as $item) { 41616a367d4SAndreas Gohr $even *= -1; //zebra 41716a367d4SAndreas Gohr 41873f05217SPhy if(($item['type'] == 'd' || $item['type'] == 'u') && $item['id'] !== '') $item['id'] .= ':'; 41916a367d4SAndreas Gohr $link = wl($item['id']); 42016a367d4SAndreas Gohr 42116a367d4SAndreas Gohr echo '<div class="' . (($even > 0) ? 'even' : 'odd') . ' type_' . $item['type'] . '">'; 42216a367d4SAndreas Gohr 42316a367d4SAndreas Gohr if($item['type'] == 'u') { 42416a367d4SAndreas Gohr $name = $lang['upperns']; 42516a367d4SAndreas Gohr } else { 42616a367d4SAndreas Gohr $name = hsc($item['id']); 42716a367d4SAndreas Gohr } 42816a367d4SAndreas Gohr 42916a367d4SAndreas Gohr echo '<a href="' . $link . '" title="' . hsc($item['id']) . '" class="wikilink1">' . $name . '</a>'; 43016a367d4SAndreas Gohr 43116a367d4SAndreas Gohr if(!blank($item['title'])) { 43216a367d4SAndreas Gohr echo '<span>' . hsc($item['title']) . '</span>'; 43316a367d4SAndreas Gohr } 43416a367d4SAndreas Gohr echo '</div>'; 43516a367d4SAndreas Gohr } 43616a367d4SAndreas Gohr 43716a367d4SAndreas Gohr } 43816a367d4SAndreas Gohr 43916a367d4SAndreas Gohr} 440