static function purge($urlArr) { $caller = self::getPurgeCaller(); wfDebug("Purging backtrace: " . wfGetAllCallers(false) . "\n"); // Filter urls into buckets based on service backend $buckets = array_reduce($urlArr, function ($carry, $item) use($caller) { global $wgPurgeVignetteUsingSurrogateKeys; wfDebug("Purging URL {$item} from {$caller} via Celery\n"); if (isset($wgPurgeVignetteUsingSurrogateKeys) && VignetteRequest::isVignetteUrl($item)) { $carry['vignette'][] = $item; } elseif (strstr($item, 'MercuryApi') !== false) { $carry['mercury'][] = $item; $carry['mediawiki'][] = $item; // TODO: we can remove this when mercury is only using internal cache } else { $carry['mediawiki'][] = $item; } return $carry; }, array('mediawiki' => [], 'vignette' => [], 'mercury' => [])); if (empty(CeleryPurge::$buckets)) { CeleryPurge::$buckets = $buckets; } else { CeleryPurge::$buckets = array_merge_recursive(CeleryPurge::$buckets, $buckets); } }
public function __construct($url, $asOriginal = false) { $this->url = $url; $this->asOriginal = $asOriginal; if (!VignetteRequest::isVignetteUrl($url)) { $this->reportError('invalid url'); } }
/** * @param $imageName */ private function initializeImagePaths($cropPosition) { $imageTitle = Title::newFromText($this->imageName, NS_FILE); $file = wfFindFile($imageTitle); if ($file && $file->exists()) { $fullUrl = $file->getFullUrl(); if (VignetteRequest::isVignetteUrl($fullUrl)) { $this->imagePath = $this->createVignetteThumbnail($file, $cropPosition); } else { $this->imagePath = $this->createOldThumbnail($file, $cropPosition); } $this->originalImagePath = $fullUrl; } else { $this->imageName = null; $this->imagePath = null; $this->originalImagePath = null; } }
public function __construct(WebRequest $request) { global $IP; parent::__construct($request); // TODO: the background image shouldn't be passed as the url - we should pass a File reference and derive ourselves if (isset($this->mParams['background-image']) && VignetteRequest::isVignetteUrl($this->mParams['background-image']) && isset($this->mParams['path-prefix'])) { $connector = strpos($this->mParams['background-image'], '?') === false ? '?' : '&'; $this->mParams['background-image'] .= "{$connector}path-prefix={$this->mParams['path-prefix']}"; } if (strpos($this->mOid, '..') !== false) { throw new Exception('File path must not contain \'..\'.'); } if (!endsWith($this->mOid, '.scss', false)) { throw new Exception('Requested file must be .scss.'); } //remove slashes at the beginning of the string, we need a pure relative path to open the file $this->mOid = preg_replace('/^[\\/]+/', '', $this->mOid); if (!file_exists("{$IP}/{$this->mOid}")) { throw new Exception("File {$this->mOid} does not exist!"); } $this->mContentType = AssetsManager::TYPE_CSS; }
/** * Get wiki background full, up-to-date URL * * This method returns URL based on "background-image" and performs URL rewrite * for migrated wikis with short Swift bucket name * * @see $wgUploadPath - "http://images.wikia.com/24_/es/images" * * @author macbre * @return string background URL or empty string if not found */ public function getBackgroundUrl() { global $wgUploadPath; $backgroundUrl = $this->getSettings()['background-image']; if (!VignetteRequest::isVignetteUrl($backgroundUrl)) { if (empty($backgroundUrl)) { return $backgroundUrl; } $backgroundPath = explode('/images/', $backgroundUrl)[0]; if (!empty($wordmarkPath)) { $backgroundUrl = str_replace($backgroundPath . '/images', $wgUploadPath, $backgroundUrl); } $backgroundUrl = wfReplaceImageServer($backgroundUrl, SassUtil::getCacheBuster()); } return $backgroundUrl; }
/** * make an image if it's allowed, either through the global * option, through the exception, or through the on-wiki whitelist * @private * * $param $url string * * @return string */ function maybeMakeExternalImage($url) { global $wgAllowExternalWhitelistImages; # wikia $imagesfrom = $this->mOptions->getAllowExternalImagesFrom(); $imagesexception = !empty($imagesfrom); $isValidImageUrl = VignetteRequest::isVignetteUrl($url) || preg_match(self::EXT_IMAGE_REGEX, $url); $text = false; # $imagesfrom could be either a single string or an array of strings, parse out the latter if ($imagesexception && is_array($imagesfrom)) { $imagematch = false; foreach ($imagesfrom as $match) { if (strpos($url, $match) === 0) { $imagematch = true; break; } } } elseif ($imagesexception) { $imagematch = strpos($url, $imagesfrom) === 0; } else { $imagematch = false; } if ($this->mOptions->getAllowExternalImages() || !empty($wgAllowExternalWhitelistImages) && wfRunHooks('outputMakeExternalImage', array(&$url)) || $imagesexception && $imagematch) { if ($isValidImageUrl) { # Image found $text = Linker::makeExternalImage($url); } } if (!$text && $this->mOptions->getEnableImageWhitelist() && $isValidImageUrl) { $whitelist = explode("\n", wfMsgForContent('external_image_whitelist')); foreach ($whitelist as $entry) { # Sanitize the regex fragment, make it case-insensitive, ignore blank entries/comments if (strpos($entry, '#') === 0 || $entry === '') { continue; } if (preg_match('/' . str_replace('/', '\\/', $entry) . '/i', $url)) { # Image matches a whitelist entry $text = Linker::makeExternalImage($url); break; } } } return $text; }
/** * @desc Checks if given URL is pointing to our external thumbnail service. * * @param String $url url to test * * @return boolean */ public static function IsExternalThumbnailUrl($url) { return VignetteRequest::isVignetteUrl($url) || strpos($url, '/images/thumb/') !== false; }
/** * Returns the filename part of an url. * Used as alternative text for external images. * * @param $url string * * @return string */ private static function fnamePart($url) { if (VignetteRequest::isVignetteUrl($url)) { $basename = VignetteRequest::getImageFilename($url); if ($basename) { return $basename; } } $basename = strrchr($url, '/'); if (false === $basename) { $basename = $url; } else { $basename = substr($basename, 1); } return $basename; }