Extension:Google Search-2

New MediaWiki 1.12.0 version
I recently updated this to work nicely with MW 1.12.0. Download it here

Note that this is really a mod and not an extension since it requires replacing some of the default files (includes/SpecialSearch.php and skins/MonoBook,Modern,CologneBlue.php). You can Diff the versions to see the changes - very small ones.

This extension tightly integrates Google searching with MediaWiki, completely replacing the existing internal search. We use this on dozens of wikis at Intuit, Inc., via a corporate Google appliance. It retrieves XML results and applies a slightly modified Google standard XSLT to the results. It is part of the Intuit Innovation Lab's wiki baseline for new corporate wikis.

These are all internal wikis, but I uploaded some screenshots so that you can see what it looks like.



These instructions are for MediaWiki 1.7.1. However, the extension was originally written for 1.5.4 and will probably work with any 1.5.x version or above. The main difference is in editing the MediaWiki default scripts to force Google searching to be the default and ONLY search engine. I didn't have to change the extension itself when I updated our baseline from 1.5.4 to 1.7.1.

extensions/GoogleSearch.php
getText( 'search', $par ); $start = $wgRequest->getText( 'start', $par);

$wgOut->setPageTitle($search . " - Google Search");

$sitesearch = urlencode($_SERVER["HTTP_HOST"] . $wgScriptPath);

$url = 'http://googlesearchurl.yoursite.com/search?q='. urlencode($search). '&output=xml&site=ext_name&client=name&as_sitesearch='. $sitesearch. '&start='. $start;
 * 1) Google URL Parameters
 * 2) site=ext_name  : this is the Google appliance (GA) "collection" to search
 * 3) client=name    : this is the GA client that is allowed to make requests
 * 4) as_sitesearch= : this restricts the results to this specific wiki, even on shared domains
 * 5)                  so wikis.intuit.com/first  gets its own results
 * 6) 			 likewise wikis.intuit.com/second gets its own

$xmldata = file_get_contents($url);


 * 1) This saves the file to a temp location so that XSLTPROC can
 * 2) run on it. If you have Sablotron installed with PHP 5, you can
 * 3) use it's XSLT functions. The following method, however, works with
 * 4) any version of PHP.

$xmlfile = tempnam("",""); $file = fopen($xmlfile,"w"); fwrite($file,$xmldata); fclose($file);

$results = xsltproc('extensions/Google.xslt',$xmlfile);

$wgOut->addHTML($results);

unlink($xmlfile);

$wgOut->output; return; }

function xsltproc($xslfile, $xmlfile) {   $toexec = "xsltproc ". $xslfile. " " . $xmlfile; exec($toexec,$results); return implode("",$results); } ?>

extensions/Google.xslt
This is too long to directly post, so it is uploaded here.. Included in the ZIP are the graphics I use.

The modifications I made to this standard transform are to point to the graphics, slightly different messages and to prevent site:whatever.com to re-appear in the search box. It works dynamically - i.e. you don't have to modify this XSLT to match your website, just as you don't have to modify the GoogleSearch.php script except to set your collection and client.

Here are some of the modifications to the standard that you'll see: Graphic locations: http://ilab.intuit.com/wiki/images/Title_Left.gif    Plenty of misc changes - do a diff against the original. Search for "intuit.com" to change stuff to your URLs.

MediaWiki script changes
To force this to be the default search engine, you need to change includes/Wiki.php. On MediaWiki 1.5.4, the change had to be made in index.php.

includes/Wiki.php
if( !$this->getVal('DisableInternalSearch') && !is_null( $search ) && $search !== '' ) { // Commented OUT the default search // require_once( 'includes/SpecialSearch.php' ); // $title = Title::makeTitle( NS_SPECIAL, 'Search' ); // wfSpecialSearch; // Add GoogleSearch here AND see the line below where it's added wfGoogleSearch; } else if( !$title or $title->getDBkey == '' ) { $title = Title::makeTitle( NS_SPECIAL, 'Badtitle' ); # Die now before we mess up $wgArticle and the skin stops working throw new ErrorPageError( 'badtitle', 'badtitletext' ); } else if ( $title->getText == 'Search') { wfGoogleSearch; } else if ( $title->getInterwiki != '' ) { etc.............

skins/MonoBook.php
Here I've removed the "Go" button and the "search" text. Now there's a google logo and only one "search" button.   /images/google_logo.gif"> text('searchaction') ?>" id="searchform"> haveMsg('accesskey-search')) { ?>accesskey="msg('accesskey-search') ?>"data['search'] ) ) { ?> value="text('search') ?>" /> msg('search') ?>" />

Summary
Add include("extensions/GoogleSearch.php"); to your LocalSettings.php, place GoogleSearch.php and Google.xslt in extensions/, and put the graphics someplace the scripts can find them - you can just put them all in extensions/ and update the files to point there.

I think that's all the changes I made. The results look great as you can see in the screenshots above - Google is fully integrated, looks like it is "part of" the MediaWiki software. The next/prev results buttons all work as expected.

--MHart 16:24, 4 August 2006 (UTC)