Extension:ShoutWiki Ads

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
ShoutWiki Ads
Release status: stable
Implementation User interface
Description Displays Google AdSense ads on skins
Author(s) Jack Phoenix
Latest version 0.4.5 (2017-02-26)
MediaWiki 1.25+
License Public domain
Download
Example ShoutWiki
Parameters
$wgAdConfig
Hooks used
BeforePageDisplay
AuroraLeftSidebar
SkinAfterContent
DuskAfterToolbox
HomeAfterEverything
GamesSideBox
MetrolookRightPanel
MetrolookAfterToolbox
MonacoSetupSkinUserCss
MonacoSidebar
MonacoFooter
MonoBookAfterContent
MonoBookAfterToolbox
NimbusLeftSide
QuartzSidebarWidgets
QuartzSidebarWidgetAdvertiser
RefreshedFooter
RefreshedInSidebar
TruglassInContent
VectorAfterToolbox
VectorBeforeFooter
SiteNoticeAfter
Translate the ShoutWiki Ads extension if it is available at translatewiki.net
Check usage and version matrix.

ShoutWiki Ads extension displays Google AdSense ads on skins. Currently it supports Monobook, Vector, Nimbus, Quartz, Refreshed, Aurora, Dusk, Monaco and Truglass skins.

The extension will not display ads

  • when ads are disabled ($wgAdConfig['enabled'] = false;)
  • on the login page (Special:UserLogin)
  • on namespaces where ads are not enabled
  • for autoconfirmed users
  • if the wiki is in a language that is not supported by Google AdSense

This extension is currently very ShoutWiki-specific.

History[edit]

The reason why this extension was written was that in the past, each skin (at ShoutWiki) that should have ads needed to implement its own ad loader, which was not very easy to maintain, as it meant lots and lots of code duplication. To solve the problem, we stashed all the ad-related code into one class, and we'd just hook on the different hooks in different skins to display the ads.

Of course, the Monobook skin didn't have the hooks we needed to use, so we had to create them.

All the functions in the ShoutWikiAds class are public and static, so it's very easy to use the class.

Installation[edit]

  • Download and place the file(s) in a directory called ShoutWikiAds in your extensions/ folder.

Parameters[edit]

The extension has only one configuration variable, $wgAdConfig. It should look something like this:

$wgAdConfig = [
	'enabled' => true, // enabled or not? :P
	'adsense-client' => '', // provider number w/o the "pub-" part
	'namespaces' => [ NS_MAIN, NS_TALK ], // array of enabled namespaces
	'right-column' => true, // do we want a skyscraper ad column (Monobook)?
	'toolbox-button' => true, // or a "button" ad below the toolbox (Monobook)?
	'monaco-sidebar' => true, // 200x200 sidebar ad in the sidebar on Monaco skin
	'monaco-leaderboard' => true, // leaderboard (728x90) ad in the footer on Monaco skin
	'truglass-leaderboard' => true, // leaderboard ad for Truglass skin
];

If the enabled key is set to false, the extension will do nothing.

The adsense-client key should be set to your AdSense provider number (just the number, not the "pub-" part!).

The right-column and toolbox-button options apply only to the Monobook skin. monaco-sidebar and monaco-leaderboard options apply only to the Monaco skin, while truglass-leaderboard option applies only to the Truglass skin.