Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
GenerateResultTableFromJson | |
0.00% |
0 / 37 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 | |||
printSource | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
printColHeader | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
printColFooter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @ingroup Maintenance |
19 | */ |
20 | |
21 | require_once __DIR__ . '/../../../maintenance/Maintenance.php'; |
22 | |
23 | class GenerateResultTableFromJson extends Maintenance { |
24 | |
25 | public function __construct() { |
26 | parent::__construct(); |
27 | $this->addDescription( 'Imports results from a json file.' . |
28 | " \n Generates wikitext template to stdout." ); |
29 | $this->addArg( 'file', 'The file to be read', true ); |
30 | $this->requireExtension( 'MathSearch' ); |
31 | } |
32 | |
33 | public function execute() { |
34 | $filename = $this->getArg( 0 ); |
35 | |
36 | if ( !is_file( $filename ) ) { |
37 | $this->output( "{$filename} is not a directory.\n" ); |
38 | exit( 1 ); |
39 | } |
40 | $this->output( '{| class="wikitable" |
41 | |+ Result table |
42 | |- |
43 | ! # !! Formula !! Title !! Evaluation data |
44 | ' ); |
45 | $json = json_decode( file_get_contents( $filename ) ); |
46 | foreach ( $json as $item ) { |
47 | $anchor = $item->eid; |
48 | if ( preg_match( '/-1$/', $anchor ) ) { |
49 | $anchor = substr( $anchor, 0, -2 ); |
50 | } |
51 | $this->output( "\n|- \n" ); |
52 | $this->output( "| $item->id \n| " ); |
53 | $this->printSource( $item->formulae[0]->formula, '', 'tex', false, false ); |
54 | $this->output( "\n| [[$item->title#$anchor| $item->title]] \n| " ); |
55 | $this->printSource( json_encode( $item, JSON_PRETTY_PRINT ), 'Full data', 'json' ); |
56 | } |
57 | $this->output( "\n|}" ); |
58 | } |
59 | |
60 | private function printSource( |
61 | $source, $description = "", $language = "text", $linestart = true, $collapsible = true |
62 | ) { |
63 | // TODO: deduplicate from SpecialLaTeXTranslator |
64 | $inline = ' inline '; |
65 | if ( $description ) { |
66 | $description .= ": "; |
67 | } |
68 | if ( $collapsible ) { |
69 | $this->printColHeader( $description ); |
70 | $description = ''; |
71 | $inline = ''; |
72 | } |
73 | $this->output( "$description<syntaxhighlight lang=\"$language\" $inline>" . $source . |
74 | '</syntaxhighlight>', $linestart ); |
75 | if ( $collapsible ) { |
76 | $this->printColFooter(); |
77 | } |
78 | } |
79 | |
80 | private function printColHeader( string $description ): void { |
81 | $this->output( '<div class="toccolours mw-collapsible mw-collapsed" style="text-align: left">' ); |
82 | $this->output( $description ); |
83 | $this->output( '<div class="mw-collapsible-content">' ); |
84 | } |
85 | |
86 | private function printColFooter(): void { |
87 | $this->output( '</div></div>' ); |
88 | } |
89 | |
90 | } |
91 | |
92 | $maintClass = GenerateResultTableFromJson::class; |
93 | /** @noinspection PhpIncludeInspection */ |
94 | require_once RUN_MAINTENANCE_IF_MAIN; |