Matmarex has uploaded a new change for review.
https://gerrit.wikimedia.org/r/59604
Change subject: separate adding body classes and other attributes in
Skin/OutputPage
......................................................................
separate adding body classes and other attributes in Skin/OutputPage
Created separate Skin::addToBodyClasses() method and
OutputPageBodyClasses hook, in addition to Skin::addToBodyAttributes()
method and OutputPageBodyAttributes hook.
Used the above in Vector and cleaned up the class building logic in
OutputPage.
Change-Id: I0d3c29ecb5e21b2649a36844bf570d14db054200
---
M docs/hooks.txt
M includes/OutputPage.php
M includes/Skin.php
M skins/Vector.php
4 files changed, 45 insertions(+), 23 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/04/59604/1
diff --git a/docs/hooks.txt b/docs/hooks.txt
index c266dcc..17b65c8 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -1611,13 +1611,17 @@
$parserOutput: the parserOutput (object) that corresponds to the page
$text: the text that will be displayed, in HTML (string)
-'OutputPageBodyAttributes': 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.
+'OutputPageBodyClasses': Called when OutputPage::headElement is creating the
+body tag to allow for extensions to add classes to the <body> element.
$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
+&$bodyClasses: An array of classes for the body tag
+
+'OutputPageBodyAttributes': Called when OutputPage::headElement is creating the
+body tag to allow for extensions to add attributes to the <body> element.
+$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, to be passed to
Html::openElement
'OutputPageCheckLastModified': when checking if the page has been modified
since the last visit.
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 8bf6443..bcc89a6 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -2501,21 +2501,32 @@
if ( $closeHead ) {
$ret .= "$closeHead\n";
}
-
- $bodyAttrs = array();
-
+
+ $bodyClasses = array();
+ $bodyClasses[] = 'mediawiki';
+
# Classes for LTR/RTL directionality support
- $bodyAttrs['class'] = "mediawiki $userdir sitedir-$sitedir";
-
+ $bodyClasses[] = $userdir;
+ $bodyClasses[] = "sitedir-$sitedir";
+
if ( $this->getLanguage()->capitalizeAllNouns() ) {
# A <body> class is probably not the best way to do
this . . .
- $bodyAttrs['class'] .= ' capitalize-all-nouns';
+ $bodyClasses[] = 'capitalize-all-nouns';
}
- $bodyAttrs['class'] .= ' ' . $sk->getPageClasses(
$this->getTitle() );
- $bodyAttrs['class'] .= ' skin-' . Sanitizer::escapeClass(
$sk->getSkinName() );
- $bodyAttrs['class'] .= ' action-' . Sanitizer::escapeClass(
Action::getActionName( $this->getContext() ) );
- $sk->addToBodyAttributes( $this, $bodyAttrs ); // Allow skins
to add body attributes they need
+ $bodyClasses[] = $sk->getPageClasses( $this->getTitle() );
+ $bodyClasses[] = 'skin-' . Sanitizer::escapeClass(
$sk->getSkinName() );
+ $bodyClasses[] = 'action-' . Sanitizer::escapeClass(
Action::getActionName( $this->getContext() ) );
+
+ // Allow skins and extensions to add body classes they need
+ $sk->addToBodyClasses( $this, $bodyClasses );
+ wfRunHooks( 'OutputPageBodyClasses', array( $this, $sk,
&$bodyClasses ) );
+
+ $bodyAttrs = array();
+ $bodyAttrs['class'] = implode( ' ', $bodyClasses );
+
+ // Allow skins and extensions to add other body attributes they
need
+ $sk->addToBodyAttributes( $this, $bodyAttrs );
wfRunHooks( 'OutputPageBodyAttributes', array( $this, $sk,
&$bodyAttrs ) );
$ret .= Html::openElement( 'body', $bodyAttrs ) . "\n";
diff --git a/includes/Skin.php b/includes/Skin.php
index 117e6e2..0f99975 100644
--- a/includes/Skin.php
+++ b/includes/Skin.php
@@ -399,7 +399,18 @@
/**
* 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.
+ * body classes of their own.
+ * @param $out OutputPage
+ * @param $bodyClasses Array
+ */
+ function addToBodyClasses( $out, &$bodyClasses ) {
+ // does nothing by default
+ }
+
+ /**
+ * 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 of their own.
* @param $out OutputPage
* @param $bodyAttrs Array
*/
diff --git a/skins/Vector.php b/skins/Vector.php
index bcfaa11..7b8110a 100644
--- a/skins/Vector.php
+++ b/skins/Vector.php
@@ -73,14 +73,10 @@
* Adds classes to the body element.
*
* @param $out OutputPage object
- * @param &$bodyAttrs Array of attributes that will be set on the body
element
+ * @param &$bodyClasses Array of classes that will be set on the body
element
*/
- function addToBodyAttributes( $out, &$bodyAttrs ) {
- if ( isset( $bodyAttrs['class'] ) && strlen(
$bodyAttrs['class'] ) > 0 ) {
- $bodyAttrs['class'] .= ' ' . implode( ' ',
static::$bodyClasses );
- } else {
- $bodyAttrs['class'] = implode( ' ',
static::$bodyClasses );
- }
+ function addToBodyClasses( $out, &$bodyClasses ) {
+ $bodyClasses += static::$bodyClasses;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/59604
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d3c29ecb5e21b2649a36844bf570d14db054200
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Matmarex <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits