16require_once __DIR__ .
'/Maintenance.php';
27 parent::__construct();
30This script will populate the interwiki table, pulling in interwiki links that are used on Wikipedia
33When the script has finished, it will make a note of
this in the database, and will not run again
34without the --force option.
36--source parameter is the url
for the source wiki api, such as
"https://en.wikipedia.org/w/api.php"
37(the
default) from which the script fetches the interwiki data and uses here to populate
38the interwiki database table.
42 $this->
addOption(
'source',
'Source wiki for interwiki table, such as '
43 .
'https://en.wikipedia.org/w/api.php (the default)',
false,
true );
44 $this->
addOption(
'force',
'Run regardless of whether the database says it has '
45 .
'been run already.' );
50 $this->source = $this->
getOption(
'source',
'https://en.wikipedia.org/w/api.php' );
54 if ( $data ===
false ) {
55 $this->
error(
"Error during fetching data." );
68 'siprop' =>
'interwikimap',
69 'sifilteriw' =>
'local',
73 if ( $this->source ) {
74 $url = rtrim( $this->source,
'?' ) .
'?' .
$url;
78 $data = json_decode( $json,
true );
80 if ( is_array( $data ) ) {
81 return $data[
'query'][
'interwikimap'];
97 $row = $dbw->newSelectQueryBuilder()
100 ->where( [
'ul_key' =>
'populate interwiki' ] )
101 ->caller( __METHOD__ )->fetchRow();
104 $this->
output(
"Interwiki table already populated. Use php " .
105 "maintenance/populateInterwiki.php\n--force from the command line " .
112 foreach ( $data as $d ) {
113 $prefix = $d[
'prefix'];
115 $row = $dbw->newSelectQueryBuilder()
117 ->from(
'interwiki' )
118 ->where( [
'iw_prefix' => $prefix ] )
119 ->caller( __METHOD__ )->fetchRow();
122 $dbw->newInsertQueryBuilder()
123 ->insertInto(
'interwiki' )
126 'iw_prefix' => $prefix,
127 'iw_url' => $d[
'url'],
132 ->caller( __METHOD__ )->execute();
135 $lookup->invalidateCache( $prefix );
138 $this->
output(
"Interwiki links are populated.\n" );
147require_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.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
execute()
Do the actual work.
__construct()
Default constructor.
doPopulate(array $data, $force)