| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math\InputCheck; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use MediaWiki\Extension\Math\MathRestbaseInterface; |
| 7 |
use MediaWiki\Message\Message; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
class RestbaseChecker extends BaseChecker { |
| 22 |
|
| 23 |
private $restbaseInterface; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public function __construct( $tex = '', $type = 'tex', &$ref = null ) { |
| 31 |
parent::__construct( $tex ); |
| 32 |
if ( $ref ) { |
| 33 |
$this->restbaseInterface = $ref; |
| 34 |
} else { |
| 35 |
$this->restbaseInterface = new MathRestbaseInterface( $tex, $type ); |
| 36 |
$ref = $this->restbaseInterface; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function isValid() { |
| 44 |
return $this->restbaseInterface->getSuccess(); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public function getValidTex(): ?string { |
| 54 |
return $this->restbaseInterface->getCheckedTex(); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function getError(): ?Message { |
| 62 |
$err = $this->restbaseInterface->getError(); |
| 63 |
if ( $err === null ) { |
| 64 |
return null; |
| 65 |
} |
| 66 |
try { |
| 67 |
$host = $this->restbaseInterface->getUrl( '' ); |
| 68 |
} catch ( Exception $ignore ) { |
| 69 |
$host = 'invalid'; |
| 70 |
} |
| 71 |
return $this->errorObjectToMessage( $err, $host ); |
| 72 |
} |
| 73 |
|
| 74 |
public function getRbi(): MathRestbaseInterface { |
| 75 |
return $this->restbaseInterface; |
| 76 |
} |
| 77 |
|
| 78 |
} |