Add to OutputPage::headElement a OutputPageBodyAttrs hook for extensions and a bodyAt...
authorDaniel Friesen <dantman@users.mediawiki.org>
Sun, 3 Oct 2010 14:12:41 +0000 (14:12 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Sun, 3 Oct 2010 14:12:41 +0000 (14:12 +0000)
docs/hooks.txt
includes/OutputPage.php
includes/Skin.php

index bf24518..4e27541 100644 (file)
@@ -1193,6 +1193,14 @@ the resulting HTML is about to be displayed.
 $parserOutput: the parserOutput (object) that corresponds to the page
 $text: the text that will be displayed, in HTML (string)
 
+'OutputPageBodyAttrs': called when OutputPage::headElement is creating the body
+tag to allow for extensions to add attributes to the body of the page they might
+need. Or to allow building extensions to add body classes that aren't of high
+enough demand to be included in core.
+$out: The OutputPage which called the hook, can be used to get the real title
+$sk: The Skin that called OutputPage::headElement
+&$bodyAttrs: An array of attributes for the body tag passed to Html::openElement
+
 'OutputPageCheckLastModified': when checking if the page has been modified
 since the last visit
 &$modifiedTimes: array of timestamps.
index 3618f7e..866b4e5 100644 (file)
@@ -2276,6 +2276,9 @@ class OutputPage {
                $bodyAttrs['class'] .= ' ' . Sanitizer::escapeClass( 'page-' . $this->getTitle()->getPrefixedText() );
                $bodyAttrs['class'] .= ' skin-' . Sanitizer::escapeClass( $wgUser->getSkin()->getSkinName() );
 
+               $sk->bodyAttributes( $this, $bodyAttrs ); // Allow skins to add body attributes they need
+               wfRunHooks( 'OutputPageBodyAttrs', array( $this, $sk, &$bodyAttrs ) );
+
                $ret .= Html::openElement( 'body', $bodyAttrs ) . "\n";
 
                return $ret;
index 8fd1d73..0ccd2f1 100644 (file)
@@ -568,6 +568,15 @@ class Skin extends Linker {
 
                return "$numeric $type $name";
        }
+       
+       /**
+        * This will be called by OutputPage::headElement when it is creating the
+        * <body> tag, skins can override it if they have a need to add in any
+        * body attributes or classes of their own.
+        */
+       function bodyAttributes( $out, &$bodyAttrs ) {
+               // does nothing by default
+       }
 
        /**
         * URL to the logo