Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
MathSearchUtils | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
addExtensionTable | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
createEvaluationTables | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getTableHead | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
dbRowToWikiTable | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | use MediaWiki\MediaWikiServices; |
4 | use Wikimedia\Rdbms\IResultWrapper; |
5 | |
6 | class MathSearchUtils { |
7 | |
8 | private static function addExtensionTable( $name, $folder = '' ) { |
9 | $dbw = MediaWikiServices::getInstance() |
10 | ->getConnectionProvider() |
11 | ->getPrimaryDatabase(); |
12 | $sql = file_get_contents( __DIR__ . "/../db/wmc/{$folder}/{$name}.sql" ); |
13 | $dbw->query( $sql ); |
14 | } |
15 | |
16 | public static function createEvaluationTables() { |
17 | self::addExtensionTable( 'math_wmc_formula_counts', 'topics' ); |
18 | self::addExtensionTable( 'math_wmc_topics_easy', 'topics' ); |
19 | self::addExtensionTable( 'math_wmc_topics_frequent', 'topics' ); |
20 | self::addExtensionTable( 'math_wmc_topics_variable', 'topics' ); |
21 | self::addExtensionTable( 'math_wmc_topics_hard', 'topics' ); |
22 | self::addExtensionTable( 'math_wmc_results_pages' ); |
23 | self::addExtensionTable( 'math_wmc_results_top' ); |
24 | self::addExtensionTable( 'math_wmc_queries_top_dist' ); |
25 | self::addExtensionTable( 'math_wmc_page_ranks' ); |
26 | self::addExtensionTable( 'math_wmc_query_summary' ); |
27 | } |
28 | |
29 | /** |
30 | * @param array $cols |
31 | * |
32 | * @return string |
33 | */ |
34 | private static function getTableHead( array $cols ) { |
35 | $out = "{| class=\"wikitable sortable\"\n|-\n! "; |
36 | $out .= implode( ' !! ', $cols ); |
37 | return $out; |
38 | } |
39 | |
40 | static function dbRowToWikiTable( IResultWrapper $resultWrapper, array $heads ) { |
41 | $out = self::getTableHead( $heads ); |
42 | foreach ( $resultWrapper as $row ) { |
43 | $out .= "\n|-"; |
44 | foreach ( $row as $col ) { |
45 | $out .= "\n| " . $col; |
46 | } |
47 | } |
48 | return $out . "\n|}\n"; |
49 | } |
50 | } |