Extension:Google Custom Search Engine

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
Google Custom Search Engine

Release status: stable

Implementation  Tag
Description This extension adds a Google Custom Search Engine (Google Co-op) to your MediaWiki-powered site.
Author(s)  User:BiGreat
Last Version  0.1 (2006-11-21)
MediaWiki  1.7.1
License No license specified
Download see below

check usage (experimental)

This extension adds a Google Custom Search Engine (Google Co-op) to your Wiki site.

Contents

[edit] What is the utility of this extension ?

This extension adds a Google Custom Search Engine to your Wiki site, uses a specific page that shows you the results, and, if you will, the GoogleSearch box could replace the MediaWiki box.

[edit] Get Google Co-op Codes

  • Before you start to install this extension, you need to go to http://www.google.com/coop/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).
Co-op codes
  • 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.

[edit] Installation

Copy "google-coop.php" below in Notepad or gedit, and copy the TWO codes (code 1 and code 2) provided by Google and paste them between $output=' and ';//google code end here in google-coop.php :

[edit] google-coop.php

<?php
# Google Custom Search Engine Extension
# 
# Tag :
#   <Googlecoop></Googlecoop> or <Googlecoop/>
# Ex :
#   Add this tag to the wiki page you configed at your Google co-op control panel.
#
# Enjoy !

$wgExtensionFunctions[] = 'GoogleCoop';
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'Google Co-op Extension',
        'description' => 'Using Google Co-op',
        'author' => 'Liang Chen The BiGreat',
        'url' => 'http://www.mediawiki.org/wiki/Extension:Google_Custom_Search_Engine'
);
 
function GoogleCoop() {
        global $wgParser;
        $wgParser->setHook('Googlecoop', 'renderGoogleCoop');
}
 
# The callback function for converting the input text to HTML output
function renderGoogleCoop($input) {
 
        $output='
                        @@@@@@@@@@@PASTE THE TWO CODEs HERE@@@@@@@@@@
When you paste the code from Google, please take care of removing all the blank spaces. It creates a  <p> or a <DIV> tag. This does not run the code of Google.
					';//google code end here
 
        return $output;
}


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

$output='<form action="YOURURL" id="cse-search-box">
<input type="hidden" name="cx" value="YOURKEY" /><input type="hidden" name="cof" value="FORID:10" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" /><input type="submit" name="sa" value="Search" />
</form><script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script><script type="text/javascript" src="http://www.google.com/***/t13n?form=cse-search-box&t13n_langs=fr"></script><script type="text/javascript" src="http://www.google.com/***/brand?form=cse-search-box&lang=fr"></script>
<script type="text/javascript">var googleSearchIframeName = "cse-search-results";var googleSearchFormName = "cse-search-box";var googleSearchFrameWidth = 600;var googleSearchDomain = "www.google.com";var googleSearchPath = "/cse";</script><script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>';//google code end here

[edit] Save, upload and configure

  • Save your file under the name : google-coop.php ;
  • Upload the google-coop.php to your extensions/ directory, and add include("extensions/google-coop.php"); 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 <Googlecoop></Googlecoop> to this page and protect it.
  • Then use another code Google provided at the pages you want to be the entrance of the search.

[edit] Sidebar

Edit /skins/MonoBook.php, and, after function searchBox, replace all between "<form action=" and "</form>" by your Google CODE 1. You could configure the widht of the search box by modifying size="31".

[edit] Illustrations

The entrance at sidebar
Search Result

[edit] Site users

Please list your site here if you are using this code