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 stdClass;
use Throwable;
use Xml;
use XmlTypeCheck;
/**
@ -468,10 +467,7 @@ class MathMathML extends MathRenderer {
$titleObj = SpecialPage::getTitleFor( 'MathWikibase' );
$hyperlink = $titleObj->getLocalURL( [ 'qid' => $this->params['qid'] ] );
}
$output = Html::openElement( $element, $attribs );
if ( $hyperlink && $enableLinks ) {
$output .= Html::openElement( 'a', [ 'href' => $hyperlink, 'style' => 'color:inherit;' ] );
}
$output = '';
// 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
// (Beginning from Mathoid 0.2.5 block is the default layout.)
@ -481,15 +477,19 @@ class MathMathML extends MathRenderer {
if ( $this->getMathStyle() == 'display' ) {
$mml = preg_replace( '/<math/', '<math display="block"', $mml );
}
$output .= Xml::tags( $element, [
$output .= Html::rawElement( $element, [
'class' => $this->getClassName(), 'style' => 'display: none;'
], $mml );
$output .= $this->getFallbackImage();
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() {

View file

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