30require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
44This script will populate the interwiki table, pulling in interwiki links that are used on Wikipedia
47When the script has finished, it will make a note of
this in the database, and will not
run again
48without the --force option.
50--source parameter is the url
for the source wiki api, such as
"https://en.wikipedia.org/w/api.php"
51(the
default) from which the script fetches the interwiki data and uses here to populate
52the interwiki database table.
56 $this->
addOption(
'source',
'Source wiki for interwiki table, such as '
57 .
'https://en.wikipedia.org/w/api.php (the default)',
false,
true );
58 $this->
addOption(
'force',
'Run regardless of whether the database says it has '
59 .
'been run already.' );
64 $this->source = $this->
getOption(
'source',
'https://en.wikipedia.org/w/api.php' );
68 if ( $data ===
false ) {
69 $this->
error(
"Error during fetching data." );
82 'siprop' =>
'interwikimap',
83 'sifilteriw' =>
'local',
87 if ( $this->source ) {
88 $url = rtrim( $this->source,
'?' ) .
'?' .
$url;
92 $data = json_decode( $json,
true );
94 if ( is_array( $data ) ) {
95 return $data[
'query'][
'interwikimap'];
111 $row = $dbw->newSelectQueryBuilder()
113 ->from(
'updatelog' )
114 ->where( [
'ul_key' =>
'populate interwiki' ] )
115 ->caller( __METHOD__ )->fetchRow();
118 $this->
output(
"Interwiki table already populated. Use php " .
119 "maintenance/populateInterwiki.php\n--force from the command line " .
126 foreach ( $data as $d ) {
127 $prefix = $d[
'prefix'];
129 $row = $dbw->newSelectQueryBuilder()
131 ->from(
'interwiki' )
132 ->where( [
'iw_prefix' => $prefix ] )
133 ->caller( __METHOD__ )->fetchRow();
136 $dbw->newInsertQueryBuilder()
137 ->insertInto(
'interwiki' )
140 'iw_prefix' => $prefix,
141 'iw_url' => $d[
'url'],
146 ->caller( __METHOD__ )->execute();
149 $lookup->invalidateCache( $prefix );
152 $this->
output(
"Interwiki links are populated.\n" );
161require_once RUN_MAINTENANCE_IF_MAIN;
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
execute()
Do the actual work.
__construct()
Default constructor.
doPopulate(array $data, $force)