Thursday, November 5, 2009

Add a wikipedia search box for your website or blog

On the main site of Wikipedia there is a search box to search the articles on their wiki, can you do this from your website or wiki? Yes you can search wikipedia from your site or even your own wiki if you have one!.
Create a search.html file containing the following code:

CODE
<html>
<body>
<form action="search-redirect.php" id="searchform"><div>
   <input id="searchInput" name="search" type="text" />
   <input type='submit' name="go" class="searchButton" id="searchGoButton" value="Search" />
</div></form>
<!-- you can remove the below line if you wish, although it's appreciated if you leave it;) -->
Wiki search provided by <a href="http:/www.ipbwiki.com">IpbWiki.com</a>
</body>
</html>

(All you really need of the above code is the part between <form> and </form>). In the same folder as search.html, create a file called search-redirect.php, copy the following code in it and customize the path to have it point to your wiki

CODE
<?php
# Author: Peter De Decker
# Help & documentation: http://www.ipbwiki.com/Media_Wiki:Add_a_wikipedia_search_box_to_your_main_website_or_blog

###############################################################
# Parametrisation, customize this!                            #
###############################################################

# set this to the same value as $wgArticlePath in your LocalSettings.php, make sure to have a trailing /
# examples:
# $path = 'http://www.ipbwiki.com/'; // search on ipbwiki, index.php is eliminated from the url here;
# $path = 'http://en.wikipedia.org/wiki/';              // search on english wikipedia
# $path = 'http://localhost/mediawiki-1.8/index.php/';  // default article naming...
$path = 'http://www.ipbwiki.com/';
###############################################################
# Actual code, wooo :)                                        #
###############################################################
$redirect_url = $path . 'Special:Search?search=' . $_GET['search'] . '&go=Go';
@header( "Location: ".$redirect_url );
?>

Another simple one:
<form action="http://www.wikipedia.org/search-redirect.php" method="get">
Search Wikipedia:
<input type="hidden" name="language" value="en" />
<input type="text" name="search" size="20" />
<input type="submit" name="go" value=" Go! " />
</form>