Skip to content

Instantly share code, notes, and snippets.

@phuedx
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phuedx/8941767 to your computer and use it in GitHub Desktop.
Save phuedx/8941767 to your computer and use it in GitHub Desktop.
<?php
require __DIR__ . '/wmgUseGettingStarted.php'; // Modified to initialise $wmgUseGettingStarted
function getSitelinksByID( $id ) {
$url = "https://www.wikidata.org/w/api.php?format=json&action=wbgetentities&props=sitelinks&ids={$id}";
$responseBodyRaw = file_get_contents( $url );
$responseBody = json_decode( $responseBodyRaw, true );
$entity = $responseBody[ 'entities' ][ $id ];
$result = array();
foreach ( $entity[ 'sitelinks' ] as $wgDBname => $sitelink ) {
$result[ $wgDBname ] = $sitelink[ 'title' ];
}
return $result;
}
$taskToWikidataCategoryIDMap = array(
'copyedit' => 'Q9137504', // Category:Wikipedia articles needing copy edit
'clarify' => 'Q8235653', // Category:All Wikipedia articles needing clarification
'addlinks' => 'Q8235714', // Category:All articles with too few wikilinks
);
$config = array();
foreach ( $taskToWikidataCategoryIDMap as $task => $id ) {
$sitelinks = getSitelinksByID( $id );
foreach ( $sitelinks as $wgDBname => $category ) {
if ( isset( $wmgUseGettingStarted[ $wgDBname ] ) && $wmgUseGettingStarted[ $wgDBname ] ) {
$config[ $wgDBname ][ $task ] = $category;
}
}
}
$contents = var_export( $config, true );
file_put_contents( 'wmgGettingStartedCategoriesForTaskTypes.php', $contents );
$config = getSitelinksByID( 'Q5312304' ); // Category:Living people
$contents = var_export( $config, true );
file_put_contents( 'wmgGettingStartedExcludedCategories.php', $contents );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment