Cleanup MathMathML.php after the PNG fallback removal.

- Remove the special handling for the PNG fallback in
  getFallbackImageUrl, getFallbackImage and getClassName.

- Make these functions private and remove useless parameters.

Bug: 71912
Change-Id: I569f2dd3d32a0c9690a5d9674a1c6ae0b8698f08
This commit is contained in:
Frédéric Wang 2014-10-11 16:13:04 +02:00
parent 0ddd3afaea
commit d1eef046af
1 changed files with 9 additions and 24 deletions

View File

@ -326,14 +326,13 @@ class MathMathML extends MathRenderer {
} }
/** /**
* @param int $mode
* @param boolean $noRender * @param boolean $noRender
* @return type * @return type
*/ */
private function getFallbackImageUrl( $mode = MW_MATH_MATHML, $noRender = false ) { private function getFallbackImageUrl( $noRender = false ) {
return SpecialPage::getTitleFor( 'MathShowImage' )->getLocalURL( array( return SpecialPage::getTitleFor( 'MathShowImage' )->getLocalURL( array(
'hash' => $this->getMd5(), 'hash' => $this->getMd5(),
'mode' => $mode, 'mode' => $this->getMode(),
'noRender' => $noRender ) 'noRender' => $noRender )
); );
} }
@ -366,30 +365,22 @@ class MathMathML extends MathRenderer {
/** /**
* Gets img tag for math image * Gets img tag for math image
* @param int $mode if MW_MATH_PNG a png is used instead of an svg image
* @param boolean $noRender if true no rendering will be performed if the image is not stored in the database * @param boolean $noRender if true no rendering will be performed if the image is not stored in the database
* @param boolean|string $classOverride if classOverride is false the class name will be calculated by getClassName * @param boolean|string $classOverride if classOverride is false the class name will be calculated by getClassName
* @return string XML the image html tag * @return string XML the image html tag
*/ */
public function getFallbackImage( $mode = MW_MATH_MATHML, $noRender = false, $classOverride = false ) { private function getFallbackImage( $noRender = false, $classOverride = false ) {
$url = $this->getFallbackImageUrl( $mode , $noRender ); $url = $this->getFallbackImageUrl( $noRender );
if ( $mode == MW_MATH_PNG ) {
$png = true;
} else {
$png = false;
}
$attribs = array(); $attribs = array();
if ( $classOverride === false ) { // $class = '' suppresses class attribute if ( $classOverride === false ) { // $class = '' suppresses class attribute
$class = $this->getClassName( true, $png ); $class = $this->getClassName( true );
} else { } else {
$class = $classOverride; $class = $classOverride;
} }
$style = ''; $style = '';
if ( !$png ) { $this->correctSvgStyle( $this->getSvg(), $style );
$this->correctSvgStyle( $this->getSvg(), $style );
}
if ( $class ) { $attribs['class'] = $class; } if ( $class ) { $attribs['class'] = $class; }
if ( $style ) { $attribs['style'] = $style; } if ( $style ) { $attribs['style'] = $style; }
// an alternative for svg might be an object with type="image/svg+xml" // an alternative for svg might be an object with type="image/svg+xml"
@ -403,18 +394,12 @@ class MathMathML extends MathRenderer {
/** /**
* Calculates the default class name for a math element * Calculates the default class name for a math element
* @param boolean $fallback * @param boolean $fallback
* @param boolean $png
* @return string the class name * @return string the class name
*/ */
protected function getClassName( $fallback = false, $png = false ) { private function getClassName( $fallback = false ) {
$class = "mwe-math-"; $class = "mwe-math-";
if ( $fallback ) { if ( $fallback ) {
$class .= 'fallback-'; $class .= 'fallback-svg-';
if ( $png ) {
$class .= 'png-';
} else {
$class .= 'svg-';
}
} else { } else {
$class .= 'mathml-'; $class .= 'mathml-';
} }
@ -450,7 +435,7 @@ class MathMathML extends MathRenderer {
$mml = preg_replace( '/<math/', '<math display="block"', $mml ); $mml = preg_replace( '/<math/', '<math display="block"', $mml );
} }
$output .= Xml::tags( $element, array( 'class' => $this->getClassName(), 'style' => 'display: none;' ), $mml ); $output .= Xml::tags( $element, array( 'class' => $this->getClassName(), 'style' => 'display: none;' ), $mml );
$output .= $this->getFallbackImage( $this->getMode() ) . "\n"; $output .= $this->getFallbackImage( ) . "\n";
$output .= HTML::closeElement( $element ); $output .= HTML::closeElement( $element );
return $output; return $output;
} }