Permalink
Browse files

added a compensation for "remove_url_params" option

  • Loading branch information...
kazmiya committed Jan 23, 2010
1 parent 7b40b91 commit b80c9dd07a940948a1b6505de6fc69470c22f167
Showing with 40 additions and 7 deletions.
  1. +37 −4 action.php
  2. +1 −1 lang/en/settings.php
  3. +1 −1 lang/ja/settings.php
  4. +1 −1 plugin.info.txt
View
@@ -28,9 +28,14 @@ class action_plugin_nohighlight extends DokuWiki_Action_Plugin {
* Registers event handlers
*/
function register(&$controller) {
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'disableHighlight', array());
$controller->register_hook('SEARCH_QUERY_FULLPAGE', 'AFTER', $this, 'removeUrlParams', array('do' => 'modify'));
$controller->register_hook('FULLTEXT_SNIPPET_CREATE', 'BEFORE', $this, 'removeUrlParams', array('do' => 'restore'));
$controller->register_hook('DOKUWIKI_STARTED',
'BEFORE', $this, 'disableHighlight', array());
$controller->register_hook('DOKUWIKI_STARTED',
'AFTER', $this, 'removeUrlParams', array('do' => 'get'));
$controller->register_hook('SEARCH_QUERY_FULLPAGE',
'AFTER', $this, 'removeUrlParams', array('do' => 'modify'));
$controller->register_hook('FULLTEXT_SNIPPET_CREATE',
'BEFORE', $this, 'removeUrlParams', array('do' => 'restore'));
}
/**
@@ -53,7 +58,7 @@ function disableHighlight(&$event, $param) {
if (!empty($_REQUEST['s'])) $HIGH = '';
break;
case 'auto': // disable auto-highlight via search engines
$HIGH = $_REQUEST['s'];
$HIGH = isset($_REQUEST['s']) ? (string) $_REQUEST['s'] : '';
break;
}
}
@@ -90,6 +95,9 @@ function removeUrlParams(&$event, $param) {
if (!$this->remove_url_params) return;
switch ($param['do']) {
case 'get':
$this->getCandidatesFromReferer();
break;
case 'modify':
$this->modifyCandidates($event->data['highlight']);
break;
@@ -99,6 +107,31 @@ function removeUrlParams(&$event, $param) {
}
}
/**
* Gets highlight candidates from HTTP_REFERER info
* (A compensation for "remove_url_paarams" option)
*/
function getCandidatesFromReferer() {
global $HIGH;
global $ACT;
if ($ACT !== 'show') return;
if (!empty($HIGH)) return;
if (!isset($_SERVER['HTTP_REFERER'])) return;
if (in_array($this->disable_highlight, array('all', 'auto'))) return;
$referer = (string) $_SERVER['HTTP_REFERER'];
if (!preg_match('/^'.preg_quote(DOKU_URL, '/').'.*[?&]do=search/', $referer)) return;
if (!preg_match('/[?&]id=([^&]+)/', $referer, $matches)) return;
// users seem to have jumped from search result link in this wiki
require_once(DOKU_INC.'inc/fulltext.php');
$parsed_query = ft_queryParser(urldecode($matches[1]));
// set highlight candidates
$HIGH = $parsed_query['highlight'];
}
/**
* Modifies highlight candidates
*/
View
@@ -9,7 +9,7 @@
$lang['disable_highlight'] = 'Disable search term highlighting features in a wiki page';
$lang['disable_highlight_o_all'] = 'Disable all highlighting features';
$lang['disable_highlight_o_query'] = 'Disable highlighting by URL param "?s[]=term"';
$lang['disable_highlight_o_auto'] = 'Disable auto-highlight via search engines';
$lang['disable_highlight_o_auto'] = 'Disable auto-highlighting by HTTP_REFERER info';
$lang['disable_highlight_o_none'] = 'None (DokuWiki default behavior)';
$lang['remove_url_params'] = 'Remove "?s[]=term" part from search result link URLs';
View
@@ -9,7 +9,7 @@
$lang['disable_highlight'] = 'Wiki ページ上での検索ワードのハイライト機能を無効化する';
$lang['disable_highlight_o_all'] = 'すべてのハイライト機能を無効化';
$lang['disable_highlight_o_query'] = 'URL パラメータ "?s[]=term" によるハイライトを無効化';
$lang['disable_highlight_o_auto'] = '検索エンジン経由の自動ハイライトを無効化';
$lang['disable_highlight_o_auto'] = 'HTTP リファラ情報による自動ハイライトを無効化';
$lang['disable_highlight_o_none'] = '無効化しない (DokuWiki のデフォルト動作)';
$lang['remove_url_params'] = '検索結果のリンク URL から "?s[]=term" の部分を削除する';
View
@@ -1,7 +1,7 @@
base nohighlight
author Kazutaka Miyasaka
email kazmiya@gmail.com
date 2010-01-22
date 2010-01-23
name No Highlight Plugin
desc Disables search term highlighting features
url http://www.dokuwiki.org/plugin:nohighlight

0 comments on commit b80c9dd

Please sign in to comment.