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 * @ingroup Extensions
*/ */
$specialPageAliases = array(); $specialPageAliases = [];
/** English (English) */ /** English (English) */
$specialPageAliases['en'] = array( $specialPageAliases['en'] = [
'MathShowImage' => array( 'MathShowImage' ) 'MathShowImage' => [ 'MathShowImage' ]
); ];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,8 +13,8 @@ use MediaWiki\Logger\LoggerFactory;
*/ */
class MathMathML extends MathRenderer { class MathMathML extends MathRenderer {
protected $defaultAllowedRootElements = array( 'math' ); protected $defaultAllowedRootElements = [ 'math' ];
protected $restbaseInputTypes = array( 'tex', 'inline-tex', 'chem' ); protected $restbaseInputTypes = [ 'tex', 'inline-tex', 'chem' ];
protected $allowedRootElements = ''; protected $allowedRootElements = '';
protected $hosts; protected $hosts;
@ -23,7 +23,7 @@ class MathMathML extends MathRenderer {
private $svgPath = false; private $svgPath = false;
private $mathoidStyle; private $mathoidStyle;
public function __construct( $tex = '', $params = array() ) { public function __construct( $tex = '', $params = [] ) {
global $wgMathMathMLUrl; global $wgMathMathMLUrl;
parent::__construct( $tex, $params ); parent::__construct( $tex, $params );
$this->setMode( 'mathml' ); $this->setMode( 'mathml' );
@ -163,7 +163,7 @@ class MathMathML extends MathRenderer {
if ( !$post ) { if ( !$post ) {
$this->getPostData(); $this->getPostData();
} }
$options = array( 'method' => 'POST', 'postData' => $post, 'timeout' => $wgMathLaTeXMLTimeout ); $options = [ 'method' => 'POST', 'postData' => $post, 'timeout' => $wgMathLaTeXMLTimeout ];
/** @var $req (CurlHttpRequest|PhpHttpRequest) the request object */ /** @var $req (CurlHttpRequest|PhpHttpRequest) the request object */
$req = $httpRequestClass::factory( $host, $options ); $req = $httpRequestClass::factory( $host, $options );
/** @var Status $req Status the request status */ /** @var Status $req Status the request status */
@ -175,22 +175,22 @@ class MathMathML extends MathRenderer {
if ( $status->hasMessage( 'http-timed-out' ) ) { if ( $status->hasMessage( 'http-timed-out' ) ) {
$error = $this->getError( 'math_timeout', $this->getModeStr(), $host ); $error = $this->getError( 'math_timeout', $this->getModeStr(), $host );
$res = false; $res = false;
LoggerFactory::getInstance( 'Math' )->warning( 'Timeout:' . var_export( array( LoggerFactory::getInstance( 'Math' )->warning( 'Timeout:' . var_export( [
'post' => $post, 'post' => $post,
'host' => $host, 'host' => $host,
'timeout' => $wgMathLaTeXMLTimeout 'timeout' => $wgMathLaTeXMLTimeout
), true ) ); ], true ) );
} else { } else {
// for any other unkonwn http error // for any other unkonwn http error
$errormsg = $status->getHtml(); $errormsg = $status->getHtml();
$error = $error =
$this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg, $this->getError( 'math_invalidresponse', $this->getModeStr(), $host, $errormsg,
$this->getModeStr( 'mathml' ) ); $this->getModeStr( 'mathml' ) );
LoggerFactory::getInstance( 'Math' )->warning( 'NoResponse:' . var_export( array( LoggerFactory::getInstance( 'Math' )->warning( 'NoResponse:' . var_export( [
'post' => $post, 'post' => $post,
'host' => $host, 'host' => $host,
'errormsg' => $errormsg 'errormsg' => $errormsg
), true ) ); ], true ) );
} }
return false; return false;
} }
@ -264,21 +264,21 @@ class MathMathML extends MathRenderer {
} }
$this->lastError = $this->getError( 'math_mathoid_error', $host, $log ); $this->lastError = $this->getError( 'math_mathoid_error', $host, $log );
LoggerFactory::getInstance( 'Math' )->warning( LoggerFactory::getInstance( 'Math' )->warning(
'Mathoid conversion error:' . var_export( array( 'Mathoid conversion error:' . var_export( [
'post' => $post, 'post' => $post,
'host' => $host, 'host' => $host,
'result' => $res 'result' => $res
), true ) ); ], true ) );
return false; return false;
} }
} else { } else {
$this->lastError = $this->getError( 'math_invalidjson', $host ); $this->lastError = $this->getError( 'math_invalidjson', $host );
LoggerFactory::getInstance( 'Math' )->error( LoggerFactory::getInstance( 'Math' )->error(
'MathML InvalidJSON:' . var_export( array( 'MathML InvalidJSON:' . var_export( [
'post' => $post, 'post' => $post,
'host' => $host, 'host' => $host,
'res' => $res 'res' => $res
), true ) ); ], true ) );
return false; return false;
} }
} else { } else {
@ -328,10 +328,11 @@ class MathMathML extends MathRenderer {
if ( $this->svgPath ) { if ( $this->svgPath ) {
return $this->svgPath; return $this->svgPath;
} }
return SpecialPage::getTitleFor( 'MathShowImage' )->getLocalURL( array( return SpecialPage::getTitleFor( 'MathShowImage' )->getLocalURL( [
'hash' => $this->getMd5(), 'hash' => $this->getMd5(),
'mode' => $this->getMode(), 'mode' => $this->getMode(),
'noRender' => $noRender ) 'noRender' => $noRender
]
); );
} }
@ -374,7 +375,7 @@ class MathMathML extends MathRenderer {
private function getFallbackImage( $noRender = false, $classOverride = false ) { private function getFallbackImage( $noRender = false, $classOverride = false ) {
$url = $this->getFallbackImageUrl( $noRender ); $url = $this->getFallbackImageUrl( $noRender );
$attribs = array(); $attribs = [];
if ( $classOverride === false ) { // $class = '' suppresses class attribute if ( $classOverride === false ) { // $class = '' suppresses class attribute
$class = $this->getClassName( true ); $class = $this->getClassName( true );
} else { } 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 // Don't use an empty span, as that is going to be stripped by HTML tidy
// when enabled (which is true in production). // when enabled (which is true in production).
return Xml::element( 'meta', $this->getAttributes( return Xml::element( 'meta', $this->getAttributes(
'span', $attribs, array( 'aria-hidden' => 'true', 'style' => $style 'span', $attribs, [ 'aria-hidden' => 'true', 'style' => $style
) ) ); ] ) );
} }
protected function getMathTableName() { protected function getMathTableName() {
@ -436,7 +437,7 @@ class MathMathML extends MathRenderer {
} else { } else {
$element = 'span'; $element = 'span';
} }
$attribs = array(); $attribs = [];
if ( $this->getID() !== '' ) { if ( $this->getID() !== '' ) {
$attribs['id'] = $this->getID(); $attribs['id'] = $this->getID();
} }
@ -450,9 +451,9 @@ 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, array( $output .= Xml::tags( $element, [
'class' => $this->getClassName(), 'style' => 'display: none;' 'class' => $this->getClassName(), 'style' => 'display: none;'
), $mml ); ], $mml );
$output .= $this->getFallbackImage(); $output .= $this->getFallbackImage();
$output .= Html::closeElement( $element ); $output .= Html::closeElement( $element );
return $output; return $output;
@ -470,7 +471,7 @@ class MathMathML extends MathRenderer {
protected function dbInArray() { protected function dbInArray() {
$out = parent::dbInArray(); $out = parent::dbInArray();
if ( $this->getMathTableName() == 'mathoid' ) { if ( $this->getMathTableName() == 'mathoid' ) {
$out = array_diff( $out, array( 'math_inputtex' ) ); $out = array_diff( $out, [ 'math_inputtex' ] );
$out[] = 'math_input'; $out[] = 'math_input';
} }
return $out; return $out;
@ -512,8 +513,7 @@ class MathMathML extends MathRenderer {
$this->setMathml( $jsonResult->mml ); $this->setMathml( $jsonResult->mml );
} }
Hooks::run( 'MathRenderingResultRetrieved', Hooks::run( 'MathRenderingResultRetrieved',
array( &$this, [ $this, $jsonResult ] ); // Enables debugging of server results
&$jsonResult ) ); // Enables debugging of server results
return true; return true;
} else { } else {
$this->lastError = $this->getError( 'math_unknown_error', $host ); $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 */ /** @var ('inlineDisplaystyle'|'display'|'inline'|'linebreak') the rendering style */
protected $mathStyle = 'inlineDisplaystyle'; protected $mathStyle = 'inlineDisplaystyle';
/** @var array with userdefined parameters passed to the extension (not used) */ /** @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. */ /** @var string a userdefined identifier to link to the equation. */
protected $id = ''; protected $id = '';
@ -67,7 +67,7 @@ abstract class MathRenderer {
* @param string $tex (optional) LaTeX markup * @param string $tex (optional) LaTeX markup
* @param array $params (optional) HTML attributes * @param array $params (optional) HTML attributes
*/ */
public function __construct( $tex = '', $params = array() ) { public function __construct( $tex = '', $params = [] ) {
$this->params = $params; $this->params = $params;
if ( isset( $params['id'] ) ) { if ( isset( $params['id'] ) ) {
$this->id = $params['id']; $this->id = $params['id'];
@ -109,7 +109,7 @@ abstract class MathRenderer {
* @param string $mode constant indicating rendering mode * @param string $mode constant indicating rendering mode
* @return string HTML for math tag * @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 ); $renderer = self::getRenderer( $tex, $params, $mode );
if ( $renderer->render() ) { if ( $renderer->render() ) {
return $renderer->getHtmlOutput(); return $renderer->getHtmlOutput();
@ -140,7 +140,7 @@ abstract class MathRenderer {
* @param string $mode indicating rendering mode * @param string $mode indicating rendering mode
* @return MathRenderer appropriate renderer for 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; global $wgDefaultUserOptions, $wgMathEnableExperimentalInputFormats;
if ( isset( $params['forcemathmode'] ) ) { if ( isset( $params['forcemathmode'] ) ) {
@ -153,7 +153,7 @@ abstract class MathRenderer {
isset( $params['type'] ) ) { isset( $params['type'] ) ) {
// Support of MathML input (experimental) // Support of MathML input (experimental)
// Currently support for mode 'mathml' only // Currently support for mode 'mathml' only
if ( !in_array( $params['type'], array( 'pmml', 'ascii' ) ) ) { if ( !in_array( $params['type'], [ 'pmml', 'ascii' ] ) ) {
unset( $params['type'] ); unset( $params['type'] );
} }
} }
@ -268,7 +268,7 @@ abstract class MathRenderer {
$dbr = wfGetDB( DB_SLAVE ); $dbr = wfGetDB( DB_SLAVE );
$rpage = $dbr->selectRow( $this->getMathTableName(), $rpage = $dbr->selectRow( $this->getMathTableName(),
$this->dbInArray(), $this->dbInArray(),
array( 'math_inputhash' => $this->getInputHash() ), [ 'math_inputhash' => $this->getInputHash() ],
__METHOD__ ); __METHOD__ );
if ( $rpage !== false ) { if ( $rpage !== false ) {
$this->initializeFromDatabaseRow( $rpage ); $this->initializeFromDatabaseRow( $rpage );
@ -285,12 +285,12 @@ abstract class MathRenderer {
* @return array with the database column names * @return array with the database column names
*/ */
protected function dbInArray() { protected function dbInArray() {
$in = array( 'math_inputhash', $in = [ 'math_inputhash',
'math_mathml', 'math_mathml',
'math_inputtex', 'math_inputtex',
'math_tex', 'math_tex',
'math_svg' 'math_svg'
); ];
return $in; return $in;
} }
@ -343,7 +343,7 @@ abstract class MathRenderer {
$dbw, $outArray, $inputHash, $method, $mathTableName $dbw, $outArray, $inputHash, $method, $mathTableName
) { ) {
$dbw->update( $mathTableName, $outArray, $dbw->update( $mathTableName, $outArray,
array( 'math_inputhash' => $inputHash ), $method ); [ 'math_inputhash' => $inputHash ], $method );
LoggerFactory::getInstance( 'Math' )->debug( LoggerFactory::getInstance( 'Math' )->debug(
'Row updated after db transaction was idle: ' . 'Row updated after db transaction was idle: ' .
var_export( $outArray, true ) . " to database" ); var_export( $outArray, true ) . " to database" );
@ -352,7 +352,7 @@ abstract class MathRenderer {
$dbw->onTransactionIdle( function () use ( $dbw->onTransactionIdle( function () use (
$dbw, $outArray, $method, $mathTableName $dbw, $outArray, $method, $mathTableName
) { ) {
$dbw->insert( $mathTableName, $outArray, $method, array( 'IGNORE' ) ); $dbw->insert( $mathTableName, $outArray, $method, [ 'IGNORE' ] );
LoggerFactory::getInstance( 'Math' )->debug( LoggerFactory::getInstance( 'Math' )->debug(
'Row inserted after db transaction was idle ' . 'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database" ); var_export( $outArray, true ) . " to database" );
@ -371,12 +371,13 @@ abstract class MathRenderer {
* @return array * @return array
*/ */
protected function dbOutArray() { protected function dbOutArray() {
$out = array( 'math_inputhash' => $this->getInputHash(), $out = [
'math_inputhash' => $this->getInputHash(),
'math_mathml' => utf8_encode( $this->mathml ), 'math_mathml' => utf8_encode( $this->mathml ),
'math_inputtex' => $this->userInputTex, 'math_inputtex' => $this->userInputTex,
'math_tex' => $this->tex, 'math_tex' => $this->tex,
'math_svg' => $this->svg 'math_svg' => $this->svg
); ];
return $out; return $out;
} }
@ -395,7 +396,7 @@ abstract class MathRenderer {
* @param array $overrides attributes to override defaults * @param array $overrides attributes to override defaults
* @return array HTML attributes * @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::validateTagAttributes( $this->params, $tag );
$attribs = Sanitizer::mergeAttributes( $defaults, $attribs ); $attribs = Sanitizer::mergeAttributes( $defaults, $attribs );
$attribs = Sanitizer::mergeAttributes( $attribs, $overrides ); $attribs = Sanitizer::mergeAttributes( $attribs, $overrides );
@ -485,14 +486,14 @@ abstract class MathRenderer {
/** /**
* Get the attributes of the math tag * Get the attributes of the math tag
* *
* @return array() * @return []
*/ */
public function getParams() { public function getParams() {
return $this->params; return $this->params;
} }
/** /**
* @param array() $params * @param [] $params
*/ */
public function setParams( $params ) { public function setParams( $params ) {
// $changed is not set to true here, because the attributes do not affect // $changed is not set to true here, because the attributes do not affect

View File

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

View File

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

View File

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

View File

@ -1,10 +1,10 @@
<?php <?php
use DataValues\StringValue;
use ValueFormatters\Exceptions\MismatchingDataValueTypeException; use ValueFormatters\Exceptions\MismatchingDataValueTypeException;
use ValueValidators\Error;
use ValueValidators\Result; use ValueValidators\Result;
use ValueValidators\ValueValidator; use ValueValidators\ValueValidator;
use ValueValidators\Error;
use DataValues\StringValue;
// @author Duc Linh Tran, Julian Hilbig, Moritz Schubotz // @author Duc Linh Tran, Julian Hilbig, Moritz Schubotz
@ -33,9 +33,9 @@ class MathValidator implements ValueValidator {
// TeX string is not valid // TeX string is not valid
return Result::newError( 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; return;
} }
$dataTypeDefinitions['PT:math'] = array( $dataTypeDefinitions['PT:math'] = [
'value-type' => 'string', 'value-type' => 'string',
'validator-factory-callback' => function() { 'validator-factory-callback' => function() {
// load validator builders // load validator builders
@ -41,7 +41,7 @@ class MathWikidataHook {
}, },
'formatter-factory-callback' => function( $format, FormatterOptions $options ) { 'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
global $wgOut; 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 ); $wgOut->addModuleStyles( $styles );
return new MathFormatter( $format ); return new MathFormatter( $format );
}, },
@ -54,7 +54,7 @@ class MathWikidataHook {
) { ) {
return new MathMLRdfBuilder(); return new MathMLRdfBuilder();
}, },
); ];
} }
/* /*
@ -67,15 +67,15 @@ class MathWikidataHook {
return; return;
} }
$dataTypeDefinitions['PT:math'] = array( $dataTypeDefinitions['PT:math'] = [
'value-type' => 'string', 'value-type' => 'string',
'formatter-factory-callback' => function( $format, FormatterOptions $options ) { 'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
global $wgOut; 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 ); $wgOut->addModuleStyles( $styles );
return new MathFormatter( $format ); return new MathFormatter( $format );
}, },
); ];
} }
} }

2
README
View File

@ -58,4 +58,4 @@ from your MediWiki home path.
== Logging == == Logging ==
The math extension supports PSR-3 logging: The math extension supports PSR-3 logging:
Configuration can be dona via 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 = MathMathML::newFromMd5( $hash );
$mmlRenderer->readFromDatabase(); $mmlRenderer->readFromDatabase();
$this->renderer = MathRenderer::getRenderer( $this->renderer = MathRenderer::getRenderer(
$mmlRenderer->getUserInputTex(), array(), 'png' $mmlRenderer->getUserInputTex(), [], 'png'
); );
$this->renderer->setMathStyle( $mmlRenderer->getMathStyle() ); $this->renderer->setMathStyle( $mmlRenderer->getMathStyle() );
} }
$success = $this->renderer->render(); $success = $this->renderer->render();
} }
} elseif ( $asciimath === '' ) { } elseif ( $asciimath === '' ) {
$this->renderer = MathRenderer::getRenderer( $tex, array(), $this->mode ); $this->renderer = MathRenderer::getRenderer( $tex, [], $this->mode );
$success = $this->renderer->render(); $success = $this->renderer->render();
} else { } else {
$this->renderer = MathRenderer::getRenderer( $this->renderer = MathRenderer::getRenderer(
$asciimath, array( 'type' => 'ascii' ), $this->mode $asciimath, [ 'type' => 'ascii' ], $this->mode
); );
$success = $this->renderer->render(); $success = $this->renderer->render();
} }

View File

@ -63,7 +63,7 @@ class SpecialMathStatus extends SpecialPage {
} }
public function testSpecialCaseText() { 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>'; $expected = 'a sample Text</mtext>';
$this->assertTrue( $renderer->render(), 'Rendering the input "x^2+\text{a sample Text}"' ); $this->assertTrue( $renderer->render(), 'Rendering the input "x^2+\text{a sample Text}"' );
$this->assertContains( $this->assertContains(
@ -78,7 +78,7 @@ class SpecialMathStatus extends SpecialPage {
public function testMathMLIntegration() { public function testMathMLIntegration() {
$svgRef = file_get_contents( __DIR__ .'/images/reference.svg' ); $svgRef = file_get_contents( __DIR__ .'/images/reference.svg' );
$svgRefNoSpeech = file_get_contents( __DIR__ .'/images/reference-nospeech.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" ); $this->assertTrue( $renderer->render( true ), "Rendering of a+b in plain MathML mode" );
$real = str_replace( "\n", '', $renderer->getHtmlOutput() ); $real = str_replace( "\n", '', $renderer->getHtmlOutput() );
$expected = '<mo>+</mo>'; $expected = '<mo>+</mo>';
@ -99,7 +99,7 @@ class SpecialMathStatus extends SpecialPage {
// @codingStandardsIgnoreStart // @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>'; $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 // @codingStandardsIgnoreEnd
$attribs = array( 'type' => 'pmml' ); $attribs = [ 'type' => 'pmml' ];
$renderer = new MathMathML( $inputSample, $attribs ); $renderer = new MathMathML( $inputSample, $attribs );
$this->assertEquals( 'pmml', $renderer->getInputType(), 'Checking if MathML input is supported' ); $this->assertEquals( 'pmml', $renderer->getInputType(), 'Checking if MathML input is supported' );
$this->assertTrue( $renderer->render(), 'Rendering Presentation MathML sample' ); $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. * i.e. if the span element is generated right.
*/ */
public function testLaTeXMLIntegration() { 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" ); $this->assertTrue( $renderer->render( true ), "Rendering of a+b in LaTeXML mode" );
// @codingStandardsIgnoreStart // @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>'; $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 .= "$i+";
} }
$tex .= $testMax; $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" ); $this->assertTrue( $renderer->render( true ), "Rendering of linebreak test in LaTeXML mode" );
$expected = 'mtr'; $expected = 'mtr';
$real = preg_replace( "/\n\\s*/", '', $renderer->getHtmlOutput() ); $real = preg_replace( "/\n\\s*/", '', $renderer->getHtmlOutput() );
@ -184,7 +184,7 @@ class SpecialMathStatus extends SpecialPage {
if ( ExtensionRegistry::getInstance()->isLoaded( "SyntaxHighlight" ) ) { if ( ExtensionRegistry::getInstance()->isLoaded( "SyntaxHighlight" ) ) {
$expected = "<syntaxhighlight lang=\"xml\">$expected</syntaxhighlight>"; $expected = "<syntaxhighlight lang=\"xml\">$expected</syntaxhighlight>";
$real = "<syntaxhighlight lang=\"xml\">$real</syntaxhighlight>"; $real = "<syntaxhighlight lang=\"xml\">$real</syntaxhighlight>";
$this->getOutput()->addWikiMsgArray( $message, array( $real, $expected ) ); $this->getOutput()->addWikiMsgArray( $message, [ $real, $expected ] );
} else { } else {
LoggerFactory::getInstance( 'Math' )->warning( 'Can not display expected and real value.'. LoggerFactory::getInstance( 'Math' )->warning( 'Can not display expected and real value.'.
'SyntaxHighlight is not installed.' ); 'SyntaxHighlight is not installed.' );

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ class MathIdTest extends MediaWikiTestCase {
*/ */
public function testBasics() { public function testBasics() {
define( 'RANDOM_ID', 'a_random_id' ); 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() ); $this->assertEquals( RANDOM_ID, $renderer->getId() );
} }

View File

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

View File

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

View File

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

View File

@ -38,7 +38,7 @@ class MathRendererTest extends MediaWikiTestCase {
* @covers MathRenderer::__construct() * @covers MathRenderer::__construct()
*/ */
public function testBasics() { 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 // check if the TeX input was corretly passed to the class
$this->assertEquals( self::SOME_TEX, $renderer->getTex(), "test getTex" ); $this->assertEquals( self::SOME_TEX, $renderer->getTex(), "test getTex" );
$this->assertEquals( $renderer->isChanged(), false, "test if changed is initially false" ); $this->assertEquals( $renderer->isChanged(), false, "test if changed is initially false" );
@ -50,12 +50,12 @@ class MathRendererTest extends MediaWikiTestCase {
*/ */
public function testWriteCacheSkip() { public function testWriteCacheSkip() {
$renderer = $renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array( $this->getMockBuilder( 'MathRenderer' )->setMethods( [
'writeToDatabase', 'writeToDatabase',
'render', 'render',
'getMathTableName', 'getMathTableName',
'getHtmlOutput' 'getHtmlOutput'
) )->disableOriginalConstructor()->getMock(); ] )->disableOriginalConstructor()->getMock();
$renderer->expects( $this->never() )->method( 'writeToDatabase' ); $renderer->expects( $this->never() )->method( 'writeToDatabase' );
$renderer->writeCache(); $renderer->writeCache();
} }
@ -66,23 +66,23 @@ class MathRendererTest extends MediaWikiTestCase {
*/ */
public function testWriteCache() { public function testWriteCache() {
$renderer = $renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array( $this->getMockBuilder( 'MathRenderer' )->setMethods( [
'writeToDatabase', 'writeToDatabase',
'render', 'render',
'getMathTableName', 'getMathTableName',
'getHtmlOutput' 'getHtmlOutput'
) )->disableOriginalConstructor()->getMock(); ] )->disableOriginalConstructor()->getMock();
$renderer->expects( $this->never() )->method( 'writeToDatabase' ); $renderer->expects( $this->never() )->method( 'writeToDatabase' );
$renderer->writeCache(); $renderer->writeCache();
} }
public function testSetPurge() { public function testSetPurge() {
$renderer = $renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array( $this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render', 'render',
'getMathTableName', 'getMathTableName',
'getHtmlOutput' 'getHtmlOutput'
) )->disableOriginalConstructor()->getMock(); ] )->disableOriginalConstructor()->getMock();
$renderer->setPurge(); $renderer->setPurge();
$this->assertEquals( $renderer->isPurge(), true, "Test purge." ); $this->assertEquals( $renderer->isPurge(), true, "Test purge." );
@ -91,13 +91,13 @@ class MathRendererTest extends MediaWikiTestCase {
public function testDisableCheckingAlways() { public function testDisableCheckingAlways() {
$this->setMwGlobals( "wgMathDisableTexFilter", 'never' ); $this->setMwGlobals( "wgMathDisableTexFilter", 'never' );
$renderer = $renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array( $this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render', 'render',
'getMathTableName', 'getMathTableName',
'getHtmlOutput', 'getHtmlOutput',
'readFromDatabase', 'readFromDatabase',
'setTex' 'setTex'
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock(); ] )->setConstructorArgs( [ self::TEXVCCHECK_INPUT ] )->getMock();
$renderer->expects( $this->never() )->method( 'readFromDatabase' ); $renderer->expects( $this->never() )->method( 'readFromDatabase' );
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT ); $renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
@ -110,13 +110,13 @@ class MathRendererTest extends MediaWikiTestCase {
public function testDisableCheckingNever() { public function testDisableCheckingNever() {
$this->setMwGlobals( "wgMathDisableTexFilter", 'always' ); $this->setMwGlobals( "wgMathDisableTexFilter", 'always' );
$renderer = $renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array( $this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render', 'render',
'getMathTableName', 'getMathTableName',
'getHtmlOutput', 'getHtmlOutput',
'readFromDatabase', 'readFromDatabase',
'setTex' 'setTex'
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock(); ] )->setConstructorArgs( [ self::TEXVCCHECK_INPUT ] )->getMock();
$renderer->expects( $this->never() )->method( 'readFromDatabase' ); $renderer->expects( $this->never() )->method( 'readFromDatabase' );
$renderer->expects( $this->never() )->method( 'setTex' ); $renderer->expects( $this->never() )->method( 'setTex' );
@ -126,13 +126,13 @@ class MathRendererTest extends MediaWikiTestCase {
public function testCheckingNewUnknown() { public function testCheckingNewUnknown() {
$this->setMwGlobals( "wgMathDisableTexFilter", 'new' ); $this->setMwGlobals( "wgMathDisableTexFilter", 'new' );
$renderer = $renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array( $this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render', 'render',
'getMathTableName', 'getMathTableName',
'getHtmlOutput', 'getHtmlOutput',
'readFromDatabase', 'readFromDatabase',
'setTex' 'setTex'
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock(); ] )->setConstructorArgs( [ self::TEXVCCHECK_INPUT ] )->getMock();
$renderer->expects( $this->once() )->method( 'readFromDatabase' ) $renderer->expects( $this->once() )->method( 'readFromDatabase' )
->will( $this->returnValue( false ) ); ->will( $this->returnValue( false ) );
$renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT ); $renderer->expects( $this->once() )->method( 'setTex' )->with( self::TEXVCCHECK_OUTPUT );
@ -145,13 +145,13 @@ class MathRendererTest extends MediaWikiTestCase {
public function testCheckingNewKnown() { public function testCheckingNewKnown() {
$this->setMwGlobals( "wgMathDisableTexFilter", 'new' ); $this->setMwGlobals( "wgMathDisableTexFilter", 'new' );
$renderer = $renderer =
$this->getMockBuilder( 'MathRenderer' )->setMethods( array( $this->getMockBuilder( 'MathRenderer' )->setMethods( [
'render', 'render',
'getMathTableName', 'getMathTableName',
'getHtmlOutput', 'getHtmlOutput',
'readFromDatabase', 'readFromDatabase',
'setTex' 'setTex'
) )->setConstructorArgs( array( self::TEXVCCHECK_INPUT ) )->getMock(); ] )->setConstructorArgs( [ self::TEXVCCHECK_INPUT ] )->getMock();
$renderer->expects( $this->exactly( 2 ) )->method( 'readFromDatabase' ) $renderer->expects( $this->exactly( 2 ) )->method( 'readFromDatabase' )
->will( $this->returnValue( true ) ); ->will( $this->returnValue( true ) );
$renderer->expects( $this->never() )->method( 'setTex' ); $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. * i.e. if the span element is generated right.
*/ */
public function testBasics() { public function testBasics() {
$real = MathRenderer::renderMath( "a+b", array(), 'source' ); $real = MathRenderer::renderMath( "a+b", [], 'source' );
$this->assertEquals( $this->assertEquals(
'<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a+b $</span>', '<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a+b $</span>',
$real, $real,
@ -28,7 +28,7 @@ class MathSourceTest extends MediaWikiTestCase {
* Checks if newlines are converted to spaces correctly. * Checks if newlines are converted to spaces correctly.
*/ */
public function testNewLines() { public function testNewLines() {
$real = MathRenderer::renderMath( "a\n b", array(), 'source' ); $real = MathRenderer::renderMath( "a\n b", [], 'source' );
$this->assertSame( $this->assertSame(
'<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a b $</span>', '<span class="mwe-math-fallback-source-inline tex" dir="ltr">$ a b $</span>',
$real, $real,

View File

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