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 | /** @var string */ |
32 | private static $mwsns = 'mws:'; |
33 | /** @var string */ |
34 | private static $XMLHead; |
35 | /** @var string */ |
36 | private static $XMLFooter; |
37 | /** @var \BaseXSession */ |
38 | private $session; |
39 | |
40 | public function __construct() { |
41 | parent::__construct(); |
42 | $this->addDescription( 'Generates harvest files for the MathWebSearch Daemon.' ); |
43 | $this->addOption( 'mwsns', 'The namespace or mws normally "mws:"', false ); |
44 | $this->addOption( 'truncate', 'If set the database will be recreated.' ); |
45 | } |
46 | |
47 | /** |
48 | * @param stdClass $row |
49 | * |
50 | * @return string |
51 | */ |
52 | protected function generateIndexString( $row ) { |
53 | $out = ""; |
54 | $xml = simplexml_load_string( $row->math_mathml ); |
55 | if ( !$xml ) { |
56 | echo "ERROR while converting:\n " . var_export( $row->math_mathml, true ) . "\n"; |
57 | foreach ( libxml_get_errors() as $error ) { |
58 | echo "\t", $error->message; |
59 | } |
60 | libxml_clear_errors(); |
61 | return ""; |
62 | } |
63 | $out .= "\n<" . self::$mwsns . "expr url=\"" . |
64 | MathSearchHooks::generateMathAnchorString( $row->mathindex_revision_id, |
65 | $row->mathindex_anchor, '' ) . "\">\n\t"; |
66 | $out .= $row->math_mathml;// $xml->math->children()->asXML(); |
67 | $out .= "\n</" . self::$mwsns . "expr>\n"; |
68 | // TODO: This does not work yet. |
69 | // Find out how to insert new data without to write it into a temporary file |
70 | // $this->session->execute("insert node $out "); |
71 | return $out; |
72 | } |
73 | |
74 | protected function getHead() { |
75 | return self::$XMLHead; |
76 | } |
77 | |
78 | protected function getFooter() { |
79 | return self::$XMLFooter; |
80 | } |
81 | |
82 | /** |
83 | * @param string $fn |
84 | * @param int $min |
85 | * @param int $inc |
86 | * |
87 | * @return bool |
88 | */ |
89 | protected function wFile( $fn, $min, $inc ) { |
90 | $retval = parent::wFile( $fn, $min, $inc ); |
91 | $this->session->execute( "add $fn" ); |
92 | return $retval; |
93 | } |
94 | |
95 | public function execute() { |
96 | global $wgMathSearchBaseXDatabaseName; |
97 | self::$mwsns = $this->getOption( 'mwsns', '' ); |
98 | self::$XMLHead = |
99 | "<?xml version=\"1.0\"?>\n<" . self::$mwsns . |
100 | "harvest xmlns:mws=\"http://search.mathweb.org/ns\" xmlns:m=\"http://www.w3.org/1998/Math/MathML\">"; |
101 | self::$XMLFooter = "</" . self::$mwsns . "harvest>"; |
102 | $this->session = new BaseXSession(); |
103 | if ( $this->getOption( 'truncate', false ) ) { |
104 | $this->session->execute( "open " . $wgMathSearchBaseXDatabaseName ); |
105 | } else { |
106 | $this->session->execute( "create db " . $wgMathSearchBaseXDatabaseName ); |
107 | } |
108 | parent::execute(); |
109 | } |
110 | |
111 | public function __destruct() { |
112 | $this->session->close(); |
113 | } |
114 | } |
115 | |
116 | $maintClass = CreateBaseXMathTable::class; |
117 | /** @noinspection PhpIncludeInspection */ |
118 | require_once RUN_MAINTENANCE_IF_MAIN; |