View Issue Details

IDProjectCategoryView StatusLast Update
0008281mantisbtfilterspublic2016-08-23 04:42
ReporterDGtlRift Assigned Todregad  
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status closedResolutionno change required 
Product Version1.1.0a4 
Summary0008281: Add Mantis to search engines
Description

For installations of Mantis there should be a method to include mantis in Firefox's search engine list.

Additional Information

I'm not sure if it applies to IE, but I'm sure this would be a nice feature there as well.

Since my installation is https based, I was unable to test this patch.

NOTE: This will NOT work on https based installations according to the mozilla website.

This was based on the code from victor:
http://www.mantisbt.org/wiki/doku.php/mantisbt:mantis_search_plugin_for_mozilla_firefox
and
http://www.mozilla.org/projects/search/technical.html

New Code/Files:
config_defaults_inc.php
g_search_engine_add_enabled // Turn on and off the icon
g_search_engine_name // Name of the search engine (site installation)

mantis_search_src.php
file contains php code based on victors search engine code on the wiki page above

core/html_api.php
Add javascript include for new file javascript/common.js.php
Add link to add search engine to your browser

core/utility_api.php
php function get_server_domain
New function to return a guess of the domain name of the server

images/mantis_search_src.ico
Binary file for the icon of the search engine (copy of favicon.ico)

javascript/common.js.php
php script to render site specific javascript.
javascript function addEngine
adds this sites installation of mantis to the search engine list

lang/strings_english.txt
php lang var search_engine_add
"Add Mantis to Search Engines"

Tagspatch
Attached Files
search_engine.2007-08-21.patch (7,231 bytes)   
Index: config_defaults_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/config_defaults_inc.php,v
retrieving revision 1.355
diff -u -r1.355 config_defaults_inc.php
--- config_defaults_inc.php	15 Aug 2007 02:57:07 -0000	1.355
+++ config_defaults_inc.php	21 Aug 2007 13:20:09 -0000
@@ -1883,4 +1883,12 @@
 	
 	# The twitter account password.
 	$g_twitter_password = '';
+
+	#############################
+	# Browser Search Engine
+	#############################
+	# Allow users to add a search engine for mantis to the search engine list
+	$g_search_engine_add_enabled	= ON;
+	$g_search_engine_name		= 'Mantis Search Engine';
+	
 ?>
Index: mantis_search_src.php
===================================================================
RCS file: mantis_search_src.php
diff -N mantis_search_src.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mantis_search_src.php	21 Aug 2007 13:20:09 -0000
@@ -0,0 +1,32 @@
+<?php
+	# Mantis - a php based bugtracking system
+	# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
+	# Copyright (C) 2002 - 2004  Mantis Team   - mantisbt-dev@lists.sourceforge.net
+	# This program is distributed under the terms and conditions of the GPL
+	# See the README and LICENSE files for details
+
+	# --------------------------------------------------------
+	# $Id: mantis_search_src.php,v 1.3 2005/02/12 20:01:08 jlatour Exp $
+	# --------------------------------------------------------
+?>
+<?php
+	require_once( 'core.php' );
+
+	$t_core_path = config_get( 'core_path' );
+
+	require_once( $t_core_path.'utility_api.php' );
+?>
+
+# Mozilla/Mantis plug-in by Victor Boctor (http://www.futureware.biz)
+# Modded for inlining in Mantis
+<search
+    name=<?php echo '"Mantis ' . config_get( 'search_engine_name' ) . '"' . "\n"; ?>
+    description=<?php echo '"' . config_get( 'search_engine_name' ) . '"' . "\n"; ?>
+    method="GET"
+    action=<?php echo '"' . config_get( 'path' ) . 'view.php"' . "\n"; ?>
+    queryEncoding="utf-8"
+    queryCharset="utf-8">
+
+    <input name="id" user>
+
+</search>
Index: core/html_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/html_api.php,v
retrieving revision 1.211
diff -u -r1.211 html_api.php
--- core/html_api.php	31 Jul 2007 07:51:16 -0000	1.211
+++ core/html_api.php	21 Aug 2007 13:20:11 -0000
@@ -260,6 +260,8 @@
 		if ( ON == config_get( 'use_javascript' ) ) {
 			echo "\t" . '<script type="text/javascript" language="JavaScript" src="javascript/common.js">';
 			echo '</script>' . "\n";
+			echo "\t" . '<script type="text/javascript" language="JavaScript" src="javascript/common.js.php">';
+			echo '</script>' . "\n";
 			echo "\t" . '<script type="text/JavaScript" src="javascript/ajax.js">';
 			echo '</script>' . "\n";
 
@@ -601,6 +603,13 @@
 
 				PRINT '<input type="submit" class="button-small" value="' . lang_get( 'jump' ) . '" />&nbsp;';
 				PRINT '</form>';
+				if (	( config_get('search_engine_add_enabled') ) &&
+					( ON == config_get( 'use_javascript' ) ) &&
+					!is_server_protocol( 'https' ) ) {
+					PRINT '<a href="javascript:addEngine()">';
+					PRINT '<img src="images/favicon.ico" alt="' . lang_get('search_engine_add') . '" style="border-style: none; margin: 5px; vertical-align: middle;" />';
+					PRINT '</a>';
+				}
 			PRINT '</td>';
 			PRINT '</tr>';
 			PRINT '</table>';
Index: core/utility_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/utility_api.php,v
retrieving revision 1.22
diff -u -r1.22 utility_api.php
--- core/utility_api.php	21 Jul 2007 22:54:29 -0000	1.22
+++ core/utility_api.php	21 Aug 2007 13:20:11 -0000
@@ -216,5 +216,34 @@
 	function is_page_name( $p_string ) {
 	   return isset( $_SERVER['PHP_SELF'] ) && ( 0 < strpos( $_SERVER['PHP_SELF'], $p_string ) );
 	}
-	
+
+	# --------------------
+	# Return the domain of this webserver
+	# Taken from config_defaults_inc
+	function get_server_domain() {
+		$t_host = 'www.example.com';
+		if ( isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) { // Support ProxyPass
+			$t_host = $_SERVER['HTTP_X_FORWARDED_HOST'];
+		} else if ( isset( $_SERVER['HTTP_HOST'] ) ) {
+			$t_host = $_SERVER['HTTP_HOST'];
+		} else if ( isset( $_SERVER['SERVER_NAME'] ) ) {
+			$t_host = $_SERVER['SERVER_NAME'] . $t_port;
+		} else if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
+			$t_host = $_SERVER['SERVER_ADDR'] . $t_port;
+		}
+		return( $t_host );
+	}
+
+	# --------------------
+	# Return the boolean that this session is using the specified protocol
+	# Taken from config_defaults_inc
+	function is_server_protocol( $p_protocol ) {
+		$t_protocol = 'http';
+		if (		( isset( $_SERVER['HTTPS'] ) ) &&
+				( 'off' != strtolower( $_SERVER['HTTPS'] ) ) ) {
+			$t_protocol = 'https';
+		}
+		return( $t_protocol == $p_protocol );
+	}
+
 ?>
Index: images/mantis_search_src.ico
===================================================================
RCS file: images/mantis_search_src.ico
diff -N images/mantis_search_src.ico
Binary files /dev/null and mantis_search_src.ico differ
Index: javascript/common.js.php
===================================================================
RCS file: javascript/common.js.php
diff -N javascript/common.js.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ javascript/common.js.php	21 Aug 2007 13:20:12 -0000
@@ -0,0 +1,35 @@
+/*
+ * Mantis - a php based bugtracking system
+ * Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
+ * Copyright (C) 2002 - 2004  Mantis Team   - mantisbt-dev@lists.sourceforge.net
+ * This program is distributed under the terms and conditions of the GPL
+ * See the README and LICENSE files for details
+ *
+ * ----------------------------------------------------------
+ * $Id: common.js.php,v 1.9 2007/08/14 01:46:35 jhanley Exp $
+ * ----------------------------------------------------------
+ */
+
+<?php
+	require_once( '../core.php' );
+
+	$t_core_path = config_get( 'core_path' );
+
+	require_once( $t_core_path.'utility_api.php' );
+?>
+
+function addEngine()
+{
+	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function"))
+	{
+		window.sidebar.addSearchEngine(
+				<?php echo '"' . config_get( 'path' ) . '../mantis_search_src.php"'; ?>,		/* engine URL */
+				<?php echo '"' . config_get( 'path' ) . '../images/mantis_search_src.gif"'; ?>,		/* icon URL */
+				<?php echo '"' . get_server_domain() . '"'; ?>,	/* engine name */
+				"Web" );				/* category name */
+	}
+	else
+	{
+		alert("Mozilla M15 or later is required to add a search engine.");
+	}
+}
Index: lang/strings_english.txt
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/lang/strings_english.txt,v
retrieving revision 1.312
diff -u -r1.312 strings_english.txt
--- lang/strings_english.txt	15 Aug 2007 16:25:29 -0000	1.312
+++ lang/strings_english.txt	21 Aug 2007 13:20:13 -0000
@@ -662,6 +662,7 @@
 $s_older_news_link = 'Older News';
 $s_archives = 'Archives';
 $s_rss = 'RSS';
+$s_search_engine_add = 'Add Mantis to Search Engines';
 
 # manage_create_new_user.php
 $s_created_user_part1 = 'Created user';
search_engine.2007-08-21.patch (7,231 bytes)   

Activities

vboctor

vboctor

2007-08-21 03:13

manager   ~0015467

Looks good.

Following are my comments:

  • $g_search_engine_name = 'Change Me Mantis Search Engine';
    The string looks strange. Do you mean 'Mantis Search Engine'?

  • if ( ( ON == config_get( 'use_javascript' ) ) and

  • ( config_get('search_engine_add_enabled') ) ) {

  • Replace "and" with &&.

  • Add "ON ==" for the second check.

  • We should consider having a page specially for this search engine. The page can handle any string, not just an issue id.

DGtlRift

DGtlRift

2007-08-21 09:05

reporter   ~0015471

Last edited: 2007-08-21 09:24

RE: Strange String
Not really, the mozilla documentation was a little vague - I wasn't sure if the name token in the src file indicates the search engine or if (what I would actually expect) the domain argument to addSearchEngine is what determines the "id" of the search engine. If it is the former, the admin must change that value to prevent other mantis installations from overwriting the search engine src and image file. At least this is my understanding. I suppose the default for the variable could be:
get_server_domain() . " Mantis Search Engine";

Just simplified it to 'Mantis Search Engine';

RE: order check
That's an easy change, but after reading, I thought I should also add a check for the protocol and skip the line code if it is https, since mozilla/sherlock doesn't even support this via https.

Added check for https

RE: Separate search page
I'm guessing you mean that there should be a page to handle creating a filter based on the search params? It could become fairly flexible where the user could enter a string like 'r:jdoe n:"bad checksum" corrupt' where everything is optional, but the r: is for the reporter and n: is for notes and the third searches everywhere, but this flexibility could (and should) be added later.

Let's write up a requirements page for this

DGtlRift

DGtlRift

2007-08-22 11:34

reporter   ~0015489

If all the new patch look good and someone can peer review/test I'll check them in.

siebrand

siebrand

2009-06-13 04:11

developer   ~0022131

Unassigned after having been assigned for almost 2 years without progress.

dregad

dregad

2016-08-09 08:22

developer   ~0053767

I believe this is fully covered by the implemented opensearch functionality provided by browser_search_plugin.php page.