From 5ae0f26b1e701e3e27c860fb47e27e7d3f44fbdc Mon Sep 17 00:00:00 2001 From: Leon Weber Date: Fri, 8 Aug 2008 15:53:49 +0000 Subject: [PATCH] Introduced a new hook 'SkinAfterContent' that allows extensions to add text after the page content and article metadata. Updated all skins and skin templates to work with that hook. The hook is added in the newly introduced Skin::hookAfterContent(). It couldn't be implemented anywhere else as we want to be able using a single hook in all skins: Some skins are based on SkinTemplate (e.g. MonoBook), while some directly extend the Skin class (like CologneBlue). The Skin based ones collect their output from several functions from Skin class, while SkinTemplate prepares an array with all the needed data and passes it to the skins using it. Thus we had to create said new protected function for running that hook. SkinTemplate pushes the function's output into the data array. The Skin class based skins directly use the function's output. --- RELEASE-NOTES | 3 +++ docs/hooks.txt | 6 ++++++ includes/Skin.php | 40 +++++++++++++++++++++++++++++++++++++++ includes/SkinTemplate.php | 4 ++++ skins/Modern.php | 1 + skins/MonoBook.php | 1 + 6 files changed, 55 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 42bedefd65..a036bcd737 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -58,6 +58,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 14921) Special:Contributions/: add user name to Patch by Emufarmers * Unescape more "safe" characters when producing URLs, for added prettiness +* Introduced a new hook 'SkinAfterContent' that allows extensions to add text + after the page content and article metadata. Updated all skins and skin + templates to work with that hook. === Bug fixes in 1.14 === diff --git a/docs/hooks.txt b/docs/hooks.txt index 8b1fa600ac..7c9218aafc 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1078,6 +1078,12 @@ $skin: Skin object &$text: bottomScripts Text Append to $text to add additional text/scripts after the stock bottom scripts. +'SkinAfterContent': Allows extensions to add text after the page content and +article metadata. +&$data: (string) Text to be printed out directly (without parsing) +This hook should work in all skins. Just set the &$data variable to the text +you're going to add. + 'SkinBuildSidebar': At the end of Skin::buildSidebar() $skin: Skin object &$bar: Sidebar contents diff --git a/includes/Skin.php b/includes/Skin.php index b09bed1abf..b065217a40 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -282,6 +282,9 @@ class Skin extends Linker { $out->out( $out->mBodytext . "\n" ); + // See self::afterContentHook() for documentation + $out->out ($this->afterContentHook()); + $out->out( $this->afterContent() ); $out->out( $this->bottomScripts() ); @@ -752,6 +755,43 @@ END; return "<td width='152' rowspan='{$rows}'> </td>"; } + /** + * This runs a hook to allow extensions placing their stuff after content + * and article metadata (e.g. categories). + * Note: This function has nothing to do with afterContent(). + * + * This hook is placed here in order to allow using the same hook for all + * skins, both the SkinTemplate based ones and the older ones, which directly + * use this class to get their data. + * + * The output of this function gets processed in SkinTemplate::outputPage() for + * the SkinTemplate based skins, all other skins should directly echo it. + * + * Returns an empty string by default, if not changed by any hook function. + */ + protected function afterContentHook () { + $data = ""; + + if (wfRunHooks ('SkinAfterContent', array (&$data))) { + // adding just some spaces shouldn't toggle the output + // of the whole <div/>, so we use trim() here + if (trim ($data) != "") { + // Doing this here instead of in the skins to + // ensure that the div has the same ID in all + // skins + $data = "<!-- begin SkinAfterContent hook -->\n" . + "<div id='mw-data-after-content'>\n" . + "\t$data\n" . + "</div>\n" . + "<!-- end SkinAfterContent hook -->\n"; + } + } else { + wfDebug ('Hook SkinAfterContent changed output processing.'); + } + + return $data; + } + /** * This gets called shortly before the \</body\> tag. * @return String HTML to be put before \</body\> diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 0f16c694e2..89b0f690d8 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -455,6 +455,10 @@ class SkinTemplate extends Skin { wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' ); } + // allow extensions adding stuff after the page content. + // See Skin::afterContentHook() for further documentation. + $tpl->set ('dataAfterContent', $this->afterContentHook()); + // execute template wfProfileIn( __METHOD__."-execute" ); $res = $tpl->execute(); diff --git a/skins/Modern.php b/skins/Modern.php index b4067433c0..a7c29a5480 100644 --- a/skins/Modern.php +++ b/skins/Modern.php @@ -156,6 +156,7 @@ class ModernTemplate extends QuickTemplate { <?php $this->html('bodytext') ?> <div class='mw_clear'></div> <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?> + <?php $this->html ('dataAfterContent') ?> </div><!-- mw_contentholder --> </div><!-- mw_content --> </div><!-- mw_contentwrapper --> diff --git a/skins/MonoBook.php b/skins/MonoBook.php index a96a14785c..a79825f13d 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -121,6 +121,7 @@ class MonoBookTemplate extends QuickTemplate { <?php $this->html('bodytext') ?> <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?> <!-- end content --> + <?php if($this->data['dataAfterContent']) { $this->html ('dataAfterContent'); } ?> <div class="visualClear"></div> </div> </div> -- 2.20.1