r38910 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38909‎ | r38910 | r38911 >
Date:15:53, 8 August 2008
Author:leon
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/skins/Modern.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/MonoBook.php
@@ -121,6 +121,7 @@
122122 <?php $this->html('bodytext') ?>
123123 <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
124124 <!-- end content -->
 125+ <?php if($this->data['dataAfterContent']) { $this->html ('dataAfterContent'); } ?>
125126 <div class="visualClear"></div>
126127 </div>
127128 </div>
Index: trunk/phase3/skins/Modern.php
@@ -156,6 +156,7 @@
157157 <?php $this->html('bodytext') ?>
158158 <div class='mw_clear'></div>
159159 <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
 160+ <?php $this->html ('dataAfterContent') ?>
160161 </div><!-- mw_contentholder -->
161162 </div><!-- mw_content -->
162163 </div><!-- mw_contentwrapper -->
Index: trunk/phase3/docs/hooks.txt
@@ -1078,6 +1078,12 @@
10791079 &$text: bottomScripts Text
10801080 Append to $text to add additional text/scripts after the stock bottom scripts.
10811081
 1082+'SkinAfterContent': Allows extensions to add text after the page content and
 1083+article metadata.
 1084+&$data: (string) Text to be printed out directly (without parsing)
 1085+This hook should work in all skins. Just set the &$data variable to the text
 1086+you're going to add.
 1087+
10821088 'SkinBuildSidebar': At the end of Skin::buildSidebar()
10831089 $skin: Skin object
10841090 &$bar: Sidebar contents
Index: trunk/phase3/includes/SkinTemplate.php
@@ -455,6 +455,10 @@
456456 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
457457 }
458458
 459+ // allow extensions adding stuff after the page content.
 460+ // See Skin::afterContentHook() for further documentation.
 461+ $tpl->set ('dataAfterContent', $this->afterContentHook());
 462+
459463 // execute template
460464 wfProfileIn( __METHOD__."-execute" );
461465 $res = $tpl->execute();
Index: trunk/phase3/includes/Skin.php
@@ -282,6 +282,9 @@
283283
284284 $out->out( $out->mBodytext . "\n" );
285285
 286+ // See self::afterContentHook() for documentation
 287+ $out->out ($this->afterContentHook());
 288+
286289 $out->out( $this->afterContent() );
287290
288291 $out->out( $this->bottomScripts() );
@@ -753,6 +756,43 @@
754757 }
755758
756759 /**
 760+ * This runs a hook to allow extensions placing their stuff after content
 761+ * and article metadata (e.g. categories).
 762+ * Note: This function has nothing to do with afterContent().
 763+ *
 764+ * This hook is placed here in order to allow using the same hook for all
 765+ * skins, both the SkinTemplate based ones and the older ones, which directly
 766+ * use this class to get their data.
 767+ *
 768+ * The output of this function gets processed in SkinTemplate::outputPage() for
 769+ * the SkinTemplate based skins, all other skins should directly echo it.
 770+ *
 771+ * Returns an empty string by default, if not changed by any hook function.
 772+ */
 773+ protected function afterContentHook () {
 774+ $data = "";
 775+
 776+ if (wfRunHooks ('SkinAfterContent', array (&$data))) {
 777+ // adding just some spaces shouldn't toggle the output
 778+ // of the whole <div/>, so we use trim() here
 779+ if (trim ($data) != "") {
 780+ // Doing this here instead of in the skins to
 781+ // ensure that the div has the same ID in all
 782+ // skins
 783+ $data = "<!-- begin SkinAfterContent hook -->\n" .
 784+ "<div id='mw-data-after-content'>\n" .
 785+ "\t$data\n" .
 786+ "</div>\n" .
 787+ "<!-- end SkinAfterContent hook -->\n";
 788+ }
 789+ } else {
 790+ wfDebug ('Hook SkinAfterContent changed output processing.');
 791+ }
 792+
 793+ return $data;
 794+ }
 795+
 796+ /**
757797 * This gets called shortly before the \</body\> tag.
758798 * @return String HTML to be put before \</body\>
759799 */
Index: trunk/phase3/RELEASE-NOTES
@@ -58,6 +58,9 @@
5959 * (bug 14921) Special:Contributions/: add user name to <title>
6060 Patch by Emufarmers
6161 * Unescape more "safe" characters when producing URLs, for added prettiness
 62+* Introduced a new hook 'SkinAfterContent' that allows extensions to add text
 63+ after the page content and article metadata. Updated all skins and skin
 64+ templates to work with that hook.
6265
6366 === Bug fixes in 1.14 ===
6467

Status & tagging log