Skip to content

Commit

Permalink
feat(search): trigger event for each result
Browse files Browse the repository at this point in the history
Add events around each search result, both for the pagename results
and the fullpage results.

The fullpage results are wrapped in a div for better separation and
styling.
( see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl )

These events are intended to provide plugin authors with the ability
to hydrate the search results with more information.
  • Loading branch information
micgro42 committed Mar 21, 2018
1 parent bb8ef86 commit 4eab6f7
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions inc/Ui/Search.php
Expand Up @@ -280,19 +280,13 @@ protected function getPageLookupHTML($data)
$html .= '<h3>' . $lang['quickhits'] . ':</h3>';
$html .= '<ul class="search_quickhits">';
foreach ($data as $id => $title) {
$html .= '<li> ';
if (useHeading('navigation')) {
$name = $title;
} else {
$ns = getNS($id);
if ($ns) {
$name = shorten(noNS($id), ' (' . $ns . ')', 30);
} else {
$name = $id;
}
}
$html .= html_wikilink(':' . $id, $name);
$html .= '</li> ';
$link = html_wikilink(':' . $id);
$eventData = [
'listItemContent' => [$link],
'page' => $id,
];
trigger_event('SEARCH_RESULT_PAGELOOKUP', $eventData);
$html .= '<li>' . implode('', $eventData['listItemContent']) . '</li>';
}
$html .= '</ul> ';
//clear float (see http://www.complexspiral.com/publications/containing-floats/)
Expand Down Expand Up @@ -322,18 +316,27 @@ protected function getFulltextResultsHTML($data, $highlight)
$html .= '<dl class="search_results">';
$num = 1;
foreach ($data as $id => $cnt) {
$html .= '<dt>';
$html .= html_wikilink(':' . $id, useHeading('navigation') ? null : $id, $highlight);
if ($cnt !== 0) {
$html .= ': ' . $cnt . ' ' . $lang['hits'] . '';
}
$html .= '</dt>';
$resultLink = html_wikilink(':' . $id, null, $highlight);
$hits = '';
$snippet = '';
if ($cnt !== 0) {
$hits = $cnt . ' ' . $lang['hits'];
if ($num < FT_SNIPPET_NUMBER) { // create snippets for the first number of matches only
$html .= '<dd>' . ft_snippet($id, $highlight) . '</dd>';
$snippet = '<dd>' . ft_snippet($id, $highlight) . '</dd>';
}
$num++;
}

$eventData = [
'resultHeader' => [$resultLink, $hits],
'resultBody' => [$snippet],
'page' => $id,
];
trigger_event('SEARCH_RESULT_FULLPAGE', $eventData);
$html .= '<div class="search_fullpage_result">';
$html .= '<dt>' . implode(' ', $eventData['resultHeader']) . '</dt>';
$html .= implode('', $eventData['resultBody']);
$html .= '</div>';
}
$html .= '</dl>';

Expand Down

0 comments on commit 4eab6f7

Please sign in to comment.