139 public function query( $sparql, $rawData =
false ) {
140 if ( empty( $this->endpoint ) ) {
143 $queryData = [
"query" => $sparql,
"format" =>
"json" ];
144 $options = array_merge( [
'method' =>
'GET' ], $this->options );
146 if ( empty(
$options[
'userAgent'] ) ) {
150 if ( $this->timeout >= 0 ) {
152 $queryData[
'maxQueryTimeMillis'] = $this->timeout * 1000;
156 if ( strlen( $sparql ) > self::MAX_GET_SIZE ) {
159 $options[
'postData'] =
'query=' . urlencode( $sparql );
160 unset( $queryData[
'query'] );
164 $request = $this->requestFactory->create( $url,
$options, __METHOD__ );
166 $status = $request->execute();
168 if ( !$status->isOK() ) {
169 throw new SparqlException(
'HTTP error: ' . $status->getWikiText(
false,
false,
'en' ) );
171 $result = $request->getContent();
172 \Wikimedia\suppressWarnings();
173 $data = json_decode( $result,
true );
174 \Wikimedia\restoreWarnings();
175 if ( $data ===
null || $data ===
false ) {
177 substr( $result, 1024 ) );