Manual:Hooks/SkinAfterPortlet

SkinAfterPortlet
Available from version 1.35.0
Occurs whenever a page is rendered and allows the addition of HTML after portlets have been put out.
Define function:
public static function onSkinAfterPortlet( $skin, $portletName, &$html ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"SkinAfterPortlet": "MediaWiki\\Extension\\MyExtension\\Hooks::onSkinAfterPortlet"
	}
}
Called from: File(s): skins/Skin.php
Interface: SkinAfterPortletHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:SkinAfterPortlet extensions.


Allow custom HTML to be injected after the section after the portlets' output. Any use of the hook needs to handle escaping. Note that if the portlet is empty and $html is nonempty, the portlet will be rendered.

Details

edit
  • $skin: Skin
  • $portletName: string portlet name
  • &$html: string The HTML code to display. It will be wrapped into a div tag, but apart from that, it will be outputted directly into the page.
Escape dangerous signs in HTML!

Example

edit

This example will place an ad in the sidebar following the Toolbox ("tb") portlet. Replace the data-ad-client and data-ad-slot with your values.

$wgHooks['SkinAfterPortlet'][] = function($skin, $portletName, &$html) {
    $user = $skin->getUser();
    if ($user->isRegistered() && $portletName === "tb") {
        $html = <<< EOT
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
                <ins class="adsbygoogle"
                     style="display:inline-block;width:160px;height:1000px;margin:20px 0 0 -20px;"
                     data-ad-client="ca-pub-00000000000000"
                     data-ad-slot="000000000">
                </ins>
        <script>
                (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
        EOT;
        return true;
    }
};