Extension:Google AdSense 2

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Google AdSense

Release status: stable

Extensions-GoogleAdSense2.png
Implementation Skin
Description Adds GoogleAdSense to the sidebar
Author(s) Siebrand Mazeland (SiebrandTalk)
Last version 1.1 (2008-11-27)
MediaWiki 1.14 or newer
License MIT
Download Download snapshot
Subversion [Help]

Browse source code
View code changes

Example translatewiki.net, and GT5-Tuning.com
Parameters

$wgGoogleAdSenseClient, $wgGoogleAdSenseSlot, $wgGoogleAdSenseID, $wgGoogleAdSenseWidth, $wgGoogleAdSenseHeight, $wgGoogleAdSenseSrc, $wgGoogleAdSenseAnonOnly

Hooks used
SkinBuildSidebar

Check usage (experimental)

Contents

[edit] Description

Enables easy addition of Google AdSense advertisements to a MediaWiki instance. See screenshot and Installation for details. This extension requires an account with Google's AdSense.

[edit] Installation

  • Download the extension
  • Add the following lines to your LocalSettings.php (replace the text where directed), putting any $wgGoogle... globals after the require_once statement:
require_once( "$IP/extensions/GoogleAdSense/GoogleAdSense.php" );
$wgGoogleAdSenseClient = 'replace this with the client name';
$wgGoogleAdSenseSlot = 'replace this with the slot name';
$wgGoogleAdSenseID = 'replace this with your ID';

Example settings

$wgGoogleAdSenseClient = 'pub-8330046405419293';
$wgGoogleAdSenseSlot = '1640430293';
$wgGoogleAdSenseID = 'yourwiki-2';
  • Add any of the optional settings below, if your settings deviate from the defaults
// Width of the AdSense box, specified in your AdSense account
$wgGoogleAdSenseWidth  = 120;
// Height of the AdSense box, specified in your AdSense account
$wgGoogleAdSenseHeight = 240;
// Source URL of the AdSense script
$wgGoogleAdSenseSrc    = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
// Show the AdSense box only for anonymous users
$wgGoogleAdSenseAnonOnly = true;
/* Pad Google AdSense box in portlet in sidebar */
#p-googleadsense .pBody {
    padding-top: 5px;
    text-align:  center;
}
  • Found pBody not working but .body does
  • If you want to add a "Text/image, 200x200" into the vector skin you will need to shift the left panel over slightly. Add the following to the MediaWiki:Vector.css page
#content, #footer { margin-left: 11em; }
#left-navigation  { left: 11em; }
  • The description (label) of the portlet can be changed in [[MediaWiki:Googleadsense]]. Defaults to "Google AdSense".

[edit] How to install on Mediawiki prior to 1.14

Note: This is not official code and it was tested on 1.13 mediawiki only. Use it at your own risk!

Open ./include/Skin.php file and find buildSidebar function at the end.

Insert next code

// Port from 1.15
wfRunHooks('SkinBuildSidebar', array($this, &$bar));

prior to

if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );

And ads should work.

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox