register_hook('SEARCH_QUERY_PAGELOOKUP', 'BEFORE', $this, 'linkWizard', array());
}
/**
* Modify the returned pages
* The {@link callLinkWiz} of inc/Ajax.php do
* just a page search with {@link ft_pageLookup()}
* https://www.dokuwiki.org/search
* @param Doku_Event $event
* @param $params
* The path are initialized in {@link init_paths}
* @return void
*/
function linkWizard(Doku_Event $event, $params)
{
global $INPUT;
$postCall = $INPUT->post->str('call');
if ($postCall !== self::CALL) {
return;
}
if (SiteConfig::getConfValue(self::CONF_ENABLE_ENHANCED_LINK_WIZARD, 1) === 0) {
return;
}
$searchTerm = $event->data["id"]; // yes id is the search term
$pages = Search::getPages($searchTerm);
/**
* Adapted from {@link Ajax::callLinkwiz()}
* because link-wizard delete the pages in the same namespace and shows the group instead
* Breaking the flow
*/
global $lang;
if (!count($pages)) {
ExecutionContext::getActualOrCreateFromEnv()
->response()
->setStatus(HttpResponseStatus::ALL_GOOD)
->setBody("
" . $lang['nothingfound'] . "
", Mime::getHtml())
->end();
return;
}
// output the found data
$even = 1;
$html = "";
$lowerSearchTerm = strtolower($searchTerm);
foreach ($pages as $page) {
try {
$id = $page->getWikiId();
} catch (ExceptionBadArgument $e) {
LogUtility::internalError("The selection should return wiki path", self::CANONICAL, $e);
continue;
}
$path = $page->getPathObject()->toAbsoluteId();
/**
* The name is the label that is put
* punt in the markup link
* We set it in lowercase then.
* Nobody want uppercase letter in their link label
*/
$name = strtolower($page->getNameOrDefault());
$title = $page->getTitleOrDefault();
$h1 = $page->getH1OrDefault();
$even *= -1; //zebra
$link = wl($id);
$evenOrOdd = (($even > 0) ? 'even' : 'odd');
$label = null;
if (strpos(strtolower($title), $lowerSearchTerm) !== false) {
$label = "Title: $title";
}
if ($label === null && strpos(strtolower($h1), $lowerSearchTerm) !== false) {
$label = "H1: $h1";
} else {
$label = "Title: $title";
}
$class = "";
if (!FileSystems::exists($page->getPathObject())) {
$errorClass = LinkMarkup::getHtmlClassNotExist();
$class = "class=\"$errorClass\"";
}
/**
* Because path is used in the title to create the link
* by {@link file linkwiz.js} we set a title on the span
*/
$html .= <<
$path$name
EOF;
}
ExecutionContext::getActualOrCreateFromEnv()
->response()
->setStatus(HttpResponseStatus::ALL_GOOD)
->setBody($html, Mime::getHtml())
->end();
}
}