29 require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
42 This script will populate the interwiki table, pulling in interwiki links that are used on Wikipedia
45 When the script has finished, it will make a note of
this in the database, and will not run again
46 without 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
50 the 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.' );
62 $this->source = $this->
getOption(
'source',
'https://en.wikipedia.org/w/api.php' );
66 if ( $data ===
false ) {
67 $this->
error(
"Error during fetching data." );
80 'siprop' =>
'interwikimap',
81 'sifilteriw' =>
'local',
85 if ( !empty( $this->source ) ) {
86 $url = rtrim( $this->source,
'?' ) .
'?' . $url;
89 $json = MediaWikiServices::getInstance()->getHttpRequestFactory()->get( $url, [], __METHOD__ );
90 $data = json_decode( $json,
true );
92 if ( is_array( $data ) ) {
93 return $data[
'query'][
'interwikimap'];
109 $row = $dbw->selectRow(
112 [
'ul_key' =>
'populate interwiki' ],
117 $this->
output(
"Interwiki table already populated. Use php " .
118 "maintenance/populateInterwiki.php\n--force from the command line " .
124 $lookup = MediaWikiServices::getInstance()->getInterwikiLookup();
125 foreach ( $data as $d ) {
126 $prefix = $d[
'prefix'];
128 $row = $dbw->selectRow(
131 [
'iw_prefix' => $prefix ],
139 'iw_prefix' => $prefix,
140 'iw_url' => $d[
'url'],
150 $lookup->invalidateCache( $prefix );
153 $this->
output(
"Interwiki links are populated.\n" );
161 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.
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)