Fix and add missing documentation and fix minor code smell issues

Change-Id: Ifa2f8a47fbd0bdd20334f59dd06a21339b9a4292
This commit is contained in:
Thiemo Mättig 2017-07-10 11:40:12 +02:00
parent ed7fdd990c
commit bdeec56d1f
9 changed files with 29 additions and 19 deletions

View File

@ -9,7 +9,12 @@
use MediaWiki\Logger\LoggerFactory;
class MathHooks {
/**
* @var array[]
*/
private static $tags = [];
const MATHCACHEKEY = 'math=';
public static function mathConstantToString( $value, array $defs, $prefix, $default ) {
@ -388,10 +393,9 @@ class MathHooks {
self::$tags = [];
return true;
}
/**
*
* @global type $wgOut
* @param type $toolbar
* @param string $toolbar HTML
*/
static function onEditPageBeforeEditToolbar( &$toolbar ) {
global $wgOut;

View File

@ -63,7 +63,7 @@ class MathFormatter implements ValueFormatter {
default:
$renderer = new MathMathML( $tex );
if ( $renderer->checkTex() && $renderer->render() ) {
if ( $renderer->checkTeX() && $renderer->render() ) {
$html = $renderer->getHtmlOutput();
} else {
$html = $renderer->getLastError();

View File

@ -20,7 +20,12 @@ class MathMathML extends MathRenderer {
/** @var boolean if false MathML output is not validated */
private $XMLValidation = true;
/**
* @var string|bool
*/
private $svgPath = false;
private $mathoidStyle;
public function __construct( $tex = '', $params = [] ) {
@ -176,9 +181,8 @@ class MathMathML extends MathRenderer {
$this->getPostData();
}
$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 );
/** @var Status $req Status the request status */
$status = $req->execute();
if ( $status->isGood() ) {
$res = $req->getContent();
@ -334,7 +338,7 @@ class MathMathML extends MathRenderer {
/**
* @param boolean $noRender
* @return type
* @return Title|string
*/
private function getFallbackImageUrl( $noRender = false ) {
if ( $this->svgPath ) {

View File

@ -487,14 +487,14 @@ abstract class MathRenderer {
/**
* Get the attributes of the math tag
*
* @return []
* @return array
*/
public function getParams() {
return $this->params;
}
/**
* @param [] $params
* @param array $params
*/
public function setParams( $params ) {
// $changed is not set to true here, because the attributes do not affect

View File

@ -22,7 +22,6 @@ class MathRestbaseInterface {
private $purge = false;
/**
* MathRestbaseInterface constructor.
* @param string $tex
* @param string $type
*/
@ -34,8 +33,8 @@ class MathRestbaseInterface {
/**
* Bundles several requests for fetching MathML.
* Does not send requests, if the the input TeX is invalid.
* @param $rbis
* @param $serviceClient
* @param MathRestbaseInterface[] $rbis
* @param VirtualRESTServiceClient $serviceClient
*/
private static function batchGetMathML( $rbis, $serviceClient ) {
$requests = [];
@ -135,7 +134,7 @@ class MathRestbaseInterface {
}
/**
* @param array $rbis array of MathRestbaseInterface instances
* @param MathRestbaseInterface[] $rbis
*/
public static function batchEvaluate( $rbis ) {
if ( count( $rbis ) == 0 ) {
@ -162,6 +161,9 @@ class MathRestbaseInterface {
self::batchGetMathML( $rbis, $serviceClient );
}
/**
* @return VirtualRESTServiceClient
*/
private function getServiceClient() {
global $wgVirtualRestConfig, $wgMathConcurrentReqs;
$http = new MultiHttpClient( [ 'maxConnsPerHost' => $wgMathConcurrentReqs ] );
@ -263,6 +265,7 @@ class MathRestbaseInterface {
[ 'uniqueTeX' => $uniqueTeX ] );
return false;
}
try {
$url = $testInterface->getFullSvgUrl();
$req = MWHttpRequest::factory( $url );

View File

@ -57,7 +57,7 @@ class MathTexvc extends MathRenderer {
}
/**
* @param database_row $rpage
* @param stdClass $rpage
* @return bool
*/
protected function initializeFromDatabaseRow( $rpage ) {
@ -330,7 +330,7 @@ class MathTexvc extends MathRenderer {
if ( !$backend ) {
$backend = new FSFileBackend( [
'name' => 'math-backend',
'wikiId' => wfWikiId(),
'wikiId' => wfWikiID(),
'lockManager' => new NullLockManager( [] ),
'containerPaths' => [ 'math-render' => $wgMathDirectory ],
'fileMode' => 0777,

View File

@ -85,7 +85,7 @@ class MathCoverageTest extends MediaWikiTestCase {
/**
* 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
*/
public function provideCoverage() {

View File

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

View File

@ -69,7 +69,7 @@ class MathMathMLTest extends MediaWikiTestCase {
$requestReturn = $renderer->makeRequest( $url, 'a+b', $res, $error,
'MathMLHttpRequestTester' );
$this->assertEquals( true, $requestReturn, "successful call return" );
$this->isTrue( $res, "successfull call" );
$this->assertTrue( $res, 'successfull call' );
$this->assertEquals( $error, '', "successfull call errormessage" );
}
@ -139,7 +139,6 @@ class MathMathMLTest extends MediaWikiTestCase {
* Helper class for testing
* @author physikerwelt
* @see MWHttpRequestTester
*
*/
class MathMLHttpRequestTester {