require $baseDir . 'lib/wikidata.php';
require $baseDir . 'lib/popularity.php';
$api = new Toplist\Api();
$validationRules = array('id' => 'integer|min_numeric,0|max_numeric,9999', 'popularity' => 'alpha_dash');
$filterRules = array('id' => 'trim|sanitize_numbers', 'popularity' => 'trim|sanitize_string');
$parameters = $api->getParameters($validationRules, $filterRules);
$laureate = @$parameters['id'] ?: 1;
/* Get dbPedia url */
$simpleSPARQLQuery = new Toplist\SimpleSPARQLQuery($laureate);
$dbPediaLink = $simpleSPARQLQuery->getDbpedia();
if (array_key_exists('popularity', $parameters) && $parameters['popularity'] === 'wikipedia') {
    /* Get all WP ids from dbPedia */
    $dbPediaQuery = new Toplist\DbPediaQuery();
    $wpName = $dbPediaQuery->getWikipediaNames($dbPediaLink);
    /* get iw links */
    $wikiDataQuery = new Toplist\WikiDataQuery();
    $iwLinks = $wikiDataQuery->getSitelinks(array_pop($wpName));
    global $gStatsInterval;
    global $gStatsStart;
    if (preg_match('/^\\d{8}/', $gStatsStart)) {
        /* A date */
    } else {
        /* Assume an offset */
        global $gTimezone;
        $date = new \DateTime('now', new DateTimeZone($gTimezone));
        $date->add(\DateInterval::createFromDateString('-' . $gStatsStart));
        $gStatsStart = $date->format('Ymd');
    }
    /* get Article stats for each WP */
    global $gStatsWPEditions;
    $totalWeight = 0;
Ejemplo n.º 2
0
}
/* Get dbPedia url */
$simpleSPARQLQuery = new Toplist\SimpleSPARQLQuery($laureate);
$dbPediaLink = $simpleSPARQLQuery->getDbpedia();
/* Query DbPedia for enwp link */
$dbPediaQuery = new Toplist\DbPediaQuery();
$response = $dbPediaQuery->getWikipediaNames($dbPediaLink);
if (!array_key_exists($dbPediaLink, $response)) {
    /* No such dbPedia article, or invalid laureate id */
    $api->write_headers();
    $api->write_json(array($laureate => array()));
    exit;
}
$enWikipediaName = $response[$dbPediaLink];
/* Get language links */
$wikiDataQuery = new Toplist\WikiDataQuery();
$iwLinks = $wikiDataQuery->getSitelinks($enWikipediaName);
$allWikipediaNames = array();
global $gImageSourceWPEditions;
foreach ($gImageSourceWPEditions as $wpEdition) {
    if (array_key_exists($wpEdition . 'wiki', $iwLinks)) {
        $allWikipediaNames[$wpEdition] = $iwLinks[$wpEdition . 'wiki'];
    }
}
/* Query Wikipedias for images */
$output = array();
foreach ($allWikipediaNames as $wikipediaEdition => $pageName) {
    $wikipediaApi = new TopList\WikipediaQuery($wikipediaEdition);
    $images = $wikipediaApi->getImages($pageName, $width, $height);
    $output = array_merge($images, $output);
}