From 42ba9ea516beb06969bd3e579aa506821629ecb8 Mon Sep 17 00:00:00 2001 From: Zhuyifei1999 Date: Fri, 18 Aug 2017 08:01:02 +0000 Subject: [PATCH] SpecialNewpages: add $attribs['class'] immediately before creating
  • The call to `wfArrayFilterByKey` / `isReservedDataAttribute` removes all attributes that are not reserved (`/^data-(ooui|mw|parsoid)/i`). The `class` attribute is not reserved, and is therefore unfortunately removed. Moving the addition of $attribs['class'] will allow overriding of the sanitizer, and actually add the attribute. It is also moved below the Hooks::run call so that extensions can effectively add the classes, and SpecialNewpages will not disregard the changes to `$classes` from hooks. This behaviour / placement is consistent with other calls to `wfArrayFilterByKey` / `isReservedDataAttribute`, such as `OldChangesList`, `DeletedContribsPager`, and `ContribsPager`. Bug: T173556 Change-Id: I40e5e98228dae79a2de39efc28091cc9f69f64ea --- includes/specials/SpecialNewpages.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/specials/SpecialNewpages.php b/includes/specials/SpecialNewpages.php index e3b73a98b0..ede4898321 100644 --- a/includes/specials/SpecialNewpages.php +++ b/includes/specials/SpecialNewpages.php @@ -391,10 +391,6 @@ class SpecialNewpages extends IncludableSpecialPage { $oldTitleText = ''; $oldTitle = Title::makeTitle( $result->rc_namespace, $result->rc_title ); - if ( count( $classes ) ) { - $attribs['class'] = implode( ' ', $classes ); - } - if ( !$title->equals( $oldTitle ) ) { $oldTitleText = $oldTitle->getPrefixedText(); $oldTitleText = Html::rawElement( @@ -411,6 +407,10 @@ class SpecialNewpages extends IncludableSpecialPage { Hooks::run( 'NewPagesLineEnding', [ $this, &$ret, $result, &$classes, &$attribs ] ); $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] ); + if ( count( $classes ) ) { + $attribs['class'] = implode( ' ', $classes ); + } + return Html::rawElement( 'li', $attribs, $ret ) . "\n"; } -- 2.20.1