Extension:GoogleSiteSearch

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
GoogleSiteSearch

Release status: beta

Implementation Search
Description Adds to or replaces MW Special:Search results with Google CSE results
Author(s) Ryan Finnie (Fo0bartalk)
Latest version 2.2 (2014-04-14)
MediaWiki 1.21+
License GPL
Download Download latest stable release (2.2), or:
Example finnix.org search result

Translate the GoogleSiteSearch extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

The GoogleSiteSearch extension allows you to add Google Custom Search Engine (CSE) results to "Special:Search" additionally to MediaWiki search results, or optionally, replace them altogether.

For an example, please see this search result on finnix.org.

Installation[edit | edit source]

  • 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.
  • Download and extract the tarball in your extensions/ folder. It should generate a new folder called GoogleSiteSearch directly inside your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/GoogleSiteSearch/GoogleSiteSearch.php";
  • Add the following line after the previous line of code (replacing YOUR_CSE_ID with the search engine ID noted above):
$wgGoogleSiteSearchCSEID = 'YOUR_CSE_ID';

Configuration[edit | edit source]

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 | edit source]

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 | edit source]

This extension relies on a MediaWiki hook which was 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.

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;
    }