Extension:GoogleAjax
|
GoogleAjax Release status: stable |
|
|---|---|
| Implementation | Ajax |
| Description | To add a google search to the search results page using the Google Ajax API[1] |
| Author(s) | Bryden Smith (BrydenTalk) |
| Last version | 1.1 |
| License | GPL |
| Download | No link |
|
Check usage (experimental) |
|
Contents |
[edit] What can this extension do?
This will add a section to the bottom of the search results page for a google search, just above the Advanced Search box, using Google's Ajax API.[1] It will automatically search for the term that the user has searched for, and return the first result, offering the option to expand to show all results.
[edit] Usage
This is a bit of a Hack, but once it is put in place it is stable and works very smoothly, no further configuration is needed.
To use this, you will need to have Ajax enabled by adding the following to LocalSettings.php
$wgUseAjax = 'true';
[edit] Problems with MediaWiki 1.15.1
The extension is currently not correctly working with MediaWiki 1.15.1.[2]
This has now been resolved by changing the name of the Google version of the <div id="content"> to <div id="Googlecontent">
[edit] Installation
To install this extension, add the following to SpecialSearch.php:
please make sure you save a backup of specialsearch.php before you apply this extension
In the SpecialSearch.php file locate the following code
if( $num || $this->offset ) {
$wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
}
Paste in the following code after that:
$wgOut->addScript( "<script src='http://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('search', '1');
// Whenever a search starts, alert the query.
function searchStart(searchControl, searcher, query) {
var content = document.getElementById('search_control');
var queryDiv = document.getElementById('query');
if (! queryDiv) {
var queryDiv = document.createElement('div');
queryDiv.id = 'query';
document.body.appendChild(queryDiv);
}
queryDiv.innerHTML = 'User searched for: ' + query;
}
function OnLoad() {
// Create a search control
var searchControl = new google.search.SearchControl();
// Add a WebSearcher
searchControl.addSearcher(new google.search.WebSearch());
// Set a callback so that whenever a search is started we will call searchStart
searchControl.setSearchStartingCallback(this, searchStart);
// tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById('Googlecontent'));
// execute an inital search
searchControl.execute('{$term}');
}
google.setOnLoadCallback(OnLoad);
</script>/n");
Then, locate the next section of Code:
$out = Xml::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
and change it to:
$out = "<h2>Google Search Results</h2>".
"<div id='Googlecontent'>Loading...</div>".
Xml::openElement( 'form', array( 'id' => 'powersearch', 'method' => 'get', 'action' => $wgScript ) ) .
[edit] references
- ↑ Google Search API
- ↑ One of the problems is the use of a <div id="content"> container for the Google search result, the same id being used by MediaWiki's content area. (Fixed, see above)
