Extension:AdsWherever

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear app error.png
AdsWherever

Release status:Extension status unstable

ImplementationTemplate:Extension#type Tag
DescriptionTemplate:Extension#description Allows to place any ads wherever you want
Author(s)Template:Extension#username Wikimama (Wmamatalk)
Latest versionTemplate:Extension#version 1.0.1 (2011-04-12)
MediaWikiTemplate:Extension#mediawiki 1.15+
LicenseTemplate:Extension#license GNU General Public License
Download see below

Translate the AdsWherever extension if it is available at translatewiki.net

Check usage and version matrix.

The AdsWherever extension displays any advertising codes on your wiki page.

Usage[edit]

After setting the variable in $ad['name'] (see the code), insert a tag into anywhere of your page. Here is an example to insert the Google Adsense code:

To insert this tag:

<ads media=Goo1>

It will show the whole Google Adsense code.

Also try

<ads media=example /> 

where it shows the "Hello World" example as above.

Installation[edit]

  • Copy the code into a file and place the file(s) in a directory called AdsWherever in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/AdsWherever/AdsWherever.php";
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Code[edit]

AdsWherever.php
<?php
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'AdsWherever',
        'version' => '1.0.1',
        'description' => 'Allows to place any ads wherever you want',
        'author' => 'Wikimama',
        'url' => 'https://www.mediawiki.org/wiki/Extension:AdsWherever'
);

$wgHooks['ParserFirstCallInit'][] = 'AdsSetup';
 
function AdsSetup( &$parser ) {
	$parser->setHook( 'ads', 'AdsRender' );
       return true;
}

function AdsRender($input, $args ) {	
$input =""; 
$url = array();	
// Google Adsense Example
$ad['goo1']  = '<div class="thumbnail"><div id="ads">'."\n";
$ad['goo1'] .= '<script type="text/javascript"><!--'."\n";
$ad['goo1'] .= 'google_ad_client = "Your Publisher ID";'."\n";
$ad['goo1'] .= 'google_ad_slot = "The Ads slot number";'."\n";
$ad['goo1'] .='google_ad_width = ;'."\n";
$ad['goo1'] .= 'google_ad_height = ;'."\n";
$ad['goo1'] .= '//-->'."\n";
$ad['goo1'] .= '</script>'."\n";
$ad['goo1'] .= '<script type="text/javascript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js">'."\n";
$ad['goo1'] .= '</script>'."\n";
$ad['goo1'] .= '</div></div>';

// Commission Junction Example
$ad['code1']  = '<a href="http://www.example.com/123" target="_blank">';
$ad['code1'] .= '<img src="http://www.example.com/123.gif" width="190" height="190" /></a>';

// Commission Junction Example
$ad['example']  = '<a href="http://www.google.com">';
$ad['example'] .= 'Hello world</a>';

$media = $args['media'];
return $ad[$media];
}

See also[edit]