MediaWiki master
PopulateInterwikiTask.php
Go to the documentation of this file.
1<?php
2
4
6use Wikimedia\AtEase\AtEase;
7
15 public function getName() {
16 return 'interwiki';
17 }
18
20 public function getDependencies() {
21 return 'tables';
22 }
23
24 public function execute(): Status {
25 $status = $this->getConnection( ITaskContext::CONN_CREATE_TABLES );
26 if ( !$status->isOK() ) {
27 return $status;
28 }
29 $conn = $status->getDB();
30
31 $row = $conn->newSelectQueryBuilder()
32 ->select( '1' )
33 ->from( 'interwiki' )
34 ->caller( __METHOD__ )->fetchRow();
35 if ( $row ) {
36 $status->warning( 'config-install-interwiki-exists' );
37 return $status;
38 }
39
40 AtEase::suppressWarnings();
41 $rows = file( MW_INSTALL_PATH . '/maintenance/interwiki.list',
42 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
43 AtEase::restoreWarnings();
44 if ( !$rows ) {
45 return Status::newFatal( 'config-install-interwiki-list' );
46 }
47 $insert = $conn->newInsertQueryBuilder()
48 ->insertInto( 'interwiki' );
49 foreach ( $rows as $row ) {
50 $row = preg_replace( '/^\s*([^#]*?)\s*(#.*)?$/', '\\1', $row ); // strip comments - whee
51 if ( $row == "" ) {
52 continue;
53 }
54 $row .= "|";
55 $insert->row(
56 array_combine(
57 [ 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ],
58 explode( '|', $row )
59 )
60 );
61 }
62 $insert->caller( __METHOD__ )->execute();
63
64 return Status::newGood();
65 }
66}
Populate the interwiki table from maintenance/interwiki.list.
getName()
Get the symbolic name of the task.string
getDependencies()
Get a list of names or aliases of tasks that must be done prior to this task.to override string|strin...
Base class for installer tasks.
Definition Task.php:24
getConnection(string $type)
Connect to the database for a specified purpose.
Definition Task.php:200
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
warning( $message,... $parameters)
Add a new warning.
Dependency bundle and execution context for installer tasks.