Example #1
0
 /**
  * Like a Http:get request, but with custom User-Agent.
  * @see Http::get
  * @param string $url
  * @param string $timeout
  * @param array $options
  * @param integer|bool &$mtime Resulting Last-Modified UNIX timestamp if received
  * @return bool|string
  */
 public static function httpGet($url, $timeout = 'default', $options = [], &$mtime = false)
 {
     $options['timeout'] = $timeout;
     /* Http::get */
     $url = wfExpandUrl($url, PROTO_HTTP);
     wfDebug("ForeignAPIRepo: HTTP GET: {$url}\n");
     $options['method'] = "GET";
     if (!isset($options['timeout'])) {
         $options['timeout'] = 'default';
     }
     $req = MWHttpRequest::factory($url, $options, __METHOD__);
     $req->setUserAgent(ForeignAPIRepo::getUserAgent());
     $status = $req->execute();
     if ($status->isOK()) {
         $lmod = $req->getResponseHeader('Last-Modified');
         $mtime = $lmod ? wfTimestamp(TS_UNIX, $lmod) : false;
         return $req->getContent();
     } else {
         $logger = LoggerFactory::getInstance('http');
         $logger->warning($status->getWikiText(false, false, 'en'), ['caller' => 'ForeignAPIRepo::httpGet']);
         return false;
     }
 }
Example #2
0
 /**
  * Like a Http:get request, but with custom User-Agent.
  * @see Http:get
  */
 public static function httpGet($url, $timeout = 'default', $options = array())
 {
     $options['timeout'] = $timeout;
     /* Http::get */
     $url = wfExpandUrl($url, PROTO_HTTP);
     wfDebug("ForeignAPIRepo: HTTP GET: {$url}\n");
     $options['method'] = "GET";
     if (!isset($options['timeout'])) {
         $options['timeout'] = 'default';
     }
     $req = MWHttpRequest::factory($url, $options);
     $req->setUserAgent(ForeignAPIRepo::getUserAgent());
     $status = $req->execute();
     if ($status->isOK()) {
         return $req->getContent();
     } else {
         return false;
     }
 }
Example #3
0
 /**
  * Like a Http:get request, but with custom User-Agent.
  * @see Http:get
  * @param string $url
  * @param string $timeout
  * @param array $options
  * @return bool|String
  */
 public static function httpGet($url, $timeout = 'default', $options = array())
 {
     $options['timeout'] = $timeout;
     /* Http::get */
     $url = wfExpandUrl($url, PROTO_HTTP);
     wfDebug("ForeignAPIRepo: HTTP GET: {$url}\n");
     $options['method'] = "GET";
     if (!isset($options['timeout'])) {
         $options['timeout'] = 'default';
     }
     $req = MWHttpRequest::factory($url, $options);
     $req->setUserAgent(ForeignAPIRepo::getUserAgent());
     $status = $req->execute();
     if ($status->isOK()) {
         return $req->getContent();
     } else {
         $logger = LoggerFactory::getInstance('http');
         $logger->warning($status->getWikiText(), array('caller' => 'ForeignAPIRepo::httpGet'));
         return false;
     }
 }