Extension:GoogleSiteSearch
|
GoogleSiteSearch Release status: experimental |
|
|---|---|
| Implementation | Search |
| Description | Adds to or replaces MW Special:Search results with Google CSE results |
| Author(s) | Ryan Finnie (Fo0bartalk) |
| Last version | 2.0 (2013-05-04) |
| MediaWiki | 1.21+ |
| License | GPL |
| Download | Download latest stable release (2.0), or: |
| Example | finnix.org search result |
| Check usage and version matrix | |
This extension allows you to add Google Custom Search Engine (CSE) results to Special:Search MediaWiki search results, or optionally, replace them altogether.
For an example, please see this search result on finnix.org.
| This extension relies on a MediaWiki hook which is not yet available, but is scheduled to be released with MediaWiki 1.21. If you would like to use this extensions with MediaWiki 1.20, see below. |
Contents |
Installation [edit]
You can download the extension directly from the MediaWiki source code repository (browse code). You can get:
- One of the extensions tags
Not all extensions have tags. Some extensions have tags for each release, in which case those tags have the same stability as the release. To download a tag
- Go to the tags list
- Click the name of the tag you want to download
- Click "snapshot"
- The latest version of one of the extensions branches
Each extension has a master branch containing the latest code (might be unstable). Extensions can have further branches as well.
- Go to the branches list
- Click the branch name
- Click "snapshot"
- A snapshot made during the release of a MediaWiki version.
This might be unstable and is not guaranteed to work with the associated MediaWiki version.
After you've got the code, save it into the extensions/GoogleSiteSearch directory of your wiki.
If you are familiar with git and have shell access to your server, you can obtain the extension, with all its tags and branches, as follows:
cd extensions
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/GoogleSiteSearch.git
- Go to the Google CSE management page and add a custom search engine.
- Make a note of the "Search engine unique ID". It should be in the format
numbers:letters. - Edit LocalSettings.php in the root of your MediaWiki installation, and add the following lines near the bottom (replacing
YOUR_CSE_IDwith the search engine ID noted above):
require_once( "$IP/extensions/GoogleSiteSearch/GoogleSiteSearch.php" ); $wgGoogleSiteSearchCSEID = 'YOUR_CSE_ID';
- Verify Special:Search is working on your wiki.
Configuration [edit]
The following configuration globals are available:
$wgGoogleSiteSearchCSEID- The ID of the created Google custom search engine. Required.$wgGoogleSiteSearchOnly- Whether to replace the the MediaWiki search results. If true, only the CSE search results are shown. If false, the CSE results are shown above the MediaWiki results. Optional, defaults to false.$wgGoogleSiteSearchCharset- Character set of the data passed to the HTML template; you should not need to modify this in most cases. Optional, default 'UTF-8'.
In addition, the HTML built by the extension is customizable. The defaults are usually sufficient (configuration values replaced automatically, search term inserted, and the user's language preference is passed on to the CSE code automatically). However, if you wish to modify the HTML, copy GoogleSiteSearch.content.default.html to GoogleSiteSearch.content.html and modify.
Internationalization [edit]
Translation of the extension strings is managed by Translatewiki.net (direct extension link). Please contribute translations there.
Internationalization of the Google results themselves is handled by passing the user's (or site default's) language preference to Google CSE. This is handled automatically and requires no configuration.
Modification of older MediaWiki releases [edit]
This extension relies on a MediaWiki hook which is not yet available, but is scheduled to be released with MediaWiki 1.21. If you would like to use this extension with MediaWiki 1.20 or earlier, you will need to modify the MediaWiki source to add the hook.
| This method has been tested only as far back as MediaWiki 1.18, and may not work with earlier versions. |
Edit includes/specials/SpecialSearch.php and look for the following comment, somewhere around line 280:
// start rendering the page
Insert the following code above that comment:
if ( !wfRunHooks( 'SpecialSearchResultsPrepend', array( $this, $out, $term ) ) ) {
# Hook requested termination
wfProfileOut( __METHOD__ );
return;
}