Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 63 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
GetEquationsByQuery | |
0.00% |
0 / 63 |
|
0.00% |
0 / 3 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 61 |
|
0.00% |
0 / 1 |
110 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * MediaWiki MathSearch extension |
4 | * |
5 | * (c) 2012 Moritz Schubotz |
6 | * GPLv2 license; info in main package. |
7 | * |
8 | * @file |
9 | * @ingroup extensions |
10 | */ |
11 | |
12 | use MediaWiki\Extension\Math\MathRenderer; |
13 | use MediaWiki\MediaWikiServices; |
14 | use MediaWiki\SpecialPage\SpecialPage; |
15 | |
16 | class GetEquationsByQuery extends SpecialPage { |
17 | |
18 | function __construct() { |
19 | parent::__construct( 'GetEquationsByQuery' ); |
20 | } |
21 | |
22 | /** |
23 | * @param string|null $par |
24 | */ |
25 | function execute( $par ) { |
26 | if ( !$this->getConfig()->get( 'MathDebug' ) ) { |
27 | $this->getOutput()->addWikiTextAsInterface( |
28 | "==Debug mode needed== This function is only supported in math debug mode." |
29 | ); |
30 | return; |
31 | } |
32 | |
33 | $filterID = $this->getRequest()->getInt( 'filterID', 1000 ); |
34 | switch ( $filterID ) { |
35 | case 0: |
36 | $sqlFilter = [ 'valid_xml' => '0' ]; |
37 | break; |
38 | case 1: |
39 | $sqlFilter = [ 'math_status' => '3' ]; |
40 | break; |
41 | case 2: |
42 | $math5 = $this->getRequest()->getVal( 'first5', null ); |
43 | $sqlFilter = [ |
44 | 'valid_xml' => '0', |
45 | 'left(math_mathml,5)' => $math5 |
46 | ]; |
47 | break; |
48 | case 3: |
49 | $math5 = $this->getRequest()->getVal( 'first5', null ); |
50 | $sqlFilter = [ |
51 | 'valid_xml' => '0', |
52 | 'left(math_tex,5)' => $math5 |
53 | ]; |
54 | break; |
55 | case 1000: |
56 | default: |
57 | $sqlFilter = [ 'math_status' => '3', 'valid_xml' => '0' ]; |
58 | } |
59 | $this->getOutput()->addWikiTextAsInterface( |
60 | "Displaying first 10 equation for query: <pre>" . var_export( $sqlFilter, true ) . '</pre>' |
61 | ); |
62 | $dbr = MediaWikiServices::getInstance() |
63 | ->getConnectionProvider() |
64 | ->getReplicaDatabase(); |
65 | $res = $dbr->select( |
66 | [ 'mathlog' ], |
67 | // TODO insert the missing fields to the mathlog table |
68 | [ |
69 | 'math_mathml', 'math_inputhash', 'math_log', 'math_tex', 'valid_xml', 'math_status', |
70 | 'math_timestamp', |
71 | ], |
72 | $sqlFilter, |
73 | __METHOD__, |
74 | [ |
75 | 'LIMIT' => $this->getRequest()->getInt( 'limit', 10 ), |
76 | 'OFFSET' => $this->getRequest()->getInt( 'offset', 0 ), |
77 | ] |
78 | ); |
79 | foreach ( $res as $row ) { |
80 | $this->getOutput()->addWikiTextAsInterface( 'Renderd at <b>' . $row->math_timestamp . '</b> ', false ); |
81 | $this->getOutput()->addHTML( '<a href="/index.php/Special:FormulaInfo?tex=' . |
82 | urlencode( $row->math_tex ) . '">more info</a>' ); |
83 | $this->getOutput()->addWikiTextAsInterface( ':TeX-Code:<pre>' . $row->math_tex . '</pre> <br />' ); |
84 | $showmml = $this->getRequest()->getVal( 'showmml', false ); |
85 | if ( $showmml ) { |
86 | $tstart = microtime( true ); |
87 | $renderer = MathRenderer::getRenderer( $row->math_tex, [], 'latexml' ); |
88 | $result = $renderer->render( true ); |
89 | $tend = microtime( true ); |
90 | $this->getOutput()->addWikiTextAsInterface( ":rendering in " . ( $tend - $tstart ) . "s.", false ); |
91 | $renderer->writeCache(); |
92 | $this->getOutput()->addHTML( "Output:" . $result . "<br/>" ); |
93 | } |
94 | |
95 | } |
96 | } |
97 | |
98 | protected function getGroupName() { |
99 | return 'mathsearch'; |
100 | } |
101 | } |