Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
CreateBaseXMathTable | |
0.00% |
0 / 35 |
|
0.00% |
0 / 7 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
generateIndexString | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
getHead | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFooter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
wFile | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
__destruct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Generates harvest files for the MathWebSearch Deamon. |
4 | * Example: php CreateMathIndex.php ~/mws_harvest_files |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; if not, write to the Free Software Foundation, Inc., |
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | * http://www.gnu.org/copyleft/gpl.html |
20 | * |
21 | * @ingroup Maintenance |
22 | */ |
23 | |
24 | require_once __DIR__ . '/IndexBase.php'; |
25 | |
26 | /** |
27 | * @author Moritz Schubotz |
28 | */ |
29 | class CreateBaseXMathTable extends IndexBase { |
30 | |
31 | private static $mwsns = 'mws:'; |
32 | private static $XMLHead; |
33 | private static $XMLFooter; |
34 | /** @var \BaseXSession */ |
35 | private $session; |
36 | |
37 | public function __construct() { |
38 | parent::__construct(); |
39 | $this->addDescription( 'Generates harvest files for the MathWebSearch Daemon.' ); |
40 | $this->addOption( 'mwsns', 'The namespace or mws normally "mws:"', false ); |
41 | $this->addOption( 'truncate', 'If set the database will be recreated.' ); |
42 | } |
43 | |
44 | /** |
45 | * @param stdClass $row |
46 | * |
47 | * @return string |
48 | */ |
49 | protected function generateIndexString( $row ) { |
50 | $out = ""; |
51 | $xml = simplexml_load_string( $row->math_mathml ); |
52 | if ( !$xml ) { |
53 | echo "ERROR while converting:\n " . var_export( $row->math_mathml, true ) . "\n"; |
54 | foreach ( libxml_get_errors() as $error ) { |
55 | echo "\t", $error->message; |
56 | } |
57 | libxml_clear_errors(); |
58 | return ""; |
59 | } |
60 | $out .= "\n<" . self::$mwsns . "expr url=\"" . |
61 | MathSearchHooks::generateMathAnchorString( $row->mathindex_revision_id, |
62 | $row->mathindex_anchor, '' ) . "\">\n\t"; |
63 | $out .= $row->math_mathml;// $xml->math->children()->asXML(); |
64 | $out .= "\n</" . self::$mwsns . "expr>\n"; |
65 | // TODO: This does not work yet. |
66 | // Find out how to insert new data without to write it into a temporary file |
67 | // $this->session->execute("insert node $out "); |
68 | return $out; |
69 | } |
70 | |
71 | protected function getHead() { |
72 | return self::$XMLHead; |
73 | } |
74 | |
75 | protected function getFooter() { |
76 | return self::$XMLFooter; |
77 | } |
78 | |
79 | /** |
80 | * @param string $fn |
81 | * @param int $min |
82 | * @param int $inc |
83 | * |
84 | * @return bool |
85 | */ |
86 | protected function wFile( $fn, $min, $inc ) { |
87 | $retval = parent::wFile( $fn, $min, $inc ); |
88 | $this->session->execute( "add $fn" ); |
89 | return $retval; |
90 | } |
91 | |
92 | public function execute() { |
93 | global $wgMathSearchBaseXDatabaseName; |
94 | self::$mwsns = $this->getOption( 'mwsns', '' ); |
95 | self::$XMLHead = |
96 | "<?xml version=\"1.0\"?>\n<" . self::$mwsns . |
97 | "harvest xmlns:mws=\"http://search.mathweb.org/ns\" xmlns:m=\"http://www.w3.org/1998/Math/MathML\">"; |
98 | self::$XMLFooter = "</" . self::$mwsns . "harvest>"; |
99 | $this->session = new BaseXSession(); |
100 | if ( $this->getOption( 'truncate', false ) ) { |
101 | $this->session->execute( "open " . $wgMathSearchBaseXDatabaseName ); |
102 | } else { |
103 | $this->session->execute( "create db " . $wgMathSearchBaseXDatabaseName ); |
104 | } |
105 | parent::execute(); |
106 | } |
107 | |
108 | public function __destruct() { |
109 | $this->session->close(); |
110 | } |
111 | } |
112 | |
113 | $maintClass = CreateBaseXMathTable::class; |
114 | /** @noinspection PhpIncludeInspection */ |
115 | require_once RUN_MAINTENANCE_IF_MAIN; |