Extension:WimaAdvertising

From mediawiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
WimaAdvertising
Release status: stable
Implementation Skin , MyWiki , Hook
Description Ads banners defined in LocalSettings.php
Author(s) WikiMANNia (WikiForMentalk)
Latest version 2.0.0 (2021-01-25)
MediaWiki 1.25+
PHP 5.6+
License GNU General Public License 2.0 or later
Download
Example http://at.wikimannia.org
  • $wgWimaAdvertising
  • $wgWimaAdvertisingAnonOnly
  • $wgBannerTopCode
  • $wgBannerTopStyle
  • $wgBannerTopType
  • $wgBannerBottomCode
  • $wgBannerBottomStyle
  • $wgBannerBottomType
  • $wgSidebarAd1Code
  • $wgSidebarAd1Type
  • $wgSidebarAd2Code
  • $wgSidebarAd2Type

Check usage and version matrix.

The WimaAdvertising extension offers four additional advertising blocks to the Cologne Blue , Modern , MonoBook , and Vector skin. The banners are placed in the top and bottom of the wiki and two of them in the sidebar .

Use[edit]

One ad block is located at the top of the "MediaWiki:Sitenotice ", a second one below the article text in front of the category bar and two more ad blocks in the Sidebar . By entering * AD1 and * AD2 in the MediaWiki:Sidebar , these can be placed individually. If Sitenotice is defined, the TopBanner will be displayed randomly alternating with the Sitenotice message.


Installation[edit]

  • Download and place the file(s) in a directory called WimaAdvertising in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'WimaAdvertising' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration options[edit]

Enable advertising. Default is false.

$wgWimaAdvertising = true;

Disable advertising for logged-in users. Default is false.

$wgWimaAdvertisingAnonOnly = true;

wgBannerType[edit]

  • Set the type of the banner
    • Possible values: 'advertising', 'eventnote', 'hint'
    • Default value: 'advertising'
$wgBannerTopType = "eventnote";
$wgBannerBottomType = "eventnote";
$wgSidebarAd1Type = "advertising";
$wgSidebarAd2Type = "hint";
The labels above the advertising blocks will be translated into: de, en, es, fr, it, nl, pt, ru

wgBannerCode[edit]

$wgBannerTopCode = '<a title="Uhren-Wiki" href="https://www.uhren-wiki.net"><img src="https://wikimannia.org/skins/werbung/Werbung - Oben.jpg" width="728" height="92" alt="Werbung" /></a>';
$wgBannerBottomCode = '
Your banner code here.
';
$wgSidebarAd1Code = '<a title="Schwarzbuch Wikipedia" href="https://de.wikimannia.org/Schwarzbuch_Wikipedia"><img src="https://wikimannia.org/werbung/images/130px-Schwarzbuch_Wikipedia.jpg" alt="Schwarzbuch_Wikipedia.jpg" /></a> <p><b>Schwarzbuch Wikipedia</b></p><p class="small">Mobbing, Diffamierung und Falschinformation in der Online-Enzyklopädie, und was jetzt dagegen getan werden muss.</p><p>Im Februar 2020 im <i>Zeitgeist-Verlag</i> erschienen.</p>';
$wgSidebarAd2Code = 'Your banner code here.';

You can also do Google AdSense:

$wgSidebarAd2Code = '<script type="text/javascript"><!--
google_ad_client = "pub-9471398824076666";
/* ID 007 */
google_ad_slot = "3512091103";
google_ad_width = 145;
google_ad_height = 260;
google_language = "en";
google_encoding = "utf8";
// -->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';

wgBannerStyle[edit]

  • Set the CSS style specifications for the banner.
$wgBannerTopStyle = 'text-align:center;border:1px solid blue;';
$wgBannerBottomStyle = 'text-align:center;border:1px dotted red;';

Google Adsense[edit]

Version 2 with Google AdSense functionality is available for testing. Just like the Google AdSense extension, but on four possible advertising units. Version 1 is stable now, version 2 is in testing process.

Enable advertising. Default is false.

$wgWimaGoogleAdSense = true;

Disable advertising for logged-in users. Default is false.

$wgWimaGoogleAdSenseAnonOnly = true;

Mandatory parameters[edit]

// Replace this with your own publisher ID (google_ad_client / data-ad-client)
$wgWimaGoogleAdSenseClient = 'none'; // Client ID for your AdSense script (example: ca-pub-1234546403419693)

(You can get your publisher ID and ad unit ID from the "Get code" page: Get and copy the ad code.)

Ad units[edit]

Define up to four ad units:

$wgWimaGoogleAdSense_AD1= [ 'slotid 1', 145, 260 ];
$wgWimaGoogleAdSense_AD2= [ 'slotid 2', 145, 260 ];
$wgWimaGoogleAdSense_Top= [ 'slotid 3', 145, 260 ];
$wgWimaGoogleAdSense_Bottom = [ 'slotid 4', 145, 260 ];

Replace the first value with your AdSense ad unit ID (google_ad_slot / data-ad-slot) for each ad unit. The Slot ID for your AdSense script is for example 1234580893.

Also specify the width and the height of the AdSense unit, specified in your AdSense account (google_ad_width / data-ad-width, google_ad_height / data-ad-height).

Optional parameters[edit]

Add any of the optional settings below – if your settings deviate from the defaults:

// This can be anything you like. Default is 'none'.
$wgWimaGoogleAdSenseID = 'none';

// Source URL of the AdSense script. No need to change - it can't deviate from the defaults.
$wgWimaGoogleAdSenseSrc = '//pagead2.googlesyndication.com/pagead/show_ads.js';

// Text coding. Default is 'utf8'.
$wgWimaGoogleAdSenseEncoding = "utf8";

// Advertising language. Default is $wgLanguageCode.
$wgWimaGoogleAdSenseLanguage = "en";

Hacks[edit]

Skin Vector[edit]

Skin Vector in revision 1.35 needs a hack to make the extension work for the ads in the sidebar.

In file includes/VectorTemplate.php change line 450:

	$props['class'] = trim( "$class $extraClasses[$type]" );

into:

	$props['class'] = trim( "$extraClasses[$type]" );

Skin MonoBook[edit]

For the Skin MonoBook, the ad at the bottom might look better if the hook is moved to the end of the content area.

In file includes/MonoBookTemplate.php change lines 85-91:

			'<!-- end content -->' .
			$this->getClear()
		)
	);
	$html .= $this->deprecatedHookHack( 'MonoBookAfterContent' );
	$html .= $this->getIfExists( 'dataAfterContent' ) . $this->getClear();
	$html .= Html::closeElement( 'div' );

into:

			'<!-- end content -->' .
			$this->getClear() .
			$this->getIfExists( 'dataAfterContent' ) .
			$this->getClear()
		)
	);
	$html .= Html::closeElement( 'div' );

See also[edit]

  • PCR GUI Inserts did something similar since REL 1.23, but not as sophisticated.
  • Google AdSense does the same, but only for one banner. And it does not allow custom banners.