Convert all array() syntax to []

Per wikitech-l consensus: https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Change-Id: I1d2604e3f246ede58ff8245ba2b940f258d2d80c
This commit is contained in:
physikerwelt 2016-04-12 16:53:25 -04:00
parent 005647a686
commit 6699724d65
28 changed files with 219 additions and 218 deletions

View File

@ -10,9 +10,9 @@
* @ingroup Extensions
*/
$specialPageAliases = array();
$specialPageAliases = [];
/** English (English) */
$specialPageAliases['en'] = array(
'MathShowImage' => array( 'MathShowImage' )
);
$specialPageAliases['en'] = [
'MathShowImage' => [ 'MathShowImage' ]
];

View File

@ -10,29 +10,29 @@
*/
// @codingStandardsIgnoreFile
$specialPageAliases = array();
$specialPageAliases = [];
/** English (English) */
$specialPageAliases['en'] = array(
'MathStatus' => array( 'MathStatus' ),
);
$specialPageAliases['en'] = [
'MathStatus' => [ 'MathStatus' ],
];
/** Arabic (العربية) */
$specialPageAliases['ar'] = array(
'MathStatus' => array( الة_الرياضيات' ),
);
$specialPageAliases['ar'] = [
'MathStatus' => [ الة_الرياضيات' ],
];
/** Persian (فارسی) */
$specialPageAliases['fa'] = array(
'MathStatus' => array( 'وضعیت_ریاضی' ),
);
$specialPageAliases['fa'] = [
'MathStatus' => [ 'وضعیت_ریاضی' ],
];
/** Macedonian (македонски) */
$specialPageAliases['mk'] = array(
'MathStatus' => array( 'МатСтатус' ),
);
$specialPageAliases['mk'] = [
'MathStatus' => [ 'МатСтатус' ],
];
/** Simplified Chinese (中文(简体)‎) */
$specialPageAliases['zh-hans'] = array(
'MathStatus' => array( '数学状态' ),
);
$specialPageAliases['zh-hans'] = [
'MathStatus' => [ '数学状态' ],
];

View File

@ -9,7 +9,7 @@
use MediaWiki\Logger\LoggerFactory;
class MathHooks {
private static $tags = array();
private static $tags = [];
const MATHCACHEKEY = 'math=';
public static function mathConstantToString( $value, array $defs, $prefix, $default ) {
@ -30,7 +30,7 @@ class MathHooks {
}
}
if ( is_string( $value ) ) {
$newValues = array();
$newValues = [];
foreach ( $defs as $k => $v ) {
$newValues[$k] = preg_replace_callback( '/_(.)/', function ( $matches ) {
return strtoupper( $matches[1] );
@ -46,21 +46,21 @@ class MathHooks {
}
public static function mathStyleToString( $style, $default = 'inlineDisplaystyle' ) {
$defs = array(
$defs = [
'MW_MATHSTYLE_INLINE_DISPLAYSTYLE' => 0, // default large operator inline
'MW_MATHSTYLE_DISPLAY' => 1, // large operators centered in a new line
'MW_MATHSTYLE_INLINE' => 2, // small operators inline
'MW_MATHSTYLE_LINEBREAK' => 3, // break long lines (experimental)
);
];
return self::mathConstantToString( $style, $defs, $prefix = 'MW_MATHSTYLE_', $default );
}
public static function mathCheckToString( $style, $default = 'always' ) {
$defs = array(
$defs = [
'MW_MATH_CHECK_ALWAYS' => 0,
'MW_MATH_CHECK_NEVER' => 1,
'MW_MATH_CHECK_NEW' => 2,
);
];
return self::mathConstantToString( $style, $defs, $prefix = 'MW_MATH_CHECK_', $default );
}
@ -72,21 +72,21 @@ class MathHooks {
// 'MW_MATH_MATHJAX' => 6
// 'MW_MATH_LATEXML_JAX' => 8
$defs = array(
$defs = [
'MW_MATH_PNG' => 0,
'MW_MATH_SOURCE' => 3,
'MW_MATH_MATHML' => 5,
'MW_MATH_LATEXML'=> 7 );
'MW_MATH_LATEXML'=> 7 ];
return self::mathConstantToString( $mode, $defs, $prefix = 'MW_MATH_', $default );
}
public static function mathModeToHashKey( $mode, $default = 0 ) {
$defs = array(
$defs = [
'png' => 0,
'source' => 3,
'mathml' => 5,
'latexml'=> 7 );
'latexml'=> 7 ];
if ( array_key_exists( $mode, $defs ) ) {
return $defs[$mode];
@ -102,7 +102,7 @@ class MathHooks {
* @param User $user reference to the current user
* @param array &$forOptions userOptions used on that page
*/
public static function onPageRenderingHash( &$confstr, $user = false, &$forOptions = array() ) {
public static function onPageRenderingHash( &$confstr, $user = false, &$forOptions = [] ) {
global $wgUser;
// To be independent of the MediaWiki core version,
@ -165,8 +165,8 @@ class MathHooks {
* @return Boolean: true
*/
static function onParserFirstCallInit( $parser ) {
$parser->setHook( 'math', array( 'MathHooks', 'mathTagHook' ) );
$parser->setHook( 'ce', array( 'MathHooks', 'ceTagHook' ) );
$parser->setHook( 'math', [ 'MathHooks', 'mathTagHook' ] );
$parser->setHook( 'ce', [ 'MathHooks', 'ceTagHook' ] );
return true;
}
@ -191,17 +191,17 @@ class MathHooks {
$parser->getOptions()->optionUsed( 'math' );
$renderer = MathRenderer::getRenderer( $content, $attributes, $mode );
$parser->getOutput()->addModuleStyles( array( 'ext.math.styles' ) );
$parser->getOutput()->addModuleStyles( [ 'ext.math.styles' ] );
if ( $mode == 'mathml' ) {
$parser->getOutput()->addModuleStyles( array( 'ext.math.desktop.styles' ) );
$parser->getOutput()->addModules( array( 'ext.math.scripts' ) );
$parser->getOutput()->addModuleStyles( [ 'ext.math.desktop.styles' ] );
$parser->getOutput()->addModules( [ 'ext.math.scripts' ] );
$marker = Parser::MARKER_PREFIX .
'-postMath-' . sprintf( '%08X', $n ++ ) .
Parser::MARKER_SUFFIX;
self::$tags[$marker] = array( $renderer, $parser );
self::$tags[$marker] = [ $renderer, $parser ];
return $marker;
}
return array( self::mathPostTagHook( $renderer, $parser ), 'markerType' => 'nowiki' );
return [ self::mathPostTagHook( $renderer, $parser ), 'markerType' => 'nowiki' ];
}
/**
@ -230,7 +230,7 @@ class MathHooks {
return $renderer->getLastError();
}
Hooks::run( 'MathFormulaPostRender',
array( $parser, &$renderer, &$renderedMath ) );// Enables indexing of math formula
[ $parser, $renderer, $renderedMath ] );// Enables indexing of math formula
// Writes cache if rendering was successful
$renderer->writeCache();
@ -247,12 +247,12 @@ class MathHooks {
*/
static function onGetPreferences( $user, &$defaultPreferences ) {
global $wgDefaultUserOptions;
$defaultPreferences['math'] = array(
$defaultPreferences['math'] = [
'type' => 'radio',
'options' => array_flip( self::getMathNames() ),
'label' => ' ',
'section' => 'rendering/math',
);
];
// If the default option is not in the valid options the
// user interface throws an exception (BUG 64844)
$mode = MathHooks::mathModeToString( $wgDefaultUserOptions['math'] );
@ -273,7 +273,7 @@ class MathHooks {
* @return array of strings
*/
public static function getMathNames() {
$names = array();
$names = [];
foreach ( MathRenderer::getValidModes() as $mode ) {
$names[$mode] = wfMessage( 'mw_math_' . $mode )->escaped();
}
@ -309,7 +309,7 @@ class MathHooks {
throw new Exception( 'Math extension is only necessary in 1.18 or above' );
}
$map = array( 'mysql', 'sqlite', 'postgres', 'oracle', 'mssql' );
$map = [ 'mysql', 'sqlite', 'postgres', 'oracle', 'mssql' ];
$type = $updater->getDB()->getType();
@ -319,7 +319,7 @@ class MathHooks {
$sql = __DIR__ . '/db/math.' . $type . '.sql';
$updater->addExtensionTable( 'math', $sql );
if ( in_array( 'latexml', MathRenderer::getValidModes() ) ) {
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
if ( in_array( $type, [ 'mysql', 'sqlite', 'postgres' ] ) ) {
$sql = __DIR__ . '/db/mathlatexml.' . $type . '.sql';
$updater->addExtensionTable( 'mathlatexml', $sql );
if ( $type == 'mysql' ) {
@ -331,7 +331,7 @@ class MathHooks {
}
}
if ( in_array( 'mathml', MathRenderer::getValidModes() ) ) {
if ( in_array( $type, array( 'mysql', 'sqlite', 'postgres' ) ) ) {
if ( in_array( $type, [ 'mysql', 'sqlite', 'postgres' ] ) ) {
$sql = __DIR__ . '/db/mathoid.' . $type . '.sql';
$updater->addExtensionTable( 'mathoid', $sql );
} else {
@ -374,7 +374,7 @@ class MathHooks {
* @return bool
*/
public static function onParserAfterTidy( &$parser, &$text ) {
$rbis = array();
$rbis = [];
foreach ( self::$tags as $key => $tag ){
/** @var MathRenderer $renderer */
$renderer = $tag[0];
@ -384,7 +384,7 @@ class MathHooks {
}
MathRestbaseInterface::batchEvaluate( $rbis );
foreach ( self::$tags as $key => $tag ){
$value = call_user_func_array( array( "MathHooks","mathPostTagHook" ), $tag );
$value = call_user_func_array( [ "MathHooks","mathPostTagHook" ], $tag );
// Workaround for https://phabricator.wikimedia.org/T103269
$text = preg_replace( '/(<mw:editsection[^>]*>.*?)' . preg_quote( $key ) .
'(.*?)<\/mw:editsection>/',
@ -392,7 +392,7 @@ class MathHooks {
$text = str_replace( $key, $value, $text );
}
// This hook might be called multiple times. However one the tags are rendered the job is done.
self::$tags = array();
self::$tags = [];
return true;
}
/**
@ -402,7 +402,7 @@ class MathHooks {
*/
static function onEditPageBeforeEditToolbar( &$toolbar ) {
global $wgOut;
$wgOut->addModules( array( 'ext.math.editbutton.enabler' ) );
$wgOut->addModules( [ 'ext.math.editbutton.enabler' ] );
}
public static function registerExtension() {

View File

@ -13,7 +13,7 @@ class MathDataModule extends ResourceLoaderModule {
/* Protected Members */
protected $origin = self::ORIGIN_USER_SITEWIDE;
protected $targets = array( 'desktop', 'mobile' );
protected $targets = [ 'desktop', 'mobile' ];
/* Methods */
@ -25,9 +25,9 @@ class MathDataModule extends ResourceLoaderModule {
}
public function getDependencies( ResourceLoaderContext $context = null ) {
return array(
return [
'ext.math.visualEditor',
);
];
}
public function enableModuleContentVersion() {

View File

@ -89,13 +89,13 @@ class MathFormatter implements ValueFormatter {
private function formatDetails( $valueHtml, $tex ) {
$html = '';
$html .= Html::rawElement( 'h4',
array( 'class' => 'wb-details wb-math-details wb-math-rendered' ),
[ 'class' => 'wb-details wb-math-details wb-math-rendered' ],
$valueHtml
);
$html .= Html::rawElement( 'div',
array( 'class' => 'wb-details wb-math-details' ),
Html::element( 'code', array(), $tex )
[ 'class' => 'wb-details wb-math-details' ],
Html::element( 'code', [], $tex )
);
return $html;

View File

@ -50,11 +50,11 @@ class MathInputCheckTexvc extends MathInputCheck {
*/
public function isValid() {
$us = $this;
$checkWork = new PoolCounterWorkViaCallback( 'MathTexvc-check', "", array(
$checkWork = new PoolCounterWorkViaCallback( 'MathTexvc-check', "", [
'doWork' => function() use ( $us ) {
return $us->doValidCheck();
}
) );
] );
return $checkWork->execute();
}

View File

@ -12,11 +12,11 @@ use MediaWiki\Logger\LoggerFactory;
*/
class MathLaTeXML extends MathMathML {
protected $defaultAllowedRootElements = array( 'math', 'div', 'table', 'query' );
protected $defaultAllowedRootElements = [ 'math', 'div', 'table', 'query' ];
/** @var String settings for LaTeXML daemon */
private $LaTeXMLSettings = '';
public function __construct( $tex = '', $params = array() ) {
public function __construct( $tex = '', $params = [] ) {
global $wgMathLaTeXMLUrl;
parent::__construct( $tex, $params );
$this->hosts = $wgMathLaTeXMLUrl;
@ -117,29 +117,28 @@ class MathLaTeXML extends MathMathML {
if ( $this->isValidMathML( $jsonResult->result ) ) {
$this->setMathml( $jsonResult->result );
Hooks::run( 'MathRenderingResultRetrieved',
array( &$this,
&$jsonResult ) );// Enables debugging of server results
[ $this, $jsonResult ] );// Enables debugging of server results
return true;
} else {
// Do not print bad mathml. It's probably too verbose and might
// mess up the browser output.
$this->lastError = $this->getError( 'math_invalidxml', $this->getModeStr(), $host );
LoggerFactory::getInstance( 'Math' )->warning(
'LaTeXML InvalidMathML: ' . var_export( array(
'LaTeXML InvalidMathML: ' . var_export( [
'post' => $post,
'host' => $host,
'result' => $res
), true ) );
], true ) );
return false;
}
} else {
$this->lastError = $this->getError( 'math_invalidjson', $this->getModeStr(), $host );
LoggerFactory::getInstance( 'Math' )->warning(
'LaTeXML InvalidJSON:' . var_export( array(
'LaTeXML InvalidJSON:' . var_export( [
'post' => $post,
'host' => $host,
'res' => $res
), true ) );
], true ) );
return false;
}
} else {
@ -167,7 +166,7 @@ class MathLaTeXML extends MathMathML {
public static function embedMathML( $mml, $tagId = '', $attribs = false ) {
$mml = str_replace( "\n", " ", $mml );
if ( ! $attribs ) {
$attribs = array( 'class' => 'tex', 'dir' => 'ltr' );
$attribs = [ 'class' => 'tex', 'dir' => 'ltr' ];
if ( $tagId ) {
$attribs['id'] = $tagId;
}

View File

@ -13,8 +13,8 @@ use MediaWiki\Logger\LoggerFactory;
*/
class MathMathML extends MathRenderer {
protected $defaultAllowedRootElements = array( 'math' );
protected $restbaseInputTypes = array( 'tex', 'inline-tex', 'chem' );
protected $defaultAllowedRootElements = [ 'math' ];
protected $restbaseInputTypes = [ 'tex', 'inline-tex', 'chem' ];
protected $allowedRootElements = '';
protected $hosts;
@ -23,7 +23,7 @@ class MathMathML extends MathRenderer {
private $svgPath = false;
private $mathoidStyle;
public function __construct( $tex = '', $params = array() ) {
public function __construct( $tex = '', $params = [] ) {
global $wgMathMathMLUrl;
parent::__construct( $tex, $params );
$this->setMode( 'mathml' );
@ -163,7 +163,7 @@ class MathMathML extends MathRenderer {
if ( !$post ) {
$this->getPostData();
}
$options = array( 'method' => 'POST', 'postData' => $post, 'timeout' => $wgMathLaTeXMLTimeout );
$options = [ 'method' => 'POST', 'postData' => $post, 'timeout' => $wgMathLaTeXMLTimeout ];
/** @var $req (CurlHttpRequest|PhpHttpRequest) the request object */
$req = $httpRequestClass::factory( $host, $options );
/** @var Status $req Status the request status */
@ -175,22 +175,22 @@ class MathMathML extends MathRenderer {
if ( $status->hasMessage( 'http-timed-out' ) ) {
$error = $this->getError( 'math_timeout', $this->getModeStr(), $host );
$res = false;
LoggerFactory::getInstance( 'Math' )->warning( 'Timeout:' . var_export( array(
LoggerFactory::getInstance( 'Math' )->warning( 'Timeout:' . var_export( [
'post' => $post,
'host' => $host,
'timeout' => $wgMathLaTeXMLTimeout
), true ) );
], true ) );
} else {
// for any other unkonwn http error
$errormsg = $status->getHtml();
$error =
$this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg,
$this->getModeStr( 'mathml' ) );
LoggerFactory::getInstance( 'Math' )->warning( 'NoResponse:' . var_export( array(
LoggerFactory::getInstance( 'Math' )->warning( 'NoResponse:' . var_export( [
'post' => $post,
'host' => $host,
'errormsg' => $errormsg
), true ) );
], true ) );
}
return false;
}
@ -264,21 +264,21 @@ class MathMathML extends MathRenderer {
}
$this->lastError = $this->getError( 'math_mathoid_error', $host, $log );
LoggerFactory::getInstance( 'Math' )->warning(
'Mathoid conversion error:' . var_export( array(
'Mathoid conversion error:' . var_export( [
'post' => $post,
'host' => $host,
'result' => $res
), true ) );
], true ) );
return false;
}
} else {
$this->lastError = $this->getError( 'math_invalidjson', $host );
LoggerFactory::getInstance( 'Math' )->error(
'MathML InvalidJSON:' . var_export( array(
'MathML InvalidJSON:' . var_export( [
'post' => $post,
'host' => $host,
'res' => $res
), true ) );
], true ) );
return false;
}
} else {
@ -328,10 +328,11 @@ class MathMathML extends MathRenderer {
if ( $this->svgPath ) {
return $this->svgPath;
}
return SpecialPage::getTitleFor( 'MathShowImage' )->getLocalURL( array(
return SpecialPage::getTitleFor( 'MathShowImage' )->getLocalURL( [
'hash' => $this->getMd5(),
'mode' => $this->getMode(),
'noRender' => $noRender )
'noRender' => $noRender
]
);
}
@ -374,7 +375,7 @@ class MathMathML extends MathRenderer {
private function getFallbackImage( $noRender = false, $classOverride = false ) {
$url = $this->getFallbackImageUrl( $noRender );
$attribs = array();
$attribs = [];
if ( $classOverride === false ) { // $class = '' suppresses class attribute
$class = $this->getClassName( true );
} else {
@ -394,8 +395,8 @@ class MathMathML extends MathRenderer {
// Don't use an empty span, as that is going to be stripped by HTML tidy
// when enabled (which is true in production).
return Xml::element( 'meta', $this->getAttributes(
'span', $attribs, array( 'aria-hidden' => 'true', 'style' => $style
) ) );
'span', $attribs, [ 'aria-hidden' => 'true', 'style' => $style
] ) );
}
protected function getMathTableName() {
@ -436,7 +437,7 @@ class MathMathML extends MathRenderer {
} else {
$element = 'span';
}
$attribs = array();
$attribs = [];
if ( $this->getID() !== '' ) {
$attribs['id'] = $this->getID();
}
@ -450,9 +451,9 @@ class MathMathML extends MathRenderer {
if ( $this->getMathStyle() == 'display' ) {
$mml = preg_replace( '/<math/', '<math display="block"', $mml );
}
$output .= Xml::tags( $element, array(
$output .= Xml::tags( $element, [
'class' => $this->getClassName(), 'style' => 'display: none;'
), $mml );
], $mml );
$output .= $this->getFallbackImage();
$output .= Html::closeElement( $element );
return $output;
@ -470,7 +471,7 @@ class MathMathML extends MathRenderer {
protected function dbInArray() {
$out = parent::dbInArray();
if ( $this->getMathTableName() == 'mathoid' ) {
$out = array_diff( $out, array( 'math_inputtex' ) );
$out = array_diff( $out, [ 'math_inputtex' ] );
$out[] = 'math_input';
}
return $out;
@ -512,8 +513,7 @@ class MathMathML extends MathRenderer {
$this->setMathml( $jsonResult->mml );
}
Hooks::run( 'MathRenderingResultRetrieved',
array( &$this,
&$jsonResult ) ); // Enables debugging of server results
[ $this, $jsonResult ] ); // Enables debugging of server results
return true;
} else {
$this->lastError = $this->getError( 'math_unknown_error', $host );

View File

@ -35,7 +35,7 @@ abstract class MathRenderer {
/** @var ('inlineDisplaystyle'|'display'|'inline'|'linebreak') the rendering style */
protected $mathStyle = 'inlineDisplaystyle';
/** @var array with userdefined parameters passed to the extension (not used) */
protected $params = array();
protected $params = [];
/** @var string a userdefined identifier to link to the equation. */
protected $id = '';
@ -67,7 +67,7 @@ abstract class MathRenderer {
* @param string $tex (optional) LaTeX markup
* @param array $params (optional) HTML attributes
*/
public function __construct( $tex = '', $params = array() ) {
public function __construct( $tex = '', $params = [] ) {
$this->params = $params;
if ( isset( $params['id'] ) ) {
$this->id = $params['id'];
@ -109,7 +109,7 @@ abstract class MathRenderer {
* @param string $mode constant indicating rendering mode
* @return string HTML for math tag
*/
public static function renderMath( $tex, $params = array(), $mode = 'png' ) {
public static function renderMath( $tex, $params = [], $mode = 'png' ) {
$renderer = self::getRenderer( $tex, $params, $mode );
if ( $renderer->render() ) {
return $renderer->getHtmlOutput();
@ -140,7 +140,7 @@ abstract class MathRenderer {
* @param string $mode indicating rendering mode
* @return MathRenderer appropriate renderer for mode
*/
public static function getRenderer( $tex, $params = array(), $mode = 'png' ) {
public static function getRenderer( $tex, $params = [], $mode = 'png' ) {
global $wgDefaultUserOptions, $wgMathEnableExperimentalInputFormats;
if ( isset( $params['forcemathmode'] ) ) {
@ -153,7 +153,7 @@ abstract class MathRenderer {
isset( $params['type'] ) ) {
// Support of MathML input (experimental)
// Currently support for mode 'mathml' only
if ( !in_array( $params['type'], array( 'pmml', 'ascii' ) ) ) {
if ( !in_array( $params['type'], [ 'pmml', 'ascii' ] ) ) {
unset( $params['type'] );
}
}
@ -268,7 +268,7 @@ abstract class MathRenderer {
$dbr = wfGetDB( DB_SLAVE );
$rpage = $dbr->selectRow( $this->getMathTableName(),
$this->dbInArray(),
array( 'math_inputhash' => $this->getInputHash() ),
[ 'math_inputhash' => $this->getInputHash() ],
__METHOD__ );
if ( $rpage !== false ) {
$this->initializeFromDatabaseRow( $rpage );
@ -285,12 +285,12 @@ abstract class MathRenderer {
* @return array with the database column names
*/
protected function dbInArray() {
$in = array( 'math_inputhash',
$in = [ 'math_inputhash',
'math_mathml',
'math_inputtex',
'math_tex',
'math_svg'
);
];
return $in;
}
@ -343,7 +343,7 @@ abstract class MathRenderer {
$dbw, $outArray, $inputHash, $method, $mathTableName
) {
$dbw->update( $mathTableName, $outArray,
array( 'math_inputhash' => $inputHash ), $method );
[ 'math_inputhash' => $inputHash ], $method );
LoggerFactory::getInstance( 'Math' )->debug(
'Row updated after db transaction was idle: ' .
var_export( $outArray, true ) . " to database" );
@ -352,7 +352,7 @@ abstract class MathRenderer {
$dbw->onTransactionIdle( function () use (
$dbw, $outArray, $method, $mathTableName
) {
$dbw->insert( $mathTableName, $outArray, $method, array( 'IGNORE' ) );
$dbw->insert( $mathTableName, $outArray, $method, [ 'IGNORE' ] );
LoggerFactory::getInstance( 'Math' )->debug(
'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database" );
@ -371,12 +371,13 @@ abstract class MathRenderer {
* @return array
*/
protected function dbOutArray() {
$out = array( 'math_inputhash' => $this->getInputHash(),
$out = [
'math_inputhash' => $this->getInputHash(),
'math_mathml' => utf8_encode( $this->mathml ),
'math_inputtex' => $this->userInputTex,
'math_tex' => $this->tex,
'math_svg' => $this->svg
);
];
return $out;
}
@ -395,7 +396,7 @@ abstract class MathRenderer {
* @param array $overrides attributes to override defaults
* @return array HTML attributes
*/
protected function getAttributes( $tag, $defaults = array(), $overrides = array() ) {
protected function getAttributes( $tag, $defaults = [], $overrides = [] ) {
$attribs = Sanitizer::validateTagAttributes( $this->params, $tag );
$attribs = Sanitizer::mergeAttributes( $defaults, $attribs );
$attribs = Sanitizer::mergeAttributes( $attribs, $overrides );
@ -485,14 +486,14 @@ abstract class MathRenderer {
/**
* Get the attributes of the math tag
*
* @return array()
* @return []
*/
public function getParams() {
return $this->params;
}
/**
* @param array() $params
* @param [] $params
*/
public function setParams( $params ) {
// $changed is not set to true here, because the attributes do not affect

View File

@ -36,8 +36,8 @@ class MathRestbaseInterface {
* @param $serviceClient
*/
private static function batchGetMathML( $rbis, $serviceClient ) {
$requests = array();
$skips = array();
$requests = [];
$skips = [];
$i = 0;
foreach ( $rbis as $rbi ) {
/** @var MathRestbaseInterface $rbi */
@ -112,11 +112,11 @@ class MathRestbaseInterface {
$serviceClient = $this->getServiceClient();
$response = $serviceClient->run( $request );
if ( $response['code'] !== 200 ) {
$this->log()->info( 'Tex check failed:', array(
$this->log()->info( 'Tex check failed:', [
'post' => $request['body'],
'error' => $response['error'],
'url' => $request['url']
) );
] );
}
return $response;
@ -129,7 +129,7 @@ class MathRestbaseInterface {
if ( count( $rbis ) == 0 ) {
return;
}
$requests = array();
$requests = [];
/** @var MathRestbaseInterface $first */
$first = $rbis[0];
$serviceClient = $first->getServiceClient();
@ -152,7 +152,7 @@ class MathRestbaseInterface {
private function getServiceClient() {
global $wgVirtualRestConfig;
$serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( array() ) );
$serviceClient = new VirtualRESTServiceClient( new MultiHttpClient( [] ) );
if ( isset( $wgVirtualRestConfig['modules']['restbase'] ) ) {
$cfg = $wgVirtualRestConfig['modules']['restbase'];
$cfg['parsoidCompat'] = false;
@ -217,10 +217,10 @@ class MathRestbaseInterface {
*/
public function checkBackend( $skipConfigCheck = false ) {
try {
$request = array(
$request = [
'method' => 'GET',
'url' => $this->getUrl( '?spec' )
);
];
} catch ( Exception $e ) {
return false;
}
@ -229,10 +229,10 @@ class MathRestbaseInterface {
if ( $response['code'] === 200 ) {
return $skipConfigCheck || $this->checkConfig();
}
$this->log()->error( "Restbase backend is not correctly set up.", array(
$this->log()->error( "Restbase backend is not correctly set up.", [
'request' => $request,
'response' => $response
) );
] );
return false;
}
@ -248,7 +248,7 @@ class MathRestbaseInterface {
$testInterface = new MathRestbaseInterface( $uniqueTeX );
if ( ! $testInterface->checkTeX() ){
$this->log()->warning( 'Config check failed, since test expression was considered as invalid.',
array( 'uniqueTeX' => $uniqueTeX ) );
[ 'uniqueTeX' => $uniqueTeX ] );
return false;
}
try {
@ -259,9 +259,9 @@ class MathRestbaseInterface {
return true;
}
$this->log()->warning( 'Config check failed, due to an invalid response code.',
array( 'responseCode' => $status ) );
[ 'responseCode' => $status ] );
} catch ( Exception $e ) {
$this->log()->warning( 'Config check failed, due to an exception.', array( $e ) );
$this->log()->warning( 'Config check failed, due to an exception.', [ $e ] );
return false;
}
}
@ -322,7 +322,7 @@ class MathRestbaseInterface {
}
private function setErrorMessage( $msg ) {
$this->error = (object)array( 'error' => (object)array( 'message' => $msg ) );
$this->error = (object)[ 'error' => (object)[ 'message' => $msg ] ];
}
/**
@ -330,14 +330,14 @@ class MathRestbaseInterface {
* @throws MWException
*/
public function getCheckRequest() {
$request = array(
$request = [
'method' => 'POST',
'body' => array(
'body' => [
'type' => $this->type,
'q' => $this->tex
),
],
'url' => $this->getUrl( "media/math/check/{$this->type}" )
);
];
return $request;
}
@ -380,10 +380,10 @@ class MathRestbaseInterface {
*/
private function getContentRequest( $type ) {
$this->calculateHash();
$request = array(
$request = [
'method' => 'GET',
'url' => $this->getUrl( "media/math/render/$type/{$this->hash}" )
);
];
return $request;
}
@ -401,12 +401,12 @@ class MathRestbaseInterface {
}
return $response['body'];
}
$this->log()->error( 'Restbase math server problem:', array(
$this->log()->error( 'Restbase math server problem:', [
'request' => $request,
'response' => $response,
'type' => $type,
'tex' => $this->tex
) );
] );
throw new MWException( "Cannot get $type. Server problem." );
}
}

View File

@ -23,7 +23,7 @@ class MathSource extends MathRenderer {
* @param string $tex
* @param array $params
*/
function __construct( $tex = '', $params = array() ) {
function __construct( $tex = '', $params = [] ) {
parent::__construct( $tex, $params );
$this->setMode( 'source' );
}
@ -44,12 +44,12 @@ class MathSource extends MathRenderer {
return Xml::element( 'span',
$this->getAttributes(
'span',
array(
[
// the former class name was 'tex'
// for backwards compatibility we keep this classname
'class' => $class. ' tex',
'dir' => 'ltr'
)
]
),
'$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $'
);

View File

@ -35,7 +35,7 @@ class MathTexvc extends MathRenderer {
* @return array
*/
public function dbOutArray() {
$out = array();
$out = [];
$dbr = wfGetDB( DB_SLAVE );
$outmd5_sql = $dbr->encodeBlob( pack( 'H32', $this->hash ) );
if ( $outmd5_sql instanceof Blob ) {
@ -52,8 +52,8 @@ class MathTexvc extends MathRenderer {
}
protected function dbInArray() {
return array( 'math_inputhash', 'math_outputhash',
'math_html_conservativeness', 'math_html', 'math_mathml' );
return [ 'math_inputhash', 'math_outputhash',
'math_html_conservativeness', 'math_html', 'math_mathml' ];
}
/**
@ -138,12 +138,12 @@ class MathTexvc extends MathRenderer {
*/
public function getMathImageHTML() {
$url = $this->getMathImageUrl();
$attributes = array(
$attributes = [
// the former class name was 'tex'
// for backwards compatibility we keep that classname
'class' => 'mwe-math-fallback-image-inline tex',
'alt' => $this->getTex()
);
];
if ( $this->getMathStyle() === 'display' ){
// if DisplayStyle is true, the equation will be centered in a new line
$attributes[ 'class' ] = 'mwe-math-fallback-image-display tex';
@ -152,9 +152,9 @@ class MathTexvc extends MathRenderer {
$this->getAttributes(
'img',
$attributes,
array(
[
'src' => $url
)
]
)
);
@ -270,7 +270,7 @@ class MathTexvc extends MathRenderer {
$this->setHash( $newHash );
}
Hooks::run( 'MathAfterTexvc', array( &$this, &$errmsg ) );
Hooks::run( 'MathAfterTexvc', [ $this, $errmsg ] );
if ( $errmsg ) {
return $errmsg;
@ -286,13 +286,13 @@ class MathTexvc extends MathRenderer {
$backend = $this->getBackend();
# Create any containers/directories as needed...
if ( !$backend->prepare( array( 'dir' => $hashpath ) )->isOK() ) {
if ( !$backend->prepare( [ 'dir' => $hashpath ] )->isOK() ) {
return $this->getError( 'math_output_error' );
}
// Store the file at the final storage path...
// Bug 56769: buffer the writes and do them at the end.
if ( !isset( $wgHooks['ParserAfterParse']['FlushMathBackend'] ) ) {
$backend->mathBufferedWrites = array();
$backend->mathBufferedWrites = [];
$wgHooks['ParserAfterParse']['FlushMathBackend'] = function () use ( $backend ) {
global $wgHooks;
unset( $wgHooks['ParserAfterParse']['FlushMathBackend'] );
@ -300,12 +300,12 @@ class MathTexvc extends MathRenderer {
unset( $backend->mathBufferedWrites );
};
}
$backend->mathBufferedWrites[] = array(
$backend->mathBufferedWrites[] = [
'op' => 'store',
'src' => "$tmpDir/{$this->getHash()}.png",
'dst' => "$hashpath/{$this->getHash()}.png",
'ref' => $tempFsFile // keep file alive
);
];
return self::MW_TEXVC_SUCCESS;
}
@ -322,13 +322,13 @@ class MathTexvc extends MathRenderer {
} else {
static $backend = null;
if ( !$backend ) {
$backend = new FSFileBackend( array(
$backend = new FSFileBackend( [
'name' => 'math-backend',
'wikiId' => wfWikiId(),
'lockManager' => new NullLockManager( array() ),
'containerPaths' => array( 'math-render' => $wgMathDirectory ),
'lockManager' => new NullLockManager( [] ),
'containerPaths' => [ 'math-render' => $wgMathDirectory ],
'fileMode' => 0777
) );
] );
}
return $backend;
}
@ -352,7 +352,7 @@ class MathTexvc extends MathRenderer {
$updated = parent::writeCache();
// If we're replacing an older version of the image, make sure it's current.
if ( $updated && $wgUseSquid ) {
$urls = array( $this->getMathImageUrl() );
$urls = [ $this->getMathImageUrl() ];
$u = new SquidUpdate( $urls );
$u->doUpdate();
}
@ -375,10 +375,10 @@ class MathTexvc extends MathRenderer {
}
$filename = $this->getHashPath() . "/{$this->getHash()}.png"; // final storage path
$backend = $this->getBackend();
if ( $backend->fileExists( array( 'src' => $filename ) ) ) {
if ( $backend->getFileSize( array( 'src' => $filename ) ) == 0 ) {
if ( $backend->fileExists( [ 'src' => $filename ] ) ) {
if ( $backend->getFileSize( [ 'src' => $filename ] ) == 0 ) {
// Some horrible error corrupted stuff :(
$backend->quickDelete( array( 'src' => $filename ) );
$backend->quickDelete( [ 'src' => $filename ] );
} else {
return true; // cache hit
}
@ -396,7 +396,7 @@ class MathTexvc extends MathRenderer {
}
$backend = $this->getBackend();
return $backend->getFileContents(
array( 'src' => $this->getHashPath() . "/" . $this->getHash() . '.png' )
[ 'src' => $this->getHashPath() . "/" . $this->getHash() . '.png' ]
);
}

View File

@ -1,10 +1,10 @@
<?php
use DataValues\StringValue;
use ValueFormatters\Exceptions\MismatchingDataValueTypeException;
use ValueValidators\Error;
use ValueValidators\Result;
use ValueValidators\ValueValidator;
use ValueValidators\Error;
use DataValues\StringValue;
// @author Duc Linh Tran, Julian Hilbig, Moritz Schubotz
@ -33,9 +33,9 @@ class MathValidator implements ValueValidator {
// TeX string is not valid
return Result::newError(
array(
Error::newError( null, null, 'malformed-value', array( $checker->getError() ) )
)
[
Error::newError( null, null, 'malformed-value', [ $checker->getError() ] )
]
);
}

View File

@ -21,7 +21,7 @@ class MathWikidataHook {
return;
}
$dataTypeDefinitions['PT:math'] = array(
$dataTypeDefinitions['PT:math'] = [
'value-type' => 'string',
'validator-factory-callback' => function() {
// load validator builders
@ -41,7 +41,7 @@ class MathWikidataHook {
},
'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
global $wgOut;
$styles = array( 'ext.math.desktop.styles', 'ext.math.scripts', 'ext.math.styles' );
$styles = [ 'ext.math.desktop.styles', 'ext.math.scripts', 'ext.math.styles' ];
$wgOut->addModuleStyles( $styles );
return new MathFormatter( $format );
},
@ -54,7 +54,7 @@ class MathWikidataHook {
) {
return new MathMLRdfBuilder();
},
);
];
}
/*
@ -67,15 +67,15 @@ class MathWikidataHook {
return;
}
$dataTypeDefinitions['PT:math'] = array(
$dataTypeDefinitions['PT:math'] = [
'value-type' => 'string',
'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
global $wgOut;
$styles = array( 'ext.math.desktop.styles', 'ext.math.scripts', 'ext.math.styles' );
$styles = [ 'ext.math.desktop.styles', 'ext.math.scripts', 'ext.math.styles' ];
$wgOut->addModuleStyles( $styles );
return new MathFormatter( $format );
},
);
];
}
}

2
README
View File

@ -58,4 +58,4 @@ from your MediWiki home path.
== Logging ==
The math extension supports PSR-3 logging:
Configuration can be dona via
$wgDebugLogGroups['Math'] = array( 'level' => 'info', 'destination' => '/path/to/file.log' );
$wgDebugLogGroups['Math'] = [ 'level' => 'info', 'destination' => '/path/to/file.log' ];

View File

@ -82,18 +82,18 @@ class SpecialMathShowImage extends SpecialPage {
$mmlRenderer = MathMathML::newFromMd5( $hash );
$mmlRenderer->readFromDatabase();
$this->renderer = MathRenderer::getRenderer(
$mmlRenderer->getUserInputTex(), array(), 'png'
$mmlRenderer->getUserInputTex(), [], 'png'
);
$this->renderer->setMathStyle( $mmlRenderer->getMathStyle() );
}
$success = $this->renderer->render();
}
} elseif ( $asciimath === '' ) {
$this->renderer = MathRenderer::getRenderer( $tex, array(), $this->mode );
$this->renderer = MathRenderer::getRenderer( $tex, [], $this->mode );
$success = $this->renderer->render();
} else {
$this->renderer = MathRenderer::getRenderer(
$asciimath, array( 'type' => 'ascii' ), $this->mode
$asciimath, [ 'type' => 'ascii' ], $this->mode
);
$success = $this->renderer->render();
}

View File

@ -63,7 +63,7 @@ class SpecialMathStatus extends SpecialPage {
}
public function testSpecialCaseText() {
$renderer = MathRenderer::getRenderer( 'x^2+\text{a sample Text}', array(), 'mathml' );
$renderer = MathRenderer::getRenderer( 'x^2+\text{a sample Text}', [], 'mathml' );
$expected = 'a sample Text</mtext>';
$this->assertTrue( $renderer->render(), 'Rendering the input "x^2+\text{a sample Text}"' );
$this->assertContains(
@ -78,7 +78,7 @@ class SpecialMathStatus extends SpecialPage {
public function testMathMLIntegration() {
$svgRef = file_get_contents( __DIR__ .'/images/reference.svg' );
$svgRefNoSpeech = file_get_contents( __DIR__ .'/images/reference-nospeech.svg' );
$renderer = MathRenderer::getRenderer( "a+b", array(), 'mathml' );
$renderer = MathRenderer::getRenderer( "a+b", [], 'mathml' );
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in plain MathML mode" );
$real = str_replace( "\n", '', $renderer->getHtmlOutput() );
$expected = '<mo>+</mo>';
@ -99,7 +99,7 @@ class SpecialMathStatus extends SpecialPage {
// @codingStandardsIgnoreStart
$inputSample = '<msub> <mrow> <mi> P</mi> </mrow> <mrow> <mi> i</mi> <mi> j</mi> </mrow> </msub> <mo> =</mo> <mfrac> <mrow> <mn> 100</mn> <msub> <mrow> <mi> d</mi> </mrow> <mrow> <mi> i</mi> <mi> j</mi> </mrow> </msub> </mrow> <mrow> <mn> 6.75</mn> <msub> <mrow> <mi> r</mi> </mrow> <mrow> <mi> j</mi> </mrow> </msub> </mrow> </mfrac> <mo> ,</mo> </math>';
// @codingStandardsIgnoreEnd
$attribs = array( 'type' => 'pmml' );
$attribs = [ 'type' => 'pmml' ];
$renderer = new MathMathML( $inputSample, $attribs );
$this->assertEquals( 'pmml', $renderer->getInputType(), 'Checking if MathML input is supported' );
$this->assertTrue( $renderer->render(), 'Rendering Presentation MathML sample' );
@ -113,7 +113,7 @@ class SpecialMathStatus extends SpecialPage {
* i.e. if the span element is generated right.
*/
public function testLaTeXMLIntegration() {
$renderer = MathRenderer::getRenderer( "a+b", array(), 'latexml' );
$renderer = MathRenderer::getRenderer( "a+b", [], 'latexml' );
$this->assertTrue( $renderer->render( true ), "Rendering of a+b in LaTeXML mode" );
// @codingStandardsIgnoreStart
$expected = '<math xmlns="http://www.w3.org/1998/Math/MathML" id="p1.m1" class="ltx_Math" alttext="{\displaystyle a+b}" ><semantics><mrow id="p1.m1.4" xref="p1.m1.4.cmml"><mi id="p1.m1.1" xref="p1.m1.1.cmml">a</mi><mo id="p1.m1.2" xref="p1.m1.2.cmml">+</mo><mi id="p1.m1.3" xref="p1.m1.3.cmml">b</mi></mrow><annotation-xml encoding="MathML-Content"><apply id="p1.m1.4.cmml" xref="p1.m1.4"><plus id="p1.m1.2.cmml" xref="p1.m1.2"/><ci id="p1.m1.1.cmml" xref="p1.m1.1">a</ci><ci id="p1.m1.3.cmml" xref="p1.m1.3">b</ci></apply></annotation-xml><annotation encoding="application/x-tex">{\displaystyle a+b}</annotation></semantics></math>';
@ -137,7 +137,7 @@ class SpecialMathStatus extends SpecialPage {
$tex .= "$i+";
}
$tex .= $testMax;
$renderer = new MathLaTeXML( $tex, array( 'display' => 'linebreak' ) );
$renderer = new MathLaTeXML( $tex, [ 'display' => 'linebreak' ] );
$this->assertTrue( $renderer->render( true ), "Rendering of linebreak test in LaTeXML mode" );
$expected = 'mtr';
$real = preg_replace( "/\n\\s*/", '', $renderer->getHtmlOutput() );
@ -184,7 +184,7 @@ class SpecialMathStatus extends SpecialPage {
if ( ExtensionRegistry::getInstance()->isLoaded( "SyntaxHighlight" ) ) {
$expected = "<syntaxhighlight lang=\"xml\">$expected</syntaxhighlight>";
$real = "<syntaxhighlight lang=\"xml\">$real</syntaxhighlight>";
$this->getOutput()->addWikiMsgArray( $message, array( $real, $expected ) );
$this->getOutput()->addWikiMsgArray( $message, [ $real, $expected ] );
} else {
LoggerFactory::getInstance( 'Math' )->warning( 'Can not display expected and real value.'.
'SyntaxHighlight is not installed.' );

View File

@ -55,14 +55,14 @@ class MathGenerateTests extends Maintenance
$wikiText = Sanitizer::removeHTMLcomments( $wikiText );
$wikiText = preg_replace( '#<nowiki>(.*)</nowiki>#', '', $wikiText );
$math = array();
Parser::extractTagsAndParams( array( 'math' ), $wikiText, $math );
$math = [];
Parser::extractTagsAndParams( [ 'math' ], $wikiText, $math );
return $math;
}
public function execute() {
global $wgUser;
$parserTests = array();
$parserTests = [];
$page = $this->getArg( 0, self::REFERENCE_PAGE );
$offset = $this->getOption( 'offset', 0 );
$length = $this->getOption( 'length', PHP_INT_MAX );
@ -80,7 +80,7 @@ class MathGenerateTests extends Maintenance
foreach ( array_slice( $allEquations, $offset, $length, true ) as $input ) {
$output = MathRenderer::renderMath( $input[1], $input[2], 'png' );
$output = preg_replace( '#src="(.*?)/(([a-f]|\d)*).png"#', 'src="\2.png"', $output );
$parserTests[] = array( (string)$input[1], $output );
$parserTests[] = [ (string)$input[1], $output ];
$i++;
echo '.';
}

View File

@ -78,14 +78,14 @@ class MathCoverageTest extends MediaWikiTestCase {
// TODO: Link to the wikipage that contains the reference rendering
$this->assertEquals(
$this->normalize( $output ),
$this->normalize( MathRenderer::renderMath( $input, array(), 'png' ) ),
$this->normalize( MathRenderer::renderMath( $input, [], 'png' ) ),
"Failed to render $input"
);
}
/**
* Gets the test-data from the file ParserTest.json
* @return array($input, $output) where $input is the test input string
* @return [$input, $output] where $input is the test input string
* and $output is the rendered html5-output string
*/
public function provideCoverage() {

View File

@ -87,10 +87,10 @@ class MathDatabaseTest extends MediaWikiTestCase {
* @covers MathHooks::onLoadExtensionSchemaUpdates
*/
public function testCreateTable() {
$this->setMwGlobals( 'wgMathValidModes', array( 'png' ) );
$this->setMwGlobals( 'wgMathValidModes', [ 'png' ] );
$this->db->dropTable( "math", __METHOD__ );
$dbu = DatabaseUpdater::newForDB( $this->db );
$dbu->doUpdates( array( "extensions" ) );
$dbu->doUpdates( [ "extensions" ] );
$this->expectOutputRegex( '/(.*)Creating math table(.*)/' );
$this->setValues();
$this->renderer->writeToDatabase();
@ -109,12 +109,12 @@ class MathDatabaseTest extends MediaWikiTestCase {
$this->assertTrue( $this->renderer->isChanged() );
$this->assertTrue( $this->renderer->writeCache(), "Write new entry" );
$res = $this->db->selectField( "math", "math_inputhash",
array( "math_inputhash" => $inputHash ) );
[ "math_inputhash" => $inputHash ] );
$this->assertTrue( $res !== false, "Check database entry" );
$this->assertTrue( $this->renderer->readFromDatabase(), "Read entry from database" );
$this->assertFalse( $this->renderer->isChanged() );
// modify the database entry manually
$this->db->delete( "math", array( "math_inputhash" => $inputHash ) );
$this->db->delete( "math", [ "math_inputhash" => $inputHash ] );
// the renderer should not be aware of the modification and should not recreate the entry
$this->assertFalse( $this->renderer->writeCache() );
// as a result no entry can be found in the database.

View File

@ -11,7 +11,7 @@ class MathHooksTest extends MediaWikiTestCase {
public function testMathModeToString() {
$default = 'png-testing'; // use a different string for testing only
$testCases = array(
$testCases = [
'MW_MATH_SIMPLE' => $default,
'MW_MATH_HTML' => $default,
'MW_MATH_MODERN' => $default,
@ -34,7 +34,7 @@ class MathHooksTest extends MediaWikiTestCase {
'source' => 'source',
'mathml' => 'mathml',
'latexml' => 'latexml',
);
];
foreach ( $testCases as $input => $expected ){
$real = MathHooks::mathModeToString( $input, $default );
$this->assertEquals( $expected, $real, "Conversion math mode $input -> $expected" );
@ -43,7 +43,7 @@ class MathHooksTest extends MediaWikiTestCase {
public function testMathStyleToString() {
$default = 'inlineDisplaystyle-test';
$testCases = array(
$testCases = [
'MW_MATHSTYLE_INLINE_DISPLAYSTYLE' => 'inlineDisplaystyle',
'MW_MATHSTYLE_DISPLAY' => 'display',
'MW_MATHSTYLE_INLINE' => 'inline',
@ -53,7 +53,7 @@ class MathHooksTest extends MediaWikiTestCase {
'inlineDisplaystyle' => 'inlineDisplaystyle',
'display' => 'display',
'inline' => 'inline',
);
];
foreach ( $testCases as $input => $expected ){
$real = MathHooks::mathStyleToString( $input, $default );
$this->assertEquals( $expected, $real, "Conversion in math style" );
@ -62,7 +62,7 @@ class MathHooksTest extends MediaWikiTestCase {
public function testMathCheckToString() {
$default = 'always-default';
$testCases = array(
$testCases = [
'MW_MATH_CHECK_ALWAYS' => 'always',
'MW_MATH_CHECK_NEVER' => 'never',
'MW_MATH_CHECK_NEW' => 'new',
@ -74,7 +74,7 @@ class MathHooksTest extends MediaWikiTestCase {
'new' => 'new',
true => 'never',
false => 'always'
);
];
foreach ( $testCases as $input => $expected ){
$real = MathHooks::mathCheckToString( $input, $default );
@ -84,13 +84,13 @@ class MathHooksTest extends MediaWikiTestCase {
public function testMathModeToHash() {
$default = 0;
$testCases = array(
$testCases = [
'png' => 0,
'source' => 3,
'mathml' => 5,
'latexml'=> 7,
'invalid'=> $default
);
];
foreach ( $testCases as $input => $expected ){
$real = MathHooks::mathModeToHashKey( $input, $default );

View File

@ -16,7 +16,7 @@ class MathIdTest extends MediaWikiTestCase {
*/
public function testBasics() {
define( 'RANDOM_ID', 'a_random_id' );
$renderer = MathRenderer::getRenderer( "a+b", array( 'id' => RANDOM_ID ) );
$renderer = MathRenderer::getRenderer( "a+b", [ 'id' => RANDOM_ID ] );
$this->assertEquals( RANDOM_ID, $renderer->getId() );
}

View File

@ -31,7 +31,7 @@ class MathInputCheckTest extends MediaWikiTestCase
*/
public function testGetValidTex() {
$InputCheck = $this->getMockBuilder( 'MathInputCheck' )
->setConstructorArgs( array( 'some tex input' ) )
->setConstructorArgs( [ 'some tex input' ] )
->getMock();
$this->assertNull( $InputCheck->getValidTex() );
}

View File

@ -71,7 +71,7 @@ class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
public function testTableName() {
$fnGetMathTableName = self::getMethod( 'getMathTableName' );
$obj = new MathLaTeXML();
$tableName = $fnGetMathTableName->invokeArgs( $obj, array() );
$tableName = $fnGetMathTableName->invokeArgs( $obj, [] );
$this->assertEquals( $tableName, "mathlatexml", "Wrong latexml table name" );
}
@ -80,10 +80,10 @@ class MathLaTeXMLDatabaseTest extends MediaWikiTestCase {
* @covers MathHooks::onLoadExtensionSchemaUpdates
*/
public function testCreateTable() {
$this->setMwGlobals( 'wgMathValidModes', array( 'latexml' ) );
$this->setMwGlobals( 'wgMathValidModes', [ 'latexml' ] );
$this->db->dropTable( "mathlatexml", __METHOD__ );
$dbu = DatabaseUpdater::newForDB( $this->db );
$dbu->doUpdates( array( "extensions" ) );
$dbu->doUpdates( [ "extensions" ] );
$this->expectOutputRegex( '/(.*)Creating mathlatexml table(.*)/' );
$this->setValues();
$this->renderer->writeToDatabase();

View File

@ -20,12 +20,13 @@ class MathLaTeXMLTest extends MediaWikiTestCase {
->setMethods( null )
->disableOriginalConstructor()
->getMock();
$sampleSettings = array(
$sampleSettings = [
'k1' => 'v1',
'k2&=' => 'v2 + & *üö',
'k3' => array(
'k3' => [
'v3A', 'v3b'
) );
]
];
$expected = 'k1=v1&k2%26%3D=v2+%2B+%26+%2A%C3%BC%C3%B6&k3=v3A&k3=v3b';
$this->assertEquals(
$expected,

View File

@ -38,7 +38,7 @@ class MathRendererTest extends MediaWikiTestCase {
* @covers MathRenderer::__construct()
*/
public function testBasics() {
$renderer = $this->getMockForAbstractClass( 'MathRenderer', array( self::SOME_TEX ) );
$renderer = $this->getMockForAbstractClass( 'MathRenderer', [ self::SOME_TEX ] );
// check if the TeX input was corretly passed to the class
$this->assertEquals( self::SOME_TEX, $renderer->getTex(), "test getTex" );
$this->assertEquals( $renderer->isChanged(), false, "test if changed is initially false" );
@ -50,12 +50,12 @@ class MathRendererTest extends MediaWikiTestCase {
*/
public function testWriteCacheSkip() {
$renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
$this->getMockBuilder( 'MathRenderer' )->setMethods( [
'writeToDatabase',
'render',
'getMathTableName',
'getHtmlOutput'
) )->disableOriginalConstructor()->getMock();
] )->disableOriginalConstructor()->getMock();
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
$renderer->writeCache();
}
@ -66,23 +66,23 @@ class MathRendererTest extends MediaWikiTestCase {
*/
public function testWriteCache() {
$renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
$this->getMockBuilder( 'MathRenderer' )->setMethods( [
'writeToDatabase',
'render',
'getMathTableName',
'getHtmlOutput'
) )->disableOriginalConstructor()->getMock();
] )->disableOriginalConstructor()->getMock();
$renderer->expects( $this->never() )->method( 'writeToDatabase' );
$renderer->writeCache();
}
public function testSetPurge() {
$renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
$this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render',
'getMathTableName',
'getHtmlOutput'
) )->disableOriginalConstructor()->getMock();
] )->disableOriginalConstructor()->getMock();
$renderer->setPurge();
$this->assertEquals( $renderer->isPurge(), true, "Test purge." );
@ -91,13 +91,13 @@ class MathRendererTest extends MediaWikiTestCase {
public function testDisableCheckingAlways() {
$this->setMwGlobals( "wgMathDisableTexFilter", 'never' );
$renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
$this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render',
'getMathTableName',
'getHtmlOutput',
'readFromDatabase',
'setTex'
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock();
] )->setConstructorArgs( [ self::TEXVCCHECK_INPUT ] )->getMock();
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
@ -110,13 +110,13 @@ class MathRendererTest extends MediaWikiTestCase {
public function testDisableCheckingNever() {
$this->setMwGlobals( "wgMathDisableTexFilter", 'always' );
$renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
$this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render',
'getMathTableName',
'getHtmlOutput',
'readFromDatabase',
'setTex'
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock();
] )->setConstructorArgs( [ self::TEXVCCHECK_INPUT ] )->getMock();
$renderer->expects( $this->never() )->method( 'readFromDatabase' );
$renderer->expects( $this->never() )->method( 'setTex' );
@ -126,13 +126,13 @@ class MathRendererTest extends MediaWikiTestCase {
public function testCheckingNewUnknown() {
$this->setMwGlobals( "wgMathDisableTexFilter", 'new' );
$renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
$this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render',
'getMathTableName',
'getHtmlOutput',
'readFromDatabase',
'setTex'
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock();
] )->setConstructorArgs( [ self::TEXVCCHECK_INPUT ] )->getMock();
$renderer->expects( $this->once() )->method( 'readFromDatabase' )
->will( $this->returnValue( false ) );
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
@ -145,13 +145,13 @@ class MathRendererTest extends MediaWikiTestCase {
public function testCheckingNewKnown() {
$this->setMwGlobals( "wgMathDisableTexFilter", 'new' );
$renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array(
$this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render',
'getMathTableName',
'getHtmlOutput',
'readFromDatabase',
'setTex'
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock();
] )->setConstructorArgs( [ self::TEXVCCHECK_INPUT ] )->getMock();
$renderer->expects( $this->exactly( 2 ) )->method( 'readFromDatabase' )
->will( $this->returnValue( true ) );
$renderer->expects( $this->never() )->method( 'setTex' );

View File

@ -16,7 +16,7 @@ class MathSourceTest extends MediaWikiTestCase {
* i.e. if the span element is generated right.
*/
public function testBasics() {
$real = MathRenderer::renderMath( "a+b", array(), 'source' );
$real = MathRenderer::renderMath( "a+b", [], 'source' );
$this->assertEquals(
'<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a+b $</span>',
$real,
@ -28,7 +28,7 @@ class MathSourceTest extends MediaWikiTestCase {
* Checks if newlines are converted to spaces correctly.
*/
public function testNewLines() {
$real = MathRenderer::renderMath( "a\n b", array(), 'source' );
$real = MathRenderer::renderMath( "a\n b", [], 'source' );
$this->assertSame(
'<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a b $</span>',
$real,

View File

@ -29,7 +29,7 @@ class MathTexvcTest extends MediaWikiTestCase {
// Create a MathTexvc mock, replacing methods 'readFromDatabase',
// 'callTexvc', and 'doHTMLRender' with test doubles.
$texvc = $this->getMockBuilder( 'MathTexvc' )
->setMethods( array( 'readCache', 'callTexvc', 'getHtmlOutput' ) )
->setMethods( [ 'readCache', 'callTexvc', 'getHtmlOutput' ] )
->disableOriginalConstructor()
->getMock();
@ -61,7 +61,7 @@ class MathTexvcTest extends MediaWikiTestCase {
*/
function testRenderCacheMiss() {
$texvc = $this->getMockBuilder( 'MathTexvc' )
->setMethods( array( 'readCache', 'callTexvc', 'getHtmlOutput' ) )
->setMethods( [ 'readCache', 'callTexvc', 'getHtmlOutput' ] )
->disableOriginalConstructor()
->getMock();
@ -92,7 +92,7 @@ class MathTexvcTest extends MediaWikiTestCase {
*/
function testRenderTexvcFailure() {
$texvc = $this->getMockBuilder( 'MathTexvc' )
->setMethods( array( 'readCache', 'callTexvc', 'getHtmlOutput' ) )
->setMethods( [ 'readCache', 'callTexvc', 'getHtmlOutput' ] )
->disableOriginalConstructor()
->getMock();
@ -175,7 +175,7 @@ class MathTexvcTest extends MediaWikiTestCase {
*/
public function testChangeHash() {
$renderer = $this->getMockBuilder( 'MathTexvc' )
->setMethods( array( 'render', 'getMathTableName' ) )
->setMethods( [ 'render', 'getMathTableName' ] )
->disableOriginalConstructor()
->getMock();
$this->assertEquals(