Debian Codegraph @

extensions/Math/src/InputCheck/RestbaseChecker.php

raw symbols SCIP
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 * MediaWiki math extension
11 *
12 * @copyright 2002-2015 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz,
13 * and other MediaWiki contributors
14 *
15 * @note The restbase checker does not support purging the cache as it just represents
16 * the state of the restbase interface.
17 *
18 * @license GPL-2.0-or-later
19 * @author Moritz Schubotz
20 */
21 class RestbaseChecker extends BaseChecker {
22 /** @var MathRestbaseInterface */
23 private $restbaseInterface;
24
25 /**
26 * @param string $tex the TeX input string to be checked
27 * @param string $type
28 * @param MathRestbaseInterface|null &$ref
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 * @return bool
42 */
43 public function isValid() {
44 return $this->restbaseInterface->getSuccess();
45 }
46
47 /**
48 * Some TeX checking programs may return
49 * a modified tex string after having checked it.
50 * You can get the altered tex string with this method
51 * @return ?string A valid Tex string
52 */
53 public function getValidTex(): ?string {
54 return $this->restbaseInterface->getCheckedTex();
55 }
56
57 /**
58 * Returns the string of the last error.
59 * @return ?Message
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 }