Extension:AdsWherever

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

Release status: unstable

Implementation Tag
Description Allows to place any ads wherever you want
Author(s) Wikimama (Wmamatalk)
Latest version 1.0.1 (2011-04-12)
MediaWiki 1.15+
License GNU General Public License
Download see below

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

Check usage and version matrix; code metrics

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

Usage[edit | edit source]

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 | edit source]

  • 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";
  • YesYDone - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Code[edit | edit source]

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 | edit source]