Extension:Google Custom Search Engine

This extension adds a Google Custom Search Engine to your wiki.

What is the utility of this extension?
Adds a Google Custom Search Engine to your wiki, using a specific page that you specify to display the search results. Also enables you to replace the standard MediaWiki search box with a Google search box.

Get Google custom search codes
Under some circumstances, Google will only give you one code.
 * Before you start to install this extension, you need to go to www.google.com/cse/, create a Custom Search Engine by clicking the "Create a Custom Search Engine" button, and find the "code" section at "Control panel".
 * At the "code" section, expand "Search box and search results code for your website" and file one wiki page in your site where you want to display the search result (for example : http://yoursite.com/wiki/yourwikiname:GoogleSearch).
 * After you finish this step, you will get two "codes" as the picture shown right :
 * code 1 is in box 1 : it is the code for the search engine ;
 * code 2 is in box 2: this code is for the search results.

Installation
Save the code below into a file called "google-cse.php", and then edit the file: copy the TWO codes (code 1 and code 2) provided by Google and paste them between $output=' and ';//google code end here into google-cse.php.

Extension code
Then, remove all the blank spaces in code 1 and 2. The result should be something like:

Save, upload and configure

 * Save your file under the name : google-cse.php ;
 * Upload the google-cse.php to your extensions/ directory, and add  at the end of your LocalSettings.php file.
 * Go to the wiki page which you want to display the search result like (http://yoursite.com/wiki/yourwikiname:GoogleSearch), add  to this page and protect it.
 * Then use another code Google provided at the pages you want to be the entrance of the search.

Replacing standard MediaWiki search
You can have the Google Custom Search Engine input replace the standard MediaWiki search input. To do that, you need to edit your skin file. If you're using the Vector skin, edit /skins/Vector.php, and replace all the code between "<form ... id="searchform" " and " " by your Google code 1.

If you're using the MonoBook skin, edit /skins/MonoBook.php, and, after function searchBox, replace all between "<form action=" and " " by Google code 1.

Regardless of the skin, you can configure the width of the search box by modifying size="31". 12 seems to work well.

Illustrations
Below are screenshots for how the Google custom search input can look in the MonoBook skin.



Site users
Please list your site here if you are using this code.
 * Ballotpedia
 * Teamspeak3pedia - konfiguracja - lista serwerów
 * Open Source Ecology wiki
 * Japanese Game Introduction
 * Jewish law encyclopedia

See
Google +1 extension