39 parent::__construct();
41 $this->addDescription( <<<TEXT
42This script will populate the interwiki table, pulling in interwiki links that are used on Wikipedia
45When the script has finished, it will make a note of
this in the database, and will not
run again
46without the --force option.
48--source parameter is the url
for the source wiki api, such as
"https://en.wikipedia.org/w/api.php"
49(the
default) from which the script fetches the interwiki data and uses here to populate
50the interwiki database table.
54 $this->addOption(
'source',
'Source wiki for interwiki table, such as '
55 .
'https://en.wikipedia.org/w/api.php (the default)',
false,
true );
56 $this->addOption(
'force',
'Run regardless of whether the database says it has '
57 .
'been run already.' );
106 $dbw = $this->getPrimaryDB();
109 $row = $dbw->newSelectQueryBuilder()
111 ->from(
'updatelog' )
112 ->where( [
'ul_key' =>
'populate interwiki' ] )
113 ->caller( __METHOD__ )->fetchRow();
116 $this->output(
"Interwiki table already populated. Use php " .
117 "maintenance/populateInterwiki.php\n--force from the command line " .
123 $lookup = $this->getServiceContainer()->getInterwikiLookup();
124 foreach ( $data as $d ) {
125 $prefix = $d[
'prefix'];
127 $row = $dbw->newSelectQueryBuilder()
129 ->from(
'interwiki' )
130 ->where( [
'iw_prefix' => $prefix ] )
131 ->caller( __METHOD__ )->fetchRow();
134 $dbw->newInsertQueryBuilder()
135 ->insertInto(
'interwiki' )
138 'iw_prefix' => $prefix,
139 'iw_url' => $d[
'url'],
144 ->caller( __METHOD__ )->execute();
147 $lookup->invalidateCache( $prefix );
150 $this->output(
"Interwiki links are populated.\n" );