diff --git "a/include/class-wm\\Wikidata.php" "b/include/class-wm\\Wikidata.php" index 71800cf..42ccaa3 100644 --- "a/include/class-wm\\Wikidata.php" +++ "b/include/class-wm\\Wikidata.php" @@ -1,72 +1,78 @@ . # Wikimedia namespace wm; /** * Wikidata singleton instance * * @see https://www.wikidata.org/ */ class Wikidata extends \mw\StaticWikibaseSite { /** * @override */ const UID = 'wikidatawiki'; /** * @override */ const API_URL = 'https://www.wikidata.org/w/api.php'; /** * Execute a SPARQL query * * @param $query string SPARQL query * @return array */ public static function querySPARQL( $query ) { + + // do some cleanage + $query = trim( $query ); + $request = new \network\HTTPRequest( 'https://query.wikidata.org/sparql' ); $response = $request->fetch( [ 'format' => 'json', - 'query' => $query + 'query' => $query, ] ); + + // TODO: nice exceptions $response_obj = json_decode( $response ); return $response_obj->results->bindings; } /** * Retrieve the label (in English) of a property (from the cache) * * @param $property string Property title e.g. P123 * @return string|false Label in English or false */ public static function propertyLabel( $property ) { static $cache; $path = __DIR__ . '/../cache/Wikidata/properties.json'; if( ! $cache && file_exists( $path ) ) { $cache = json_decode( file_get_contents( $path ) ); } if( isset( $cache->{ $property } ) ) { return $cache->{ $property }; } return false; } }