Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PopulateInterwikiTask | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDependencies | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Installer\Task; |
4 | |
5 | use MediaWiki\Status\Status; |
6 | use Wikimedia\AtEase\AtEase; |
7 | |
8 | /** |
9 | * Populate the interwiki table from maintenance/interwiki.list |
10 | * |
11 | * @internal For use by the installer |
12 | */ |
13 | class PopulateInterwikiTask extends Task { |
14 | public function getName() { |
15 | return 'interwiki'; |
16 | } |
17 | |
18 | public function getDependencies() { |
19 | return 'tables'; |
20 | } |
21 | |
22 | public function execute(): Status { |
23 | $status = $this->getConnection( ITaskContext::CONN_CREATE_TABLES ); |
24 | if ( !$status->isOK() ) { |
25 | return $status; |
26 | } |
27 | $conn = $status->getDB(); |
28 | |
29 | $row = $conn->newSelectQueryBuilder() |
30 | ->select( '1' ) |
31 | ->from( 'interwiki' ) |
32 | ->caller( __METHOD__ )->fetchRow(); |
33 | if ( $row ) { |
34 | $status->warning( 'config-install-interwiki-exists' ); |
35 | return $status; |
36 | } |
37 | |
38 | AtEase::suppressWarnings(); |
39 | $rows = file( MW_INSTALL_PATH . '/maintenance/interwiki.list', |
40 | FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); |
41 | AtEase::restoreWarnings(); |
42 | if ( !$rows ) { |
43 | return Status::newFatal( 'config-install-interwiki-list' ); |
44 | } |
45 | $insert = $conn->newInsertQueryBuilder() |
46 | ->insertInto( 'interwiki' ); |
47 | foreach ( $rows as $row ) { |
48 | $row = preg_replace( '/^\s*([^#]*?)\s*(#.*)?$/', '\\1', $row ); // strip comments - whee |
49 | if ( $row == "" ) { |
50 | continue; |
51 | } |
52 | $row .= "|"; |
53 | $insert->row( |
54 | array_combine( |
55 | [ 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ], |
56 | explode( '|', $row ) |
57 | ) |
58 | ); |
59 | } |
60 | $insert->caller( __METHOD__ )->execute(); |
61 | |
62 | return Status::newGood(); |
63 | } |
64 | } |