27 require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
40 This script will populate the interwiki table, pulling in interwiki links that are used on Wikipedia
43 When the script has finished, it will make a note of
this in the database, and will not run again
44 without the --force option.
46 --source parameter is the url
for the source wiki api, such as
"https://en.wikipedia.org/w/api.php"
47 (the
default) from which the script fetches the interwiki data and uses here to populate
48 the interwiki database table.
52 $this->
addOption(
'source',
'Source wiki for interwiki table, such as '
53 .
'https://en.wikipedia.org/w/api.php (the default)',
false,
true );
54 $this->
addOption(
'force',
'Run regardless of whether the database says it has '
55 .
'been run already.' );
60 $this->source = $this->
getOption(
'source',
'https://en.wikipedia.org/w/api.php' );
64 if ( $data ===
false ) {
65 $this->
error(
"Error during fetching data." );
78 'siprop' =>
'interwikimap',
79 'sifilteriw' =>
'local',
83 if ( $this->source ) {
84 $url = rtrim( $this->source,
'?' ) .
'?' . $url;
88 $data = json_decode( $json,
true );
90 if ( is_array( $data ) ) {
91 return $data[
'query'][
'interwikimap'];
107 $row = $dbw->newSelectQueryBuilder()
109 ->from(
'updatelog' )
110 ->where( [
'ul_key' =>
'populate interwiki' ] )
111 ->caller( __METHOD__ )->fetchRow();
114 $this->
output(
"Interwiki table already populated. Use php " .
115 "maintenance/populateInterwiki.php\n--force from the command line " .
122 foreach ( $data as $d ) {
123 $prefix = $d[
'prefix'];
125 $row = $dbw->newSelectQueryBuilder()
127 ->from(
'interwiki' )
128 ->where( [
'iw_prefix' => $prefix ] )
129 ->caller( __METHOD__ )->fetchRow();
135 'iw_prefix' => $prefix,
136 'iw_url' => $d[
'url'],
146 $lookup->invalidateCache( $prefix );
149 $this->
output(
"Interwiki links are populated.\n" );
157 require_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...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
execute()
Do the actual work.
__construct()
Default constructor.
doPopulate(array $data, $force)