Adding Google AdSense to MediaWiki

From FVue

Jump to: navigation, search

Contents

Problem

I want to add a Google AdSense banner to my MediaWiki.

Solution

Install this MediaWiki extension from Mediawiki Extensions - PaulGu dot com.

I made these modifications:

$> diff -h GoogleAdSense.php.orig GoogleAdSense.php
119,120c119,120
<         if($input == $channelName) {
<             if ($channelName == "REF") {
---
>         if ($input == $channelName) {
>             if ($channelName == "ref") {
123c123
<                 $output = gAdSenseforContent468($clientID, $channelID );
---
>                 $output = gAdSenseforContent728($clientID, $channelID );
159c159
<         "google_ad_type = \"text_image\";\n" .
---
>         "google_ad_type = \"text\";\n" .

The extension allows for the following tags:

  • <google>ref</google>
  • <google>wiki</google>
  • <google/>
  • Advantages

    • The skyscraper 'floats' in the content area, thus not limiting page width under the skyscraper

    Drawbacks

    • The edit-area appears below the advertising sky-scraper. But since I'm the only one editing - with advertising disabled - I don't bother.

    See also

    Google AdSense in Wiki - How2Setup

    Journal

    20061018

    I am running MediaWiki-1.6.7. I tried the setup underneath for a 160x600 skyscraper, but eventually wasn't satisfied: enlarging the left area feels like making to much concessions to advertising.

    1. Create a file called adsense.php in your wiki directory:

    <script type="text/javascript"><!--
    google_ad_client = "pub-xxxxxxxxxxxxxxxx";
    google_ad_width = 160;
    google_ad_height = 600;
    google_ad_format = "160x600_as";
    google_ad_type = "text";
    //2006-10-17: LeftNavGray
    google_ad_channel = "xxxxxxxxxx";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    

    2. Modify ./wiki/skins/MonoBook.php like this:

    --- MonoBook.orig.php   2006-10-17 18:41:41.000000000 +0200
    +++ MonoBook.php        2006-10-18 07:09:26.000000000 +0200
    @@ -219,12 +219,16 @@
    
                    wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
     ?>
                            </ul>
                    </div>
            </div>
    +       <br/>
    +       <div class="portlet" style="text-align: center; width: 160px">
    +       <?php include 'adsense.php'; ?>
    +       </div>
     <?php
                    if( $this->data['language_urls'] ) { ?>
            <div id="p-lang" class="portlet">
                    <h5><?php $this->msg('otherlanguages') ?></h5>
                    <div class="pBody">
                            <ul>
    

    3. Modify ./wiki/skins/monobook/main.css to enlarge space to the left of the content-area to 13.2 em:

    *** main.orig.css       2006-10-18 07:15:02.000000000 +0200
    --- main.css    2006-10-17 23:52:20.000000000 +0200
    ***************
    *** 12,22 ****
      #column-content {
            width: 100%;
            float: right;
    !       margin: 0 0 .6em -12.2em;
            padding: 0;
      }
      #content {
    !       margin: 2.8em 0 0 12.2em;
            padding: 0 1em 1.5em 1em;
            background: white;
            color: black;
    --- 12,22 ----
      #column-content {
            width: 100%;
            float: right;
    !       margin: 0 0 .6em -13.2em;
            padding: 0;
      }
      #content {
    !       margin: 2.8em 0 0 13.2em;
            padding: 0 1em 1.5em 1em;
            background: white;
            color: black;
    

    2007

    1. Create a file called adsense.php in your wiki directory:

    <? if ($_SERVER['REMOTE_ADDR'] != 'your.ip.address.here') { ?>
    <div id=column-google>
    <script type="text/javascript"><!--
    google_ad_client = "pub-xxxxxxxxxxxxxxxx";
    google_ad_width = 120;
    google_ad_height = 600;
    google_ad_format = "120x600_as";
    google_ad_type = "text";
    //2006-10-17: LeftNavGray
    google_ad_channel = "xxxxxxxxx";
    google_color_border = "B4D0DC";
    google_color_bg = "ECF8FF";
    google_color_link = "0000CC";
    google_color_url = "008000";
    google_color_text = "6F6F6F";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </div>
    <? } // if ?>
    

    2. Modify ./wiki/skins/MonoBook.php to include AdSense only when an article is viewed and when the article isn't a category:

    --- w/skins/MonoBook.orig.php   2006-10-17 18:41:41.000000000 +0200
    +++ w/skins/MonoBook.php        2006-11-03 21:56:45.000000000 +0100
    @@ -91,6 +91,7 @@
            <div id="globalWrapper">
                    <div id="column-content">
            <div id="content">
    +               <?php $GLOBALS['wgOut']->mIsarticle && ! $GLOBALS['wgTitle']->mNamespace && include 'adsense.php'; ?>
                    <a name="top" id="top"></a>
                    <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
                    <h1 class="firstHeading"><?php $this->text('title') ?></h1>
    

    3. Add formatting code to ./wiki/skins/monobook/main.css for the column-google:

    --- main.orig.css       2006-10-18 07:15:02.000000000 +0200
    +++ main.css    2006-11-03 22:03:23.000000000 +0100
    @@ -9,6 +9,16 @@
     ** All you guys rock :)
     */
    
    +#column-google {
    +    width: 120px;
    +    clear: left;
    +    margin-right: -1em;
    +    padding: 0px 0px 6px 6px;
    +    float: right;
    +    right: 0;
    +    top: 10px;
    +}
    +
     #column-content {
            width: 100%;
            float: right;
    

    20070911

    Adding AdSense to MediaWiki
    Wiki page showing you how to add AdSense to the left and the bottom of your MediaWiki
    Mediawiki Extensions - PaulGu dot com
    MediaWiki extension for showing adSense inside articles

    Personal tools
    Google