Merge "Fix and add missing documentation and fix minor code smell issues"
This commit is contained in:
commit
82e7eb98f6
|
@ -9,7 +9,12 @@
|
||||||
use MediaWiki\Logger\LoggerFactory;
|
use MediaWiki\Logger\LoggerFactory;
|
||||||
|
|
||||||
class MathHooks {
|
class MathHooks {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array[]
|
||||||
|
*/
|
||||||
private static $tags = [];
|
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 ) {
|
||||||
|
@ -388,10 +393,9 @@ class MathHooks {
|
||||||
self::$tags = [];
|
self::$tags = [];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param string $toolbar HTML
|
||||||
* @global type $wgOut
|
|
||||||
* @param type $toolbar
|
|
||||||
*/
|
*/
|
||||||
static function onEditPageBeforeEditToolbar( &$toolbar ) {
|
static function onEditPageBeforeEditToolbar( &$toolbar ) {
|
||||||
global $wgOut;
|
global $wgOut;
|
||||||
|
|
|
@ -63,7 +63,7 @@ class MathFormatter implements ValueFormatter {
|
||||||
default:
|
default:
|
||||||
$renderer = new MathMathML( $tex );
|
$renderer = new MathMathML( $tex );
|
||||||
|
|
||||||
if ( $renderer->checkTex() && $renderer->render() ) {
|
if ( $renderer->checkTeX() && $renderer->render() ) {
|
||||||
$html = $renderer->getHtmlOutput();
|
$html = $renderer->getHtmlOutput();
|
||||||
} else {
|
} else {
|
||||||
$html = $renderer->getLastError();
|
$html = $renderer->getLastError();
|
||||||
|
|
|
@ -20,7 +20,12 @@ class MathMathML extends MathRenderer {
|
||||||
|
|
||||||
/** @var boolean if false MathML output is not validated */
|
/** @var boolean if false MathML output is not validated */
|
||||||
private $XMLValidation = true;
|
private $XMLValidation = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string|bool
|
||||||
|
*/
|
||||||
private $svgPath = false;
|
private $svgPath = false;
|
||||||
|
|
||||||
private $mathoidStyle;
|
private $mathoidStyle;
|
||||||
|
|
||||||
public function __construct( $tex = '', $params = [] ) {
|
public function __construct( $tex = '', $params = [] ) {
|
||||||
|
@ -176,9 +181,8 @@ class MathMathML extends MathRenderer {
|
||||||
$this->getPostData();
|
$this->getPostData();
|
||||||
}
|
}
|
||||||
$options = [ 'method' => 'POST', 'postData' => $post, 'timeout' => $wgMathLaTeXMLTimeout ];
|
$options = [ 'method' => 'POST', 'postData' => $post, 'timeout' => $wgMathLaTeXMLTimeout ];
|
||||||
/** @var $req (CurlHttpRequest|PhpHttpRequest) the request object */
|
/** @var CurlHttpRequest|PhpHttpRequest $req the request object */
|
||||||
$req = $httpRequestClass::factory( $host, $options );
|
$req = $httpRequestClass::factory( $host, $options );
|
||||||
/** @var Status $req Status the request status */
|
|
||||||
$status = $req->execute();
|
$status = $req->execute();
|
||||||
if ( $status->isGood() ) {
|
if ( $status->isGood() ) {
|
||||||
$res = $req->getContent();
|
$res = $req->getContent();
|
||||||
|
@ -334,7 +338,7 @@ class MathMathML extends MathRenderer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param boolean $noRender
|
* @param boolean $noRender
|
||||||
* @return type
|
* @return Title|string
|
||||||
*/
|
*/
|
||||||
private function getFallbackImageUrl( $noRender = false ) {
|
private function getFallbackImageUrl( $noRender = false ) {
|
||||||
if ( $this->svgPath ) {
|
if ( $this->svgPath ) {
|
||||||
|
|
|
@ -487,14 +487,14 @@ abstract class MathRenderer {
|
||||||
/**
|
/**
|
||||||
* Get the attributes of the math tag
|
* Get the attributes of the math tag
|
||||||
*
|
*
|
||||||
* @return []
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getParams() {
|
public function getParams() {
|
||||||
return $this->params;
|
return $this->params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param [] $params
|
* @param array $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
|
||||||
|
|
|
@ -22,7 +22,6 @@ class MathRestbaseInterface {
|
||||||
private $purge = false;
|
private $purge = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MathRestbaseInterface constructor.
|
|
||||||
* @param string $tex
|
* @param string $tex
|
||||||
* @param string $type
|
* @param string $type
|
||||||
*/
|
*/
|
||||||
|
@ -34,8 +33,8 @@ class MathRestbaseInterface {
|
||||||
/**
|
/**
|
||||||
* Bundles several requests for fetching MathML.
|
* Bundles several requests for fetching MathML.
|
||||||
* Does not send requests, if the the input TeX is invalid.
|
* Does not send requests, if the the input TeX is invalid.
|
||||||
* @param $rbis
|
* @param MathRestbaseInterface[] $rbis
|
||||||
* @param $serviceClient
|
* @param VirtualRESTServiceClient $serviceClient
|
||||||
*/
|
*/
|
||||||
private static function batchGetMathML( array $rbis, VirtualRESTServiceClient $serviceClient ) {
|
private static function batchGetMathML( array $rbis, VirtualRESTServiceClient $serviceClient ) {
|
||||||
$requests = [];
|
$requests = [];
|
||||||
|
@ -135,7 +134,7 @@ class MathRestbaseInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $rbis array of MathRestbaseInterface instances
|
* @param MathRestbaseInterface[] $rbis
|
||||||
*/
|
*/
|
||||||
public static function batchEvaluate( array $rbis ) {
|
public static function batchEvaluate( array $rbis ) {
|
||||||
if ( count( $rbis ) == 0 ) {
|
if ( count( $rbis ) == 0 ) {
|
||||||
|
@ -162,6 +161,9 @@ class MathRestbaseInterface {
|
||||||
self::batchGetMathML( $rbis, $serviceClient );
|
self::batchGetMathML( $rbis, $serviceClient );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return VirtualRESTServiceClient
|
||||||
|
*/
|
||||||
private function getServiceClient() {
|
private function getServiceClient() {
|
||||||
global $wgVirtualRestConfig, $wgMathConcurrentReqs;
|
global $wgVirtualRestConfig, $wgMathConcurrentReqs;
|
||||||
$http = new MultiHttpClient( [ 'maxConnsPerHost' => $wgMathConcurrentReqs ] );
|
$http = new MultiHttpClient( [ 'maxConnsPerHost' => $wgMathConcurrentReqs ] );
|
||||||
|
@ -263,6 +265,7 @@ class MathRestbaseInterface {
|
||||||
[ 'uniqueTeX' => $uniqueTeX ] );
|
[ 'uniqueTeX' => $uniqueTeX ] );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$url = $testInterface->getFullSvgUrl();
|
$url = $testInterface->getFullSvgUrl();
|
||||||
$req = MWHttpRequest::factory( $url );
|
$req = MWHttpRequest::factory( $url );
|
||||||
|
|
|
@ -57,7 +57,7 @@ class MathTexvc extends MathRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param database_row $rpage
|
* @param stdClass $rpage
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function initializeFromDatabaseRow( $rpage ) {
|
protected function initializeFromDatabaseRow( $rpage ) {
|
||||||
|
@ -331,7 +331,7 @@ class MathTexvc extends MathRenderer {
|
||||||
if ( !$backend ) {
|
if ( !$backend ) {
|
||||||
$backend = new FSFileBackend( [
|
$backend = new FSFileBackend( [
|
||||||
'name' => 'math-backend',
|
'name' => 'math-backend',
|
||||||
'wikiId' => wfWikiId(),
|
'wikiId' => wfWikiID(),
|
||||||
'lockManager' => new NullLockManager( [] ),
|
'lockManager' => new NullLockManager( [] ),
|
||||||
'containerPaths' => [ 'math-render' => $wgMathDirectory ],
|
'containerPaths' => [ 'math-render' => $wgMathDirectory ],
|
||||||
'fileMode' => 0777,
|
'fileMode' => 0777,
|
||||||
|
|
|
@ -85,7 +85,7 @@ class MathCoverageTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the test-data from the file ParserTest.json
|
* Gets the test-data from the file ParserTest.json
|
||||||
* @return [$input, $output] where $input is the test input string
|
* @return string[] [ $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() {
|
||||||
|
|
|
@ -17,7 +17,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", [ 'id' => RANDOM_ID ] );
|
$renderer = MathRenderer::getRenderer( "a+b", [ 'id' => RANDOM_ID ] );
|
||||||
$this->assertEquals( RANDOM_ID, $renderer->getId() );
|
$this->assertEquals( RANDOM_ID, $renderer->getID() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ class MathMathMLTest extends MediaWikiTestCase {
|
||||||
$requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error,
|
$requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error,
|
||||||
'MathMLHttpRequestTester' );
|
'MathMLHttpRequestTester' );
|
||||||
$this->assertEquals( true, $requestReturn, "successful call return" );
|
$this->assertEquals( true, $requestReturn, "successful call return" );
|
||||||
$this->isTrue( $res, "successfull call" );
|
$this->assertTrue( $res, 'successfull call' );
|
||||||
$this->assertEquals( $error, '', "successfull call errormessage" );
|
$this->assertEquals( $error, '', "successfull call errormessage" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,6 @@ class MathMathMLTest extends MediaWikiTestCase {
|
||||||
* Helper class for testing
|
* Helper class for testing
|
||||||
* @author physikerwelt
|
* @author physikerwelt
|
||||||
* @see MWHttpRequestTester
|
* @see MWHttpRequestTester
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class MathMLHttpRequestTester {
|
class MathMLHttpRequestTester {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue