SpecialNewpages: add $attribs['class'] immediately before creating <li>
authorZhuyifei1999 <zhuyifei1999@gmail.com>
Fri, 18 Aug 2017 08:01:02 +0000 (08:01 +0000)
committerZhuyifei1999 <zhuyifei1999@gmail.com>
Fri, 18 Aug 2017 08:01:02 +0000 (08:01 +0000)
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

index e3b73a9..ede4898 100644 (file)
@@ -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";
        }