/** * Get the HTML text of the description page, if available * * @param bool|Language $lang Optional language to fetch description in * @return string */ function getDescriptionText($lang = false) { global $wgMemc, $wgLang; if (!$this->repo || !$this->repo->fetchDescription) { return false; } if (!$lang) { $lang = $wgLang; } $renderUrl = $this->repo->getDescriptionRenderUrl($this->getName(), $lang->getCode()); if ($renderUrl) { if ($this->repo->descriptionCacheExpiry > 0) { wfDebug("Attempting to get the description from cache..."); $key = $this->repo->getLocalCacheKey('RemoteFileDescription', 'url', $lang->getCode(), $this->getName()); $obj = $wgMemc->get($key); if ($obj) { wfDebug("success!\n"); return $obj; } wfDebug("miss\n"); } wfDebug("Fetching shared description from {$renderUrl}\n"); $res = Http::get($renderUrl); if ($res && $this->repo->descriptionCacheExpiry > 0) { $wgMemc->set($key, $res, $this->repo->descriptionCacheExpiry); } return $res; } else { return false; } }
/** * Get the HTML text of the description page, if available * * @param bool|Language $lang Optional language to fetch description in * @return string */ function getDescriptionText($lang = false) { global $wgLang; if (!$this->repo || !$this->repo->fetchDescription) { return false; } $lang = $lang ?: $wgLang; $renderUrl = $this->repo->getDescriptionRenderUrl($this->getName(), $lang->getCode()); if ($renderUrl) { $cache = ObjectCache::getMainWANInstance(); $key = null; if ($this->repo->descriptionCacheExpiry > 0) { wfDebug("Attempting to get the description from cache..."); $key = $this->repo->getLocalCacheKey('RemoteFileDescription', 'url', $lang->getCode(), $this->getName()); $obj = $cache->get($key); if ($obj) { wfDebug("success!\n"); return $obj; } wfDebug("miss\n"); } wfDebug("Fetching shared description from {$renderUrl}\n"); $res = Http::get($renderUrl, array(), __METHOD__); if ($res && $key) { $cache->set($key, $res, $this->repo->descriptionCacheExpiry); } return $res; } else { return false; } }
/** * Get the HTML text of the description page, if available * * @param bool|Language $lang Optional language to fetch description in * @return string */ function getDescriptionText($lang = false) { global $wgLang; if (!$this->repo || !$this->repo->fetchDescription) { return false; } $lang = $lang ?: $wgLang; $renderUrl = $this->repo->getDescriptionRenderUrl($this->getName(), $lang->getCode()); if ($renderUrl) { $cache = ObjectCache::getMainWANInstance(); $key = $this->repo->getLocalCacheKey('RemoteFileDescription', 'url', $lang->getCode(), $this->getName()); return $cache->getWithSetCallback($key, $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE, function ($oldValue, &$ttl, array &$setOpts) use($renderUrl) { wfDebug("Fetching shared description from {$renderUrl}\n"); $res = Http::get($renderUrl, [], __METHOD__); if (!$res) { $ttl = WANObjectCache::TTL_UNCACHEABLE; } return $res; }); } return false; }