Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param string $vignetteResult
  * @param string $legacyDefinition
  * @dataProvider legacyThumbDefinitions
  */
 public function testApplyLegacyThumbDefinition($vignetteResult, $legacyDefinition)
 {
     $this->mockGlobalVariable('wgVignetteUrl', $this->vignetteUrl);
     $baseUrl = "{$this->vignetteUrl}/tests/images/a/ab/filename.jpg/revision/latest";
     $generator = VignetteRequest::fromConfigMap(['relative-path' => 'a/ab/filename.jpg', 'bucket' => 'tests', 'timestamp' => '123', 'domain-shard-count' => 1]);
     $actual = VignetteRequest::applyLegacyThumbDefinition($generator, $legacyDefinition)->url();
     $this->assertEquals("{$baseUrl}/{$vignetteResult}", $actual);
 }
 /**
  * Get a URL to access the thumbnail
  * This is required because the model of how files work requires that
  * the thumbnail urls be predictable. However, in our model the URL is not based on the filename
  * (that's hidden in the db)
  * Wikia change:
  *		Use our external thumbnailer for UploadStashFiles
  *		We need to look into temp directory while upload stash is saving file there
  *
  * @param String $suffix string that will be added at the end of path
  * @return String: URL to access thumbnail, or URL with partial path
  */
 public function getThumbUrl($suffix = false)
 {
     global $wgEnableVignette;
     if ($wgEnableVignette) {
         $generator = VignetteRequest::applyLegacyThumbDefinition($this->getUrlGenerator(), $suffix);
         $path = $generator->url();
     } else {
         $path = $this->repo->getZoneUrl('thumb') . '/temp/' . $this->getUrlRel();
         if ($suffix !== false) {
             $path .= '/' . rawurlencode($suffix);
         }
     }
     return $path;
 }
 public function build()
 {
     if (!$this->parseUrl()) {
         $this->reportError('unable to parse url');
     }
     $isArchive = $this->urlParts['revision'] != \Wikia\Vignette\UrlGenerator::REVISION_LATEST;
     if ($isArchive) {
         $this->timestamp = $this->urlParts['revision'];
     }
     $generator = VignetteRequest::fromConfigMap(['bucket' => $this->urlParts['bucket'], 'relative-path' => $this->urlParts['relativePath'], 'timestamp' => $this->timestamp, 'path-prefix' => $this->pathPrefix, 'is-archive' => $isArchive]);
     if (!$this->asOriginal && isset($this->urlParts['thumbnailDefinition'])) {
         $this->addThumbDefinition($generator);
     }
     return $generator;
 }
Ejemplo n.º 5
0
 /**
  * Adds extra variables to the page config.
  */
 public static function onMakeGlobalVariablesScript(array &$vars, OutputPage $out)
 {
     global $wgMaxUploadSize, $wgEnableVisualEditorUI, $wgEnableWikiaInteractiveMaps, $wgIntMapConfig, $wgUser, $wgUploadPath, $wgReCaptchaPublicKey;
     $vars['wgMaxUploadSize'] = $wgMaxUploadSize;
     $vars['wgEnableVisualEditorUI'] = !empty($wgEnableVisualEditorUI);
     $vars['wgEnableWikiaInteractiveMaps'] = !empty($wgEnableWikiaInteractiveMaps);
     if (!empty($wgIntMapConfig)) {
         $vars['interactiveMapsApiURL'] = $wgIntMapConfig['protocol'] . '://' . $wgIntMapConfig['hostname'] . ':' . $wgIntMapConfig['port'] . '/api/' . $wgIntMapConfig['version'];
     }
     // Note: even if set as integer, option value is retrieved as string
     if ($wgUser->getGlobalPreference('showVisualEditorTransitionDialog') === '1') {
         $vars['showVisualEditorTransitionDialog'] = 1;
     }
     $vars['VignettePathPrefix'] = VignetteRequest::parsePathPrefix($wgUploadPath);
     $vars['reCaptchaPublicKey'] = $wgReCaptchaPublicKey;
     return true;
 }
 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;
 }
Ejemplo n.º 7
0
 /**
  * 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;
 }
Ejemplo n.º 8
0
 /**
  * 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;
 }
Ejemplo n.º 9
0
 private function createVignetteThumbnail($file, $cropPosition)
 {
     return VignetteRequest::fromUrl($file->getFullUrl())->windowCrop()->width(self::WIKI_HERO_IMAGE_MAX_WIDTH)->xOffset(0)->yOffset(round($file->getHeight() * $cropPosition))->windowWidth($file->getWidth())->windowHeight(round($file->getWidth() / 4))->url();
 }
Ejemplo n.º 10
0
 /**
  * @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;
 }
Ejemplo n.º 11
0
 /**
  * @return \Wikia\Vignette\UrlGenerator object
  */
 public function getUrlGenerator()
 {
     return VignetteRequest::fromConfigMap(['is-archive' => false, 'timestamp' => $this->getTimestamp(), 'relative-path' => $this->getUrlRel(), 'bucket' => $this->getBucket(), 'path-prefix' => $this->getPathPrefix()]);
 }
Ejemplo n.º 12
0
 private static function buildVignetteUrl($width, $bucket, $relativePath, $timestamp, $avatarImageType = true)
 {
     $config = ['bucket' => $bucket, 'timestamp' => $timestamp, 'relative-path' => $relativePath];
     $avatar = VignetteRequest::fromConfigMap($config)->scaleToWidth($width);
     if (intval($width) > self::PERFORMANCE_JPEG_THRESHOLD) {
         $avatar->jpg();
     }
     if ($avatarImageType) {
         $avatar->avatar();
     }
     return $avatar->url();
 }
Ejemplo n.º 13
0
 /**
  * Get the Vignette\UrlGenerator for this file.
  *
  * @return \Wikia\Vignette\UrlGenerator
  *
  */
 public function getUrlGenerator()
 {
     $timestamp = $this->isOld() ? $this->getArchiveTimestamp() : $this->getTimestamp();
     return VignetteRequest::fromConfigMap(['is-archive' => $this->isOld(), 'timestamp' => $timestamp, 'relative-path' => $this->getHashPath() . rawurlencode($this->getName()), 'bucket' => $this->getBucket(), 'path-prefix' => $this->getPathPrefix()]);
 }
Ejemplo n.º 14
0
 function getPathPrefix()
 {
     $wikiDbName = $this->repo->getDBName();
     $wikiId = WikiFactory::DBtoID($wikiDbName);
     $wikiUploadPath = WikiFactory::getVarValueByName('wgUploadPath', $wikiId);
     return VignetteRequest::parsePathPrefix($wikiUploadPath);
 }
Ejemplo n.º 15
0
 /**
  * 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;
 }