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