Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 60 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
GenerateFeatureTable | |
0.00% |
0 / 57 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
populateSearchIndex | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
42 | |||
doUpdate | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
6 | |||
execute | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 |
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 GenerateFeatureTable extends Maintenance { |
26 | |
27 | private const RTI_CHUNK_SIZE = 100000; |
28 | |
29 | /** @var bool */ |
30 | private $purge = false; |
31 | /** @var \Wikimedia\Rdbms\IDatabase */ |
32 | private $dbw = null; |
33 | |
34 | /** |
35 | * @var \Wikimedia\Rdbms\IDatabase |
36 | */ |
37 | private $db; |
38 | |
39 | public function __construct() { |
40 | parent::__construct(); |
41 | $this->addDescription( 'Outputs page text to stdout' ); |
42 | $this->addOption( |
43 | 'purge', "If set all formulae are rendered again from strech. (Very time consuming!)", |
44 | false, false, "f" |
45 | ); |
46 | $this->addArg( 'min', "If set processing is started at the page with rank(pageID)>min", false ); |
47 | $this->addArg( 'max', "If set processing is stopped at the page with rank(pageID)<=max", false ); |
48 | $this->requireExtension( 'MathSearch' ); |
49 | } |
50 | |
51 | /** |
52 | * Populates the search index with content from all pages |
53 | * |
54 | * @param int $n |
55 | * @param int $cmax |
56 | */ |
57 | protected function populateSearchIndex( $n = 0, $cmax = -1 ) { |
58 | $s = $this->db->selectRow( 'page', 'MAX(page_id) AS count' ); |
59 | $count = $s->count; |
60 | if ( $cmax > 0 && $count > $cmax ) { |
61 | $count = $cmax; |
62 | } |
63 | # $this->output( "Rebuilding index fields for {$count} pages with option {$this->purge}...\n" ); |
64 | $fcount = 0; |
65 | |
66 | while ( $n < $count ) { |
67 | if ( $n ) { |
68 | $this->output( $n . " of $count \n" ); |
69 | } |
70 | $end = $n + self::RTI_CHUNK_SIZE - 1; |
71 | |
72 | $res = |
73 | $this->db->select( [ 'page', 'revision', 'text' ], [ 'page_id' ], [ |
74 | "page_id BETWEEN $n AND $end", |
75 | 'page_latest = rev_id', |
76 | 'rev_text_id = old_id' |
77 | ], __METHOD__ ); |
78 | $this->dbw->begin( __METHOD__ ); |
79 | // echo "before" +$this->dbw->selectField('mathindex', 'count(*)')."\n"; |
80 | foreach ( $res as $s ) { |
81 | $fcount += $this->doUpdate( $s->page_id ); |
82 | } |
83 | $this->dbw->commit( __METHOD__ ); |
84 | $n += self::RTI_CHUNK_SIZE; |
85 | } |
86 | // $this->output( "Updated {$fcount} formulae!\n" ); |
87 | } |
88 | |
89 | /** |
90 | * @param int $pid |
91 | * |
92 | * @return number |
93 | */ |
94 | private function doUpdate( $pid ) { |
95 | // TODO: fix link id problem |
96 | $res = |
97 | $this->db->select( [ 'mathrevisionstat', 'mathvarstat' ], [ |
98 | 'revstat_revid', |
99 | 'pagestat_featurename', |
100 | 'pagestat_featuretype', |
101 | 'revstat_featurecount', |
102 | 'varstat_id', |
103 | 'varstat_featurecount' |
104 | ], [ |
105 | 'revstat_revid' => $pid, |
106 | 'pagestat_featurename = varstat_featurename', |
107 | 'pagestat_featuretype=varstat_featuretype' |
108 | ], __METHOD__ ); |
109 | foreach ( $res as $row ) { |
110 | $this->output( $pid . ',' . $row->varstat_id . ',' . $row->pagestat_featurecount |
111 | /// $row->varstat_featurecount |
112 | . |
113 | "\n" );// .';'.$row->pagestat_featuretype.$row->pagestat_featurename."\n"); |
114 | } |
115 | return 0; |
116 | } |
117 | |
118 | public function execute() { |
119 | $this->dbw = MediaWikiServices::getInstance() |
120 | ->getConnectionProvider() |
121 | ->getPrimaryDatabase(); |
122 | $this->purge = $this->getOption( "purge", false ); |
123 | $this->db = MediaWikiServices::getInstance() |
124 | ->getConnectionProvider() |
125 | ->getPrimaryDatabase(); |
126 | $this->populateSearchIndex( $this->getArg( 0, 0 ), $this->getArg( 1, -1 ) ); |
127 | } |
128 | } |
129 | |
130 | $maintClass = GenerateFeatureTable::class; |
131 | /** @noinspection PhpIncludeInspection */ |
132 | require_once RUN_MAINTENANCE_IF_MAIN; |