SpecialNewpages: add $attribs['class'] immediately before creating <li>
[lhc/web/wiklou.git] / includes / specials / SpecialNewpages.php
index 2c39331..ede4898 100644 (file)
@@ -322,6 +322,7 @@ class SpecialNewpages extends IncludableSpecialPage {
                $rev->setTitle( $title );
 
                $classes = [];
+               $attribs = [ 'data-mw-revid' => $result->rev_id ];
 
                $lang = $this->getLanguage();
                $dm = $lang->getDirMark();
@@ -386,8 +387,6 @@ class SpecialNewpages extends IncludableSpecialPage {
                        $tagDisplay = '';
                }
 
-               $css = count( $classes ) ? ' class="' . implode( ' ', $classes ) . '"' : '';
-
                # Display the old title if the namespace/title has been changed
                $oldTitleText = '';
                $oldTitle = Title::makeTitle( $result->rc_namespace, $result->rc_title );
@@ -401,8 +400,18 @@ class SpecialNewpages extends IncludableSpecialPage {
                        );
                }
 
-               return "<li{$css}>{$time} {$dm}{$plink} {$hist} {$dm}{$length} "
-                       . "{$dm}{$ulink} {$comment} {$tagDisplay} {$oldTitleText}</li>\n";
+               $ret = "{$time} {$dm}{$plink} {$hist} {$dm}{$length} {$dm}{$ulink} {$comment} "
+                       . "{$tagDisplay} {$oldTitleText}";
+
+               // Let extensions add data
+               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";
        }
 
        /**
@@ -485,17 +494,22 @@ class SpecialNewpages extends IncludableSpecialPage {
        }
 
        protected function feedItemDesc( $row ) {
-               $revision = $this->revisionFromRcResult( $row );
-               if ( $revision ) {
-                       // XXX: include content model/type in feed item?
-                       return '<p>' . htmlspecialchars( $revision->getUserText() ) .
-                               $this->msg( 'colon-separator' )->inContentLanguage()->escaped() .
-                               htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
-                               "</p>\n<hr />\n<div>" .
-                               nl2br( htmlspecialchars( $revision->getContent()->serialize() ) ) . "</div>";
+               $revision = Revision::newFromId( $row->rev_id );
+               if ( !$revision ) {
+                       return '';
+               }
+
+               $content = $revision->getContent();
+               if ( $content === null ) {
+                       return '';
                }
 
-               return '';
+               // XXX: include content model/type in feed item?
+               return '<p>' . htmlspecialchars( $revision->getUserText() ) .
+                       $this->msg( 'colon-separator' )->inContentLanguage()->escaped() .
+                       htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
+                       "</p>\n<hr />\n<div>" .
+                       nl2br( htmlspecialchars( $content->serialize() ) ) . "</div>";
        }
 
        protected function getGroupName() {