Extension:GoogleSiteSearch

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

Release status:Extension status stable

ImplementationTemplate:Extension#type Search
DescriptionTemplate:Extension#description Adds to or replaces MW Special:Search results with Google CSE results
Author(s)Template:Extension#username Ryan Finnie (Fo0bartalk)
Latest versionTemplate:Extension#version 3.0 (2016-08-21)
MediaWikiTemplate:Extension#mediawiki 1.23+
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download Download latest stable release (3.0), or:
ExampleTemplate:Extension#example finnix.org search result

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

Check usage and version matrix.

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]

The extension can be retrieved directly from Git [?]:

  • Browse code
  • Some extensions have tags for stable releases.
  • Each branch is associated with a past MediaWiki release. There is also a "master" branch containing the latest alpha version (might require an alpha version of MediaWiki).

Extract the snapshot and place it in the extensions/GoogleSiteSearch/ directory of your MediaWiki installation.

If you are familiar with git and have shell access to your server, you can also obtain the extension as follows:

cd extensions/
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/GoogleSiteSearch.git
  • Download and place the file(s) in a directory called GoogleSiteSearch in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
wfLoadExtension( 'GoogleSiteSearch' );
$wgGoogleSiteSearchCSEID = 'YOUR_CSE_ID';

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing extensions using wfLoadExtension(), since MediaWiki 1.25. If you need to install this extension in earlier versions, instead of wfLoadExtension( 'GoogleSiteSearch' );, you need to use:

require_once "$IP/extensions/GoogleSiteSearch/GoogleSiteSearch.php";

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.
  • $wgGoogleSiteSearchAttributes - An array of optional Custom Search element attributes. For example, to make links open in a new window/tab:
    $wgGoogleSiteSearchAttributes = array( 'linkTarget' => '_blank' );
    

In addition, the HTML built by the extension is customizable via the GoogleSiteSearchHTML hook. For example:

function MyGSSHTML( $specialSearch, $term, &$html ) {
    $html .= '<p>Example append</p>';
}
$wgHooks['GoogleSiteSearchHTML'][] = 'MyGSSHTML';

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.

See also[edit]