Use Html:rawElement() where possible in special pages.
authorC. Scott Ananian <cscott@cscott.net>
Fri, 26 Oct 2018 17:04:36 +0000 (13:04 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Fri, 26 Oct 2018 17:52:22 +0000 (13:52 -0400)
Gently discourage building HTML by raw string concatenation.

Fixes for Special{Contributions/Recentchanges*/Undelete/Upload}.

Change-Id: I4a128e902dcce93372b2f188a1f37223c58ebe9a

includes/specials/SpecialContributions.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialRecentchangeslinked.php
includes/specials/SpecialUndelete.php
includes/specials/SpecialUpload.php

index 63b64ea..43c7d29 100644 (file)
@@ -744,7 +744,9 @@ class SpecialContributions extends IncludableSpecialPage {
 
                $explain = $this->msg( 'sp-contributions-explain' );
                if ( !$explain->isBlank() ) {
-                       $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>";
+                       $form .= Html::rawElement(
+                               'p', [ 'id' => 'mw-sp-contributions-explain' ], $explain->parse()
+                       );
                }
 
                $form .= Xml::closeElement( 'form' );
index 170f792..01ad657 100644 (file)
@@ -800,7 +800,11 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                $note = '';
                $msg = $this->msg( 'rclegend' );
                if ( !$msg->isDisabled() ) {
-                       $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
+                       $note .= Html::rawElement(
+                               'div',
+                               [ 'class' => 'mw-rclegend' ],
+                               $msg->parse()
+                       );
                }
 
                $lang = $this->getLanguage();
@@ -898,14 +902,21 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                $datenow = $lang->userDate( $timestamp, $user );
                $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
 
-               $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
-                       ->parse() . '</span>';
+               $rclinks = Html::rawElement(
+                       'span',
+                       [ 'class' => 'rclinks' ],
+                       $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )->parse()
+               );
 
-               $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
-                       $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
-                       [ 'from' => $timestamp ],
-                       $nondefaults
-               ) . '</span>';
+               $rclistfrom = Html::rawElement(
+                       'span',
+                       [ 'class' => 'rclistfrom' ],
+                       $this->makeOptionsLink(
+                               $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
+                               [ 'from' => $timestamp ],
+                               $nondefaults
+                       )
+               );
 
                return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
        }
index 181b4db..e42cc70 100644 (file)
@@ -297,15 +297,19 @@ class SpecialRecentChangesLinked extends SpecialRecentChanges {
                $targetTitle = $this->getTargetTitle();
                if ( $targetTitle === false ) {
                        $this->getOutput()->addHTML(
-                               '<div class="mw-changeslist-empty mw-changeslist-notargetpage">' .
-                               $this->msg( 'recentchanges-notargetpage' )->parse() .
-                               '</div>'
+                               Html::rawElement(
+                                       'div',
+                                       [ 'class' => 'mw-changeslist-empty mw-changeslist-notargetpage' ],
+                                       $this->msg( 'recentchanges-notargetpage' )->parse()
+                               )
                        );
                } elseif ( !$targetTitle || $targetTitle->isExternal() ) {
                        $this->getOutput()->addHTML(
-                               '<div class="mw-changeslist-empty mw-changeslist-invalidtargetpage">' .
-                               $this->msg( 'allpagesbadtitle' )->parse() .
-                               '</div>'
+                               Html::rawElement(
+                                       'div',
+                                       [ 'class' => 'mw-changeslist-empty mw-changeslist-invalidtargetpage' ],
+                                       $this->msg( 'allpagesbadtitle' )->parse()
+                               )
                        );
                } else {
                        parent::outputNoResults();
index a93dec0..70a26ac 100644 (file)
@@ -347,7 +347,13 @@ class SpecialUndelete extends SpecialPage {
                                );
                        }
                        $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count )->parse();
-                       $out->addHTML( "<li class='undeleteResult'>{$item} ({$revs})</li>\n" );
+                       $out->addHTML(
+                               Html::rawElement(
+                                       'li',
+                                       [ 'class' => 'undeleteResult' ],
+                                       "{$item} ({$revs})"
+                               )
+                       );
                }
                $result->free();
                $out->addHTML( "</ul>\n" );
index 836b6df..4dbfc54 100644 (file)
@@ -324,7 +324,13 @@ class SpecialUpload extends SpecialPage {
                                );
                                $link = $this->msg( $user->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted' )
                                        ->rawParams( $restorelink )->parseAsBlock();
-                               $this->getOutput()->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
+                               $this->getOutput()->addHTML(
+                                       Html::rawElement(
+                                               'div',
+                                               [ 'id' => 'contentSub2' ],
+                                               $link
+                                       )
+                               );
                        }
                }
        }