Search code examples
phpmediawikigoogle-dfp

Using ads and banners on MediaWiki


How do I add a banner (728x90) or ads using Google's DoubleClick for Publishers (DFP) on the header and footer sections of all pages in MediaWiki?

Please any one help me.

Thanks in advance.


Solution

  • There are a number of existing advertisement extensions for MediaWiki that may suit your needs, or at least serve as examples of how it can be done.

    There are a few different ways to inject ad banners into a MediaWiki skin:

    • Edit the skin template itself (e.g. skins/Vector.php for the Vector skin) and add the banner code in a suitable location. This is a fairly quick and easy solution, but suffers from the problem that you'll need to redo it every time you upgrade MediaWiki (or upgrade your skin, if you're using a non-standard one).

    • Find a suitable hook to inject the banner code into the skin. If you're just doing this for your own wiki, you can simply write the hook code directly into your LocalSettings.php (or into a separate PHP file that you include from there, if you prefer), but you could also turn it into a full MediaWiki extension (which basically just means, at a minimum, putting it in a separate file and adding a bit of boilerplate code).

      Alas, finding the right hook for the job may not always be trivial. For injecting ads into the sidebar, the SkinBuildSidebar hook may be convenient; SkinAfterContent might work for footer ads, and for top ads, you could maybe (ab)use the SiteNoticeAfter hook.

    • Create a parser tag extension that allows you to add a custom tag like <adshere/> to your pages to inject the ad banner code at that location. Straightforward, but requires you put the tag on any page that you want ads on (or in an interface message, if you can find a suitable one; tip: try appending the parameter uselang=qqx to URLs to see which messages are used where).

    • Find a suitably located interface message which is treated as raw HTML, and put your ad code there directly. Alas, there aren't many such messages, and the trend is towards getting rid of the few that are left.

    • For ads that can be injected with JavaScript only, you can simply put the code in MediaWiki:Common.js (or in the appropriate skin-specific JS page).