Stop using the Xml class in this codebase

There was only a single caller. Maybe a mistake or just old code
that was never updated.

As well as:
* Avoid the separate open/closeElement when possible, usually in
  favor of a single rawElement.
* Note this patch also fixes one place where a message was added to
  the HTML output without escaping.

Bug: T341775
Change-Id: I51a29b47fbd8e0269c065e4277ef775f1d659ff6
This commit is contained in:
thiemowmde 2024-04-19 21:02:49 +02:00 committed by Thiemo Kreuz (WMDE)
parent 6c12bdfc8b
commit a5afba306a
2 changed files with 24 additions and 28 deletions

View file

@ -18,7 +18,6 @@ use Psr\Log\LoggerInterface;
use StatusValue; use StatusValue;
use stdClass; use stdClass;
use Throwable; use Throwable;
use Xml;
use XmlTypeCheck; use XmlTypeCheck;
/** /**
@ -468,10 +467,7 @@ class MathMathML extends MathRenderer {
$titleObj = SpecialPage::getTitleFor( 'MathWikibase' ); $titleObj = SpecialPage::getTitleFor( 'MathWikibase' );
$hyperlink = $titleObj->getLocalURL( [ 'qid' => $this->params['qid'] ] ); $hyperlink = $titleObj->getLocalURL( [ 'qid' => $this->params['qid'] ] );
} }
$output = Html::openElement( $element, $attribs ); $output = '';
if ( $hyperlink && $enableLinks ) {
$output .= Html::openElement( 'a', [ 'href' => $hyperlink, 'style' => 'color:inherit;' ] );
}
// MathML has to be wrapped into a div or span in order to be able to hide it. // MathML has to be wrapped into a div or span in order to be able to hide it.
// Remove displayStyle attributes set by the MathML converter // Remove displayStyle attributes set by the MathML converter
// (Beginning from Mathoid 0.2.5 block is the default layout.) // (Beginning from Mathoid 0.2.5 block is the default layout.)
@ -481,15 +477,19 @@ class MathMathML extends MathRenderer {
if ( $this->getMathStyle() == 'display' ) { if ( $this->getMathStyle() == 'display' ) {
$mml = preg_replace( '/<math/', '<math display="block"', $mml ); $mml = preg_replace( '/<math/', '<math display="block"', $mml );
} }
$output .= Xml::tags( $element, [ $output .= Html::rawElement( $element, [
'class' => $this->getClassName(), 'style' => 'display: none;' 'class' => $this->getClassName(), 'style' => 'display: none;'
], $mml ); ], $mml );
$output .= $this->getFallbackImage(); $output .= $this->getFallbackImage();
if ( $hyperlink && $enableLinks ) { if ( $hyperlink && $enableLinks ) {
$output .= Html::closeElement( 'a' ); $output = Html::rawElement( 'a',
[ 'href' => $hyperlink, 'style' => 'color:inherit;' ],
$output
);
} }
$output .= Html::closeElement( $element );
return $output; return Html::rawElement( $element, $attribs, $output );
} }
protected function dbOutArray() { protected function dbOutArray() {

View file

@ -175,8 +175,7 @@ class MathWikibaseInfo {
$labelAlign = $lang->isRTL() ? 'left' : 'right'; $labelAlign = $lang->isRTL() ? 'left' : 'right';
$labelAlignOpposite = !$lang->isRTL() ? 'left' : 'right'; $labelAlignOpposite = !$lang->isRTL() ? 'left' : 'right';
$output = Html::openElement( "table", [ "style" => "padding: 5px" ] ); $output = '';
$output .= Html::openElement( "tbody" );
foreach ( $this->hasParts as $part ) { foreach ( $this->hasParts as $part ) {
$output .= Html::openElement( "tr" ); $output .= Html::openElement( "tr" );
@ -193,7 +192,7 @@ class MathWikibaseInfo {
$part->getLabel() $part->getLabel()
); );
} else { } else {
$output .= $part->getLabel(); $output .= htmlspecialchars( $part->getLabel() );
} }
$output .= Html::closeElement( "td" ); $output .= Html::closeElement( "td" );
@ -221,10 +220,9 @@ class MathWikibaseInfo {
$output .= Html::closeElement( "tr" ); $output .= Html::closeElement( "tr" );
} }
$output .= Html::closeElement( "tbody" ); return Html::rawElement( 'table', [ 'style' => 'padding: 5px' ],
$output .= Html::closeElement( "table" ); Html::rawElement( 'tbody', [], $output )
);
return $output;
} }
/** /**
@ -232,22 +230,20 @@ class MathWikibaseInfo {
* @return string * @return string
*/ */
public function generateSmallTableOfParts() { public function generateSmallTableOfParts() {
$output = Html::openElement( "table" ); $output = '';
$output .= Html::openElement( "tbody" );
foreach ( $this->hasParts as $part ) { foreach ( $this->hasParts as $part ) {
$output .= Html::openElement( "tr" ); $output .= Html::rawElement( 'tr', [],
$output .= Html::rawElement( Html::rawElement( 'td',
"td", [ 'style' => 'text-align: center; padding-right: 5px;' ],
[ "style" => "text-align: center; padding-right: 5px;" ], $part->getFormattedSymbol()
$part->getFormattedSymbol() ) .
Html::element( 'td', [ 'style' => 'text-align:left;' ], $part->getLabel() )
); );
$output .= Html::element( "td", [ "style" => "text-align:left;" ], $part->getLabel() );
$output .= Html::closeElement( "tr" );
} }
$output .= Html::closeElement( "tbody" ); return Html::rawElement( 'table', [],
$output .= Html::closeElement( "table" ); Html::rawElement( 'tbody', [], $output )
return $output; );
} }
} }