コード例 #1
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;
     }
 }
コード例 #2
0
ファイル: File.php プロジェクト: mb720/mediawiki
 /**
  * Get the SHA-1 base 36 hash of the file
  *
  * @return string
  */
 function getSha1()
 {
     $this->assertRepoDefined();
     return $this->repo->getFileSha1($this->getPath());
 }
コード例 #3
0
 /**
  * HTTP GET request to a mediawiki API (with caching)
  * @param string $target Used in cache key creation, mostly
  * @param array $query The query parameters for the API request
  * @param int $cacheTTL Time to live for the memcached caching
  * @return null
  */
 public function httpGetCached($target, $query, $cacheTTL = 3600)
 {
     if ($this->mApiBase) {
         $url = wfAppendQuery($this->mApiBase, $query);
     } else {
         $url = $this->makeUrl($query, 'api');
     }
     if (!isset($this->mQueryCache[$url])) {
         $data = ObjectCache::getMainWANInstance()->getWithSetCallback($this->getLocalCacheKey(get_class($this), $target, md5($url)), $cacheTTL, function () use($url) {
             return ForeignAPIRepo::httpGet($url);
         });
         if (!$data) {
             return null;
         }
         if (count($this->mQueryCache) > 100) {
             // Keep the cache from growing infinitely
             $this->mQueryCache = [];
         }
         $this->mQueryCache[$url] = $data;
     }
     return $this->mQueryCache[$url];
 }
コード例 #4
0
ファイル: ForeignAPIRepo.php プロジェクト: paladox/mediawiki
 /**
  * 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;
     }
 }
コード例 #5
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;
     }
 }