Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(search): use dedicated url-parameter for search query
This way we do not loose the context of the current page. Further, the
new id generated from the query before wasn't really that useful (see
issue #1124 ). And we can still generate a meaningful link "create a
page for your query", if that is considered useful.

Further redirects exist for the old urls, so bookmarked searches etc.
should mostly keep working.
  • Loading branch information
micgro42 committed Mar 26, 2018
1 parent bbc1da2 commit d22b78c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doku.php
Expand Up @@ -35,7 +35,7 @@

//import variables
$INPUT->set('id', str_replace("\xC2\xAD", '', $INPUT->str('id'))); //soft-hyphen
$QUERY = trim($INPUT->str('id'));
$QUERY = trim($INPUT->str('q'));
$ID = getID();

$REV = $INPUT->int('rev');
Expand Down
15 changes: 12 additions & 3 deletions inc/Action/Search.php
Expand Up @@ -25,13 +25,22 @@ public function minimumPermission() {
*/
public function checkPermissions() {
parent::checkPermissions();
global $QUERY;
$s = cleanID($QUERY);
if($s === '') throw new ActionAbort();
}

public function preProcess()
{
global $QUERY, $ID, $conf, $INPUT;
$s = cleanID($QUERY);

if ($ID !== $conf['start'] && $s === '') {
parse_str($INPUT->server->str('QUERY_STRING'), $urlParts);
$urlParts['q'] = $urlParts['id'];
$urlParts['id'] = $conf['start'];
$url = DOKU_URL . DOKU_SCRIPT . '?' . http_build_query($urlParts, null, '&');
send_redirect($url);
}

if ($s === '') throw new ActionAbort();
$this->adjustGlobalQuery();
}

Expand Down
10 changes: 5 additions & 5 deletions inc/Ui/Search.php
Expand Up @@ -91,7 +91,7 @@ protected function getSearchFormHTML($query)

$searchForm = (new Form())->attrs(['method' => 'get'])->addClass('search-results-form');
$searchForm->setHiddenField('do', 'search');
$searchForm->setHiddenField('from', $ID);
$searchForm->setHiddenField('id', $ID);
$searchForm->setHiddenField('searchPageForm', '1');
if ($INPUT->has('after')) {
$searchForm->setHiddenField('after', $INPUT->str('after'));
Expand All @@ -100,7 +100,7 @@ protected function getSearchFormHTML($query)
$searchForm->setHiddenField('before', $INPUT->str('before'));
}
$searchForm->addFieldsetOpen()->addClass('search-results-form__fieldset');
$searchForm->addTextInput('id')->val($query)->useInput(false);
$searchForm->addTextInput('q')->val($query)->useInput(false);
$searchForm->addButton('', $lang['btn_search'])->attr('type', 'submit');

if ($this->isSearchAssistanceAvailable($this->parsedQuery)) {
Expand Down Expand Up @@ -222,7 +222,7 @@ protected function addSearchLink(
$after = null,
$before = null
) {
global $INPUT;
global $INPUT, $ID;
if (null === $and) {
$and = $this->parsedQuery['and'];
}
Expand Down Expand Up @@ -252,7 +252,7 @@ protected function addSearchLink(
$ns,
$notns
);
$hrefAttributes = ['do' => 'search', 'searchPageForm' => '1'];
$hrefAttributes = ['do' => 'search', 'searchPageForm' => '1', 'q' => $newQuery];
if ($after) {
$hrefAttributes['after'] = $after;
}
Expand All @@ -261,7 +261,7 @@ protected function addSearchLink(
}
$searchForm->addTagOpen('a')
->attrs([
'href' => wl($newQuery, $hrefAttributes, false, '&')
'href' => wl($ID, $hrefAttributes, false, '&')
])
;
$searchForm->addHTML($label);
Expand Down
4 changes: 2 additions & 2 deletions inc/template.php
Expand Up @@ -670,8 +670,8 @@ function tpl_searchform($ajax = true, $autocomplete = true) {
]);
$searchForm->addTagOpen('div')->addClass('no');
$searchForm->setHiddenField('do', 'search');
$searchForm->setHiddenField('from', $ID);
$searchForm->addTextInput('id')
$searchForm->setHiddenField('id', $ID);
$searchForm->addTextInput('q')
->addClass('edit')
->attrs([
'title' => '[F]',
Expand Down

0 comments on commit d22b78c

Please sign in to comment.