Adding Google AdSense to MediaWiki 1.4

More publishers are becoming familiar with AdSense as a revolutionary business technology for monetizing eyeballs (i.e., for generating revenue from the viewers that spend time perusing your site). Here are the directions for adding AdSense to your MediaWiki 1.4 installation. You can see the results at PWS Notes, a wiki on a rare genetic disorder that I administer for my sister-in-law. I’m only using text ads and I place them under the rest of the options in the navigation column, so as to be fairly unobtrusive.

This info was inspired by these directions, which work for Mediawiki 1.3 but not for 1.4. Note that if you use the highly recommended Firefox extension Adblock, you need to hit Shift-Ctrl-B first to disable it and see the Google ads.

First, sign up for AdSense; Google takes 2-3 days to review your site. Now, the changes we are going to make are to the Monobook skin. We should really make the changes to every skin, but I believe so few users change the default skin that it’s not really worth the trouble.

In skins/MonoBook.php, we’re going to replace the MediaWiki based search box with an include call to the file containing the Google search box, and we’re going to add an include for the AdSense HTML/Javascript. This diff shows what was removed (with a leading -) and what was added (with a +).:

--- MonoBook.php.orig Thu Mar 17 21:08:46 2005
+++ MonoBook.php Thu Mar 17 19:34:52 2005
@@ -125,23 +125,9 @@
- <div id="p-search" class="portlet">
- <h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
- <div class="pBody">
- <form name="searchform" action="<?php $this->text('searchaction') ?>" id="searchform">
- <input id="searchInput" name="search" type="text"
- <?php if($this->haveMsg('accesskey-search')) {
- ?>accesskey="<?php $this->msg('accesskey-search') ?>"<?php }
- if( isset( $this->data['search'] ) ) {
- ?> value="<?php $this->text('search') ?>"<?php } ?> />
- <input type='submit' name="go" class="searchButton" id="searchGoButton"
- value="<?php $this->msg('go') ?>"
- /> <input type='submit' name="fulltext"
- class="searchButton"
- value="<?php $this->msg('search') ?>" />
- </form>
- </div>
- </div>
+<?php include("sitesearch.php") ?>
<div class="portlet" id="p-tb">
<h5><?php $this->msg('toolbox') ?></h5>
<div class="pBody">
@@ -163,6 +149,9 @@
+<?php include("adsense.php") ?>
<?php if( $this->data['language_urls'] ) { ?><div id="p-lang" class="portlet">
<h5><?php $this->msg('otherlanguages') ?></h5>
<div class="pBody">

Now, here are the contents of sitesearch.php:

<div id="p-search" class="portlet">
<h5><label for="searchInput">Search</label></h5>
<div class="pBody">
<!-- SiteSearch Google -->
<form method="get" action="" target="_top">
<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="">
<img src=""
border="0" alt="Google"></img></a>
<input type="hidden" name="domains" value=""></input>
<input type="text" name="q" size="15" maxlength="255" value=""></input>
<td nowrap="nowrap">
<input type="radio" name="sitesearch" value=""></input>
<font size="-1" color="#000000">Web</font>
<input type="radio" name="sitesearch" value=""
<font size="-1" color="#000000"></font>
<input type="submit" name="sa" value="Search"></input>
<input type="hidden" name="client" value="pub-9708820424478043"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="UTF-8"></input>
<input type="hidden" name="oe" value="UTF-8"></input>
<input type="hidden" name="safe" value="active"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;
<input type="hidden" name="hl" value="en"></input>
<!-- SiteSearch Google --> </div>

And adsense.php:

<div id="p-advertisement" class="portlet">
<div class="pBody">
<script type="text/javascript"><!--
google_ad_client = "pub-9708820424478043";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel ="";
<script type="text/javascript"
(All advertising revenues are donated to the <a href="

Note that I chose to keep these two files at the top level of the wiki, one directory above skins. Otherwise, you would have needed to say something like include(“includes/adsense.php”).

After making the changes, you often have to hit Shift-Reload to see the results, so as to get your browser not to just show the outdated page from its cache.