CSO SiteAd tag and extension
Note: Despite how they may appear on this Web page, the PHP strings shown in the examples must actually appear on a single line. Line breaks are not permitted within a string literal.
The CSO_SiteAd extension allows you to put ads—forms, Javascript, HTML—safely inside a <CSO_SiteAd> tag for use on your MediaWiki pages. It can handle Google AdSense, PayPal, and most other types of advertisements. CSO_SiteAd has two levels of security—the page must be protected and the site ad id must be known to the CSO_SiteAd extension.
CSO_SiteAd tag usage example:
<CSO_SiteAd>PayPal</CSO_SiteAd>
First, for each ad, you must add an entry in the $siteAds associative array, like this:
[php] $siteAds["MyAd"] = "HTML-for-MyAd";
Each entry must have a unique id—e.g., "MyAd"— and the HTML text of the ad must be all on one line and must not contain comments (<!-- -->). You should delete the ads which are already in the array as examples. Remember to escape (\) any quotation marks within the string.
To register the extension, add this line to <mediawikihome>/LocalSettings.php:
include ("extensions/CSO_SiteAd.php");
And, place the CSO_SiteAd extension in the <mediawikihome>/extensions directory.
<?php # CSO_SiteAd - extension to allow site ads. # CSharp-Online.NET (C) 2006 Chang & Wagers Associates # The text between the tags is used as a key to look up the # ad string in an associative array named $siteAds. # To ad your own ad, simply add an array entry, # e.g., $siteAds["MyAd"] = "my-ad-string"; # "my-ad-string" is the HTML markup provided by the advertiser. # DON'T forget to escape any quotes in "my-ad-string", e.g. "\"". # Usage: <CSO_SiteAd>ad-name-string</CSO_SiteAd> # Note: To prevent abuse, CSO_SiteAd supports ads only on protected pages. # # To activate the extension, add this line to LocalSettings.php: # include("extensions/CSO_SiteAd.php"); //Add the hook function call to an array defined earlier in wiki code execution. $wgExtensionFunctions[] = "wfCSO_SiteAd"; // Register the tag and associated callback function with the Wiki parser. function wfCSO_SiteAd() { # register the extension with the WikiText parser global $wgParser; $wgParser->setHook ( "CSO_SiteAd", "CSO_SiteAd" ); } # Callback function to render text from between tags to article function CSO_SiteAd ($CSO_SiteAd) { global $wgTitle; $errorMessage = "<!-- CSO_SiteAd: invalid site. -->"; $siteAds["SiteGround"] = "<a href=\"http://www.siteground.com/\" onClick=\"this.href='http://siteground.com/atrack.php?referrerid=22955'\" target=\"offsite\"><img src=\"http://www.siteground.com/images/468x60_2.gif\" alt=\"Web hosting services\" width=468 height=60 border=0></a>"; $siteAds["PayPal"] = "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\"><input type=\"hidden\" name=\"cmd\" value=\"_s-xclick\"><input type=\"image\" src=\"https://www.paypal.com/en_US/i/btn/x-click-but21.gif\" border=\"0\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\"><input type=\"hidden\" name=\"encrypted\" value=\"-----BEGIN PKCS7----- MIIHHgYJKoZIhvcNAQcEoIIHDzCCBwsCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1 ... hL5efb0wQ4RKt4XIIPemoKYi0=-----END PKCS7-----\"></form>"; if( ($wgTitle->isProtected ('edit')) ) { if ($siteAds[$CSO_SiteAd]) { return $siteAds[$CSO_SiteAd]; } } return $errorMessage; } ?>