diff --git a/src/MathMathML.php b/src/MathMathML.php index 6dde98d4e..010a46832 100644 --- a/src/MathMathML.php +++ b/src/MathMathML.php @@ -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( '/ $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() { diff --git a/src/MathWikibaseInfo.php b/src/MathWikibaseInfo.php index 4076e2fd4..f48b21b53 100644 --- a/src/MathWikibaseInfo.php +++ b/src/MathWikibaseInfo.php @@ -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 ) + ); } }