Skip to content


Google search box in MediaWiki

Here is how we added a Google Adsense search box to MediaWiki 1.12.0

1. Force the Monobook skin for all, or you’ll need to do the same with every skin

2. In your skins folder, create a file withtin a subfolder (for instance “adsense/adsense_search.php”) with the following content (edit with your own Google Adsense code, we put the whole thing because we edited the search box code a lot to make it fit best in the MediaWiki layout):

<form method=”get” action=”http://www.google.com/custom” target=”google_window”>
<div>
<label for=”q”><img src=”http://www.google.com/logos/Logo_25wht.gif” width=”75″ height=”32″ alt=”Google search”/></label><br/>
<input type=”hidden” name=”domains” value=”www.zengamers.com”/>
<input type=”text” name=”q” id=”q” size=”20″ maxlength=”255″ value=”zengamers”/>
<div style=”text-align:left;”>
<input type=”radio” name=”sitesearch” id=”but_web1″ value=””/><label for=”but_web1″>Web</label><br/>
<input type=”radio” name=”sitesearch” id=”but_web2″ value=”www.zengamers.com” checked=”checked”/><label for=”but_web2″>ZenGamers</label><br/>
</div>
<input type=”submit” name=”sa” value=”Search”/>
<input type=”hidden” name=”client” value=”pub-9471398824076666″></input>
<input type=”hidden” name=”forid” value=”1″></input>
<input type=”hidden” name=”channel” value=”9439165294″></input>
<input type=”hidden” name=”ie” value=”ISO-8859-1″></input>
<input type=”hidden” name=”oe” value=”ISO-8859-1″></input>
<input type=”hidden” name=”safe” value=”active”></input>
<input type=”hidden” name=”flav” value=”0000″></input>
<input type=”hidden” name=”sig” value=”KS-Bk7FzutK3E_yj”></input>
<input type=”hidden” name=”cof” value=”GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:68;LW:100;L:http://www.zengamers.com/0custom/logo1s.png;S:http://www.zengamers.com;LP:1;FORID:1″></input>
<input type=”hidden” name=”hl” value=”en”></input>
</div>
</form>

3. Edit MonoBook.php as follow:
After:

<div id=”searchBody” class=”pBody”>
<form action=”<?php $this->text(‘searchaction’) ?>” id=”searchform”><div>
<input id=”searchInput” name=”search” type=”text”<?php echo $skin->tooltipAndAccesskey(‘search’);
if( isset( $this->data[‘search’] ) ) {
?> value=”<?php $this->text(‘search’) ?>”<?php } ?> />
<input type=’submit’ name=”go” class=”searchButton” id=”searchGoButton” value=”<?php $this->msg(‘searcharticle’) ?>”<?php echo $skin->tooltipAndAccesskey( ‘search-go’ ); ?> /> 
<input type=’submit’ name=”fulltext” class=”searchButton” id=”mw-searchButton” value=”<?php $this->msg(‘searchbutton’) ?>”<?php echo $skin->tooltipAndAccesskey( ‘search-fulltext’ ); ?> />
</div></form>

Add:

<?php require(“adsense/adsense_search.php”); ?>

4. Upload the stuff 🙂

Credits: this time I made it all myself. Well, ok, credits to my old self, when I customized the search box 2 years ago :p

Update (2011-02-17): the current archived code on Wiki4Games (we’re now on Scroogle):

<form method=”get” action=”http://www.google.com/custom” target=”google_window”>
<div>
<label for=”q”><img src=”/0custom/google_logo.png” width=”75″ height=”32″ alt=”Google search”/></label><br/>
<input type=”hidden” name=”domains” value=”www.wiki4games.com”/>
<input type=”text” name=”q” id=”q” size=”18″ maxlength=”255″ value=”wiki4games”/>
<div style=”text-align:left;”>
<input type=”radio” name=”sitesearch” id=”but_web1″ value=””/><label for=”but_web1″>Web</label><br/>
<input type=”radio” name=”sitesearch” id=”but_web2″ value=”www.wiki4games.com” checked=”checked”/><label for=”but_web2″>Wiki4Games</label><br/>
</div>
<input type=”submit” name=”sa” value=”Search”/>
<input type=”hidden” name=”client” value=”pub-9471398824076666″></input>
<input type=”hidden” name=”forid” value=”1″></input>
<input type=”hidden” name=”channel” value=”9439165294″></input>
<input type=”hidden” name=”ie” value=”ISO-8859-1″></input>
<input type=”hidden” name=”oe” value=”ISO-8859-1″></input>
<input type=”hidden” name=”safe” value=”active”></input>
<input type=”hidden” name=”flav” value=”0000″></input>
<input type=”hidden” name=”sig” value=”KS-Bk7FzutK3E_yj”></input>
<input type=”hidden” name=”cof” value=”GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:68;LW:100;L:http://www.wiki4games.com/0custom/logo1s.png;S:http://www.wiki4games.com;LP:1;FORID:1″></input>
<input type=”hidden” name=”hl” value=”en”></input>
</div>
</form>

Posted in MediaWiki, web development.


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Sy Ali says

    Thanks again for this tutorial. I ended up hacking around a bit to remove the existing search area as well as implement an accesskey for the google search box.

  2. patheticcockroach says

    I’m not sure this is a good idea to remove the existing search box, for it gives some interesting functionalities IMO (like searching by namespace).



Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA