From 1839a15957bb19934ddeebc068305ceca8d09d8d Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sun, 3 Oct 2010 14:12:41 +0000 Subject: [PATCH] Add to OutputPage::headElement a OutputPageBodyAttrs hook for extensions and a bodyAttrs callback to Skin so that Extensions and Skins are able to add attributes and classes to the tag without neeing to do insane things. --- docs/hooks.txt | 8 ++++++++ includes/OutputPage.php | 3 +++ includes/Skin.php | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/docs/hooks.txt b/docs/hooks.txt index bf24518c1b..4e27541db1 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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. diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 3618f7e541..866b4e5ad0 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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; diff --git a/includes/Skin.php b/includes/Skin.php index 8fd1d73c95..0ccd2f100b 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -568,6 +568,15 @@ class Skin extends Linker { return "$numeric $type $name"; } + + /** + * This will be called by OutputPage::headElement when it is creating the + * 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 -- 2.20.1