Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
WmcRefIdentifier | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
56 |
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 WmcRefIdentifier extends Maintenance { |
24 | |
25 | public function __construct() { |
26 | parent::__construct(); |
27 | $this->requireExtension( 'MathSearch' ); |
28 | } |
29 | |
30 | public function execute() { |
31 | $dbr = $this->getServiceContainer() |
32 | ->getConnectionProvider() |
33 | ->getReplicaDatabase(); |
34 | $res = $dbr->query( 'SELECT qID, oldId, fid, math_input FROM math_wmc_ref r' . |
35 | ' JOIN mathlog l WHERE r.math_inputhash = l.math_inputhash;' ); |
36 | |
37 | $output = []; |
38 | foreach ( $res as $row ) { |
39 | $md = new MathoidDriver( $row->math_input ); |
40 | $md->texvcInfo(); |
41 | $identifiers = array_unique( $md->getIdentifiers() ); |
42 | $fId = "math.{$row->oldId}.{$row->fid}"; |
43 | $mo = MathObject::newFromRevisionText( $row->oldId, $fId ); |
44 | $relations = []; |
45 | $rels = $mo->getRelations(); |
46 | $wd = new WikidataDriver(); |
47 | foreach ( $identifiers as $i ) { |
48 | $relations[$i] = []; |
49 | if ( isset( $rels[$i] ) ) { |
50 | foreach ( $rels[$i] as $rel ) { |
51 | if ( preg_match( '/\[\[(.*)\]\]/', $rel->definition, $m ) ) { |
52 | if ( $wd->search( $m[1] ) ) { |
53 | $res = $wd->getResults(); |
54 | $relations[$i][] = $res; |
55 | } |
56 | } else { |
57 | $relations[$i][] = $rel->definition; |
58 | } |
59 | } |
60 | } |
61 | } |
62 | $output[] = (object)[ 'definitions' => $relations, 'formula' => $row ]; |
63 | } |
64 | $this->output( json_encode( $output ) ); |
65 | } |
66 | } |
67 | |
68 | $maintClass = WmcRefIdentifier::class; |
69 | /** @noinspection PhpIncludeInspection */ |
70 | require_once RUN_MAINTENANCE_IF_MAIN; |