Adding Google AdSense to MediaWiki

From FVue
Jump to: navigation, search

Problem

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

Solution 1: MediaWiki extension from paulgu.com

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

Solution 2: 160x600 Skyscraper on the right

1. Create a file adsense.php in the MediaWiki root folder, containing your Google skyscraper, surrounded by a <div id=column-google>, e.g.:

<div id=column-google><script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxx";
/* 160x600, created 8/8/8 */
google_ad_slot = "xxxxxxxxxx";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

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

diff -u MonoBook.php.orig MonoBook.php                                                        
--- MonoBook.php.orig   2011-08-11 22:35:34.620688002 +0200                                                                  
+++ MonoBook.php        2011-08-11 22:36:36.970688002 +0200                                                                  
@@ -71,6 +71,7 @@                                                                                                            
                $this->html( 'headelement' );
 ?><div id="globalWrapper">
 <div id="column-content"><div id="content" <?php $this->html("specialpageattributes") ?>>
+       <?php $GLOBALS['wgOut']->mIsarticle && ! $GLOBALS['wgTitle']->mNamespace && include 'adsense.php'; ?>
        <a id="top"></a>
        <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>

3. Add css for the skyscraper to MediaWiki page MediaWiki:Common.css:

#column-google {
    width: 160px;
    clear: left;
    margin-right: -1em;
    padding: 0px 0px 6px 6px;
    float: right;
    right: 0;
    top: 10px;
}

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
WARNING: Google AdSense Unit ID "" does not exist.
Available Unit IDs: C01, C02, C03, C04, C05, C06, C07, C08, C09, C10, S01, S02, V01, V02, V03.
Example: <google uid="C01"></google>, <google uid="C01" position="left" ></google>
WARNING: Google AdSense Unit ID "" does not exist.
Available Unit IDs: C01, C02, C03, C04, C05, C06, C07, C08, C09, C10, S01, S02, V01, V02, V03.
Example: <google uid="C01"></google>, <google uid="C01" position="left" ></google>
WARNING: Google AdSense Unit ID "" does not exist.
Available Unit IDs: C01, C02, C03, C04, C05, C06, C07, C08, C09, C10, S01, S02, V01, V02, V03.
Example: <google uid="C01"></google>, <google uid="C01" position="left" ></google>

20130309

Indenting Featured Images - CodePen
Maybe use this to float an ad left halfway the page.

Comments

blog comments powered by Disqus