Introduced a new hook 'SkinAfterContent' that allows extensions to add text
authorLeon Weber <leon@users.mediawiki.org>
Fri, 8 Aug 2008 15:53:49 +0000 (15:53 +0000)
committerLeon Weber <leon@users.mediawiki.org>
Fri, 8 Aug 2008 15:53:49 +0000 (15:53 +0000)
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
docs/hooks.txt
includes/Skin.php
includes/SkinTemplate.php
skins/Modern.php
skins/MonoBook.php

index 42bedef..a036bcd 100644 (file)
@@ -58,6 +58,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 14921) Special:Contributions/: add user name to <title>
   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 ===
 
index 8b1fa60..7c9218a 100644 (file)
@@ -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
index b09bed1..b065217 100644 (file)
@@ -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}'>&nbsp;</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\>
index 0f16c69..89b0f69 100644 (file)
@@ -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();
index b406743..a7c29a5 100644 (file)
@@ -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 -->
index a96a147..a79825f 100644 (file)
@@ -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>