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

Release status: unstable

Implementation Tag
Description Display Ads wherever with a tag <ads>
Author(s) Wikimama
Latest version 1 (2011-04-12)
MediaWiki 1.15
License GNU General Public License
Download see below
Example http://www.wikimama.com

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

Check usage and version matrix; code metrics

AdsWherever is a very simple extension that displays any advertising codes on your wiki page.

Source[edit | edit source]

Copy the following code into extensions/AdsWherever.php:

$wgExtensionCredits['parserhook'][] = array(
        'name' => 'AdsWherever',
        'description' => 'Place any ads wherever you want',
        'author' => 'Wikimama',
        'url' => 'http://www.wikimama.com'

$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="http://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];

Installation[edit | edit source]

  • Create the file AdsWherever.php and paste the code shown above. Make sure there are no empty lines after the final php exit tag.
  • Upload adswherever.php to your $IP/extensions directory.
  • Add the following lines at the end of LocalSettings.php:

Usage[edit | edit source]

After you set the variable in $ad['name'], 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.

See also[edit | edit source]