MediaWiki/Google Adsense

< MediaWiki

Google AdSense
If you're interested in running a MediaWiki site with Google AdSense, you should know that in order to comply with the Google TOS, you shouldn't display ads on non-content pages. The following solution will cause ads to not be displayed on Special, User, User talk, Image, Template, and edit/preview pages.

I've solved this by limiting my users' choice of skins to Monobook, and modifying the Monobook.php file as follows:

For a vertical ad below your left-side navigation, after this: echo htmlspecialchars($this->data['nav_urls'][$special]['href']) ?>">msg($special) ?>                          put this:        <?php          if(!strstr($_SERVER['REQUEST_URI'], "Special:") &&               !strstr($_SERVER['REQUEST_URI'], "User:") &&               !strstr($_SERVER['REQUEST_URI'], "User_talk:") &&               !strstr($_SERVER['REQUEST_URI'], "Image:") &&               !strstr($_SERVER['REQUEST_URI'], "action=submit") &&               !strstr($_SERVER['REQUEST_URI'], "action=edit") &&               !strstr($_SERVER['REQUEST_URI'], "Template:")) {            include("adsense/adsense_vertical.php");          }        ?> For a horizontal ad at the bottom of your articles, after this:            data['catlinks']) { ?> html('catlinks') ?>             &lt;!-- end content --> put this:             Now, you'll need to create an adsense/ directory in your main wiki directory, and place two files in it, adsense_horizontal.php and adsense_vertical.php as needed.

The contents of my files are as follows:

adsense_vertical.php: Advertisement Paste Google code here adsense_horizontal.php: Paste Google code here I've found that these layouts fit nicely with the Monobook skin. For the vertical ad, the 120x240 tall format ad works best.

There is a useful way to help block yourself from seeing your own adverts to prevent yourself from inadvertently clicking on them - for that see this page.