/** * Search repositories for an image. * You can also use wfFindFile() to do this. * * @param $title Title|string Title object or string * @param $options array Associative array of options: * time: requested time for an archived image, or false for the * current version. An image object will be returned which was * created at the specified time. * * ignoreRedirect: If true, do not follow file redirects * * private: If true, return restricted (deleted) files if the current * user is allowed to view them. Otherwise, such files will not * be found. * * bypassCache: If true, do not use the process-local cache of File objects * @return File object or false if it is not found */ function findFile($title, $options = array()) { if (!is_array($options)) { // MW 1.15 compat $options = array('time' => $options); } if (!$this->reposInitialised) { $this->initialiseRepos(); } $title = File::normalizeTitle($title); if (!$title) { return false; } # Check the cache if (empty($options['ignoreRedirect']) && empty($options['private']) && empty($options['bypassCache'])) { $useCache = true; $time = isset($options['time']) ? $options['time'] : ''; $dbkey = $title->getDBkey(); if (isset($this->cache[$dbkey][$time])) { wfDebug(__METHOD__ . ": got File:{$dbkey} from process cache\n"); # Move it to the end of the list so that we can delete the LRU entry later $tmp = $this->cache[$dbkey]; unset($this->cache[$dbkey]); $this->cache[$dbkey] = $tmp; # Return the entry return $this->cache[$dbkey][$time]; } else { # Add a negative cache entry, may be overridden $this->trimCache(); $this->cache[$dbkey][$time] = false; $cacheEntry =& $this->cache[$dbkey][$time]; } } else { $useCache = false; } # Check the local repo $image = $this->localRepo->findFile($title, $options); if ($image) { if ($useCache) { $cacheEntry = $image; } return $image; } # Check the foreign repos foreach ($this->foreignRepos as $repo) { $image = $repo->findFile($title, $options); if ($image) { if ($useCache) { $cacheEntry = $image; } return $image; } } # Not found, do not override negative cache return false; }
/** * Search repositories for an image. * You can also use wfFindFile() to do this. * * @param $title Title|string Title object or string * @param $options array Associative array of options: * time: requested time for an archived image, or false for the * current version. An image object will be returned which was * created at the specified time. * * ignoreRedirect: If true, do not follow file redirects * * private: If true, return restricted (deleted) files if the current * user is allowed to view them. Otherwise, such files will not * be found. * * bypassCache: If true, do not use the process-local cache of File objects * @return File object or false if it is not found */ function findFile($title, $options = array()) { if (!is_array($options)) { // MW 1.15 compat $options = array('time' => $options); } if (!$this->reposInitialised) { $this->initialiseRepos(); } $title = File::normalizeTitle($title); if (!$title) { return false; } # Check the cache if (empty($options['ignoreRedirect']) && empty($options['private']) && empty($options['bypassCache'])) { $time = isset($options['time']) ? $options['time'] : ''; $dbkey = $title->getDBkey(); if (isset($this->cache[$dbkey][$time])) { wfDebug(__METHOD__ . ": got File:{$dbkey} from process cache\n"); # Move it to the end of the list so that we can delete the LRU entry later $this->pingCache($dbkey); # Return the entry return $this->cache[$dbkey][$time]; } $useCache = true; } else { $useCache = false; } # Check the local repo $image = $this->localRepo->findFile($title, $options); # Check the foreign repos if (!$image) { foreach ($this->foreignRepos as $repo) { $image = $repo->findFile($title, $options); if ($image) { break; } } } $image = $image ? $image : false; // type sanity # Cache file existence or non-existence if ($useCache && (!$image || $image->isCacheable())) { $this->trimCache(); $this->cache[$dbkey][$time] = $image; } return $image; }
/** * Search repositories for an image. * You can also use wfFindFile() to do this. * * @param Title|string $title Title object or string * @param array $options Associative array of options: * time: requested time for an archived image, or false for the * current version. An image object will be returned which was * created at the specified time. * ignoreRedirect: If true, do not follow file redirects * private: If true, return restricted (deleted) files if the current * user is allowed to view them. Otherwise, such files will not * be found. * latest: If true, load from the latest available data into File objects * @return File|bool False if title is not found */ function findFile($title, $options = []) { if (!is_array($options)) { // MW 1.15 compat $options = ['time' => $options]; } if (isset($options['bypassCache'])) { $options['latest'] = $options['bypassCache']; // b/c } if (!$this->reposInitialised) { $this->initialiseRepos(); } $title = File::normalizeTitle($title); if (!$title) { return false; } # Check the cache $dbkey = $title->getDBkey(); if (empty($options['ignoreRedirect']) && empty($options['private']) && empty($options['bypassCache'])) { $time = isset($options['time']) ? $options['time'] : ''; if ($this->cache->has($dbkey, $time, 60)) { return $this->cache->get($dbkey, $time); } $useCache = true; } else { $time = false; $useCache = false; } # Check the local repo $image = $this->localRepo->findFile($title, $options); # Check the foreign repos if (!$image) { foreach ($this->foreignRepos as $repo) { $image = $repo->findFile($title, $options); if ($image) { break; } } } $image = $image ? $image : false; // type sanity # Cache file existence or non-existence if ($useCache && (!$image || $image->isCacheable())) { $this->cache->set($dbkey, $time, $image); } return $image; }
/** * Search repositories for an image. * You can also use wfFindFile() to do this. * * @param $title Title|string Title object or string * @param $options array Associative array of options: * time: requested time for an archived image, or false for the * current version. An image object will be returned which was * created at the specified time. * * ignoreRedirect: If true, do not follow file redirects * * private: If true, return restricted (deleted) files if the current * user is allowed to view them. Otherwise, such files will not * be found. * * bypassCache: If true, do not use the process-local cache of File objects * @return File object or false if it is not found */ function findFile($title, $options = array()) { if (!is_array($options)) { // MW 1.15 compat $options = array('time' => $options); } if (!$this->reposInitialised) { $this->initialiseRepos(); } $title = File::normalizeTitle($title); if (!$title) { return false; } # Check the cache if (empty($options['ignoreRedirect']) && empty($options['private']) && empty($options['bypassCache'])) { $useCache = true; $time = isset($options['time']) ? $options['time'] : ''; $dbkey = $title->getDBkey(); if (isset($this->cache[$dbkey][$time])) { wfDebug(__METHOD__ . ": got File:{$dbkey} from process cache\n"); # Move it to the end of the list so that we can delete the LRU entry later $tmp = $this->cache[$dbkey]; unset($this->cache[$dbkey]); $this->cache[$dbkey] = $tmp; # Return the entry return $this->cache[$dbkey][$time]; } else { # Add a negative cache entry, may be overridden $this->trimCache(); $this->cache[$dbkey][$time] = false; $cacheEntry =& $this->cache[$dbkey][$time]; } } else { $useCache = false; } # Check the local repo $image = $this->localRepo->findFile($title, $options); if ($image) { if ($useCache) { $cacheEntry = $image; } return $image; } # Wikia change - begin # @author macbre # Check redirects before checking foreign repositories (BAC-352) $titleRedirected = $this->localRepo->checkRedirect($title); if ($titleRedirected) { wfDebug(__METHOD__ . ": followed redirect before checking foreign repos\n"); $title = $titleRedirected; } # Wikia change - end # Check the foreign repos foreach ($this->foreignRepos as $repo) { $image = $repo->findFile($title, $options); if ($image) { /* Wikia changes begin */ // check if the foreign repo allows local repo file blocking if ($repo->allowBlocking) { $isDeleted = false; wfRunHooks('ForeignFileDeleted', array($image, &$isDeleted)); if ($isDeleted) { return false; } } /* Wikia changes end */ if ($useCache) { $cacheEntry = $image; } return $image; } } /* Wikia changes begin */ if ($title->isRedirect()) { // get redirected file if the foreign repo allows file redirecting wfRunHooks('FindRedirectedFile', array($this->foreignRepos, $title, $options, $useCache, &$image, &$cacheEntry)); if ($image) { return $image; } } /* Wikia changes end */ # Not found, do not override negative cache return false; }