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