Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/files/PhabricatorImageTransformer.php b/src/applications/files/PhabricatorImageTransformer.php
index 24d81aeb49..0db67d3126 100644
--- a/src/applications/files/PhabricatorImageTransformer.php
+++ b/src/applications/files/PhabricatorImageTransformer.php
@@ -1,143 +1,186 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorImageTransformer {
public function executeThumbTransform(
PhabricatorFile $file,
$x,
$y) {
$image = $this->crudelyScaleTo($file, $x, $y);
return PhabricatorFile::newFromFileData(
$image,
array(
'name' => 'thumb-'.$file->getName(),
));
}
public function executeProfileTransform(
PhabricatorFile $file,
$x,
$min_y,
$max_y) {
$image = $this->crudelyCropTo($file, $x, $min_y, $max_y);
return PhabricatorFile::newFromFileData(
$image,
array(
'name' => 'profile-'.$file->getName(),
));
}
+ public function executePreviewTransform(
+ PhabricatorFile $file,
+ $size) {
+
+ $image = $this->generatePreview($file, $size);
+
+ return PhabricatorFile::newFromFileData(
+ $image,
+ array(
+ 'name' => 'preview-'.$file->getName(),
+ ));
+ }
+
+
private function crudelyCropTo(PhabricatorFile $file, $x, $min_y, $max_y) {
$data = $file->loadFileData();
$img = imagecreatefromstring($data);
$sx = imagesx($img);
$sy = imagesy($img);
$scaled_y = ($x / $sx) * $sy;
if ($scaled_y > $max_y) {
// This image is very tall and thin.
$scaled_y = $max_y;
} else if ($scaled_y < $min_y) {
// This image is very short and wide.
$scaled_y = $min_y;
}
$img = $this->applyScaleTo(
$img,
$x,
$scaled_y);
return $this->saveImageDataInAnyFormat($img, $file->getMimeType());
}
/**
* Very crudely scale an image up or down to an exact size.
*/
private function crudelyScaleTo(PhabricatorFile $file, $dx, $dy) {
$data = $file->loadFileData();
$src = imagecreatefromstring($data);
$dst = $this->applyScaleTo($src, $dx, $dy);
return $this->saveImageDataInAnyFormat($dst, $file->getMimeType());
}
private function applyScaleTo($src, $dx, $dy) {
$x = imagesx($src);
$y = imagesy($src);
- $scale = min($x / $dx, $y / $dy);
+ $scale = min(($dx / $x), ($dy / $y), 1);
+
$dst = imagecreatetruecolor($dx, $dy);
imagesavealpha($dst, true);
- imagefill($dst, 0, 0, imagecolorallocatealpha($dst, 0, 0, 0, 127));
+ imagefill($dst, 0, 0, imagecolorallocatealpha($dst, 255, 255, 255, 127));
- // If we need to chop off some pixels, chop them off from the sides instead
- // of scaling in on <0, 0>.
- $sdx = $scale * $dx;
- $sdy = $scale * $dy;
+ $sdx = $scale * $x;
+ $sdy = $scale * $y;
imagecopyresampled(
$dst,
$src,
+ ($dx - $sdx) / 2, ($dy - $sdy) / 2,
0, 0,
- ($x - $sdx) / 2, ($y - $sdy) / 2,
- $dx, $dy,
- $sdx, $sdy);
+ $sdx, $sdy,
+ $x, $y);
return $dst;
}
+ private function generatePreview(PhabricatorFile $file, $size) {
+ $data = $file->loadFileData();
+ $src = imagecreatefromstring($data);
+
+ $x = imagesx($src);
+ $y = imagesy($src);
+
+ $scale = min($size / $x, $size / $y, 1);
+
+ $dx = max($size / 4, $scale * $x);
+ $dy = max($size / 4, $scale * $y);
+
+ $dst = imagecreatetruecolor($dx, $dy);
+ imagesavealpha($dst, true);
+ imagefill($dst, 0, 0, imagecolorallocatealpha($dst, 255, 255, 255, 127));
+
+ $sdx = $scale * $x;
+ $sdy = $scale * $y;
+
+ imagecopyresampled(
+ $dst,
+ $src,
+ ($dx - $sdx) / 2, ($dy - $sdy) / 2,
+ 0, 0,
+ $sdx, $sdy,
+ $x, $y);
+
+ return $this->saveImageDataInAnyFormat($dst, $file->getMimeType());
+ }
+
private function saveImageDataInAnyFormat($data, $preferred_mime = '') {
switch ($preferred_mime) {
case 'image/gif': // GIF doesn't support true color.
case 'image/png':
if (function_exists('imagepng')) {
ob_start();
imagepng($data);
return ob_get_clean();
}
break;
}
$img = null;
if (function_exists('imagejpeg')) {
ob_start();
imagejpeg($data);
$img = ob_get_clean();
} else if (function_exists('imagepng')) {
ob_start();
imagepng($data);
$img = ob_get_clean();
} else if (function_exists('imagegif')) {
ob_start();
imagegif($data);
$img = ob_get_clean();
} else {
throw new Exception("No image generation functions exist!");
}
return $img;
}
}
diff --git a/src/applications/files/controller/PhabricatorFileTransformController.php b/src/applications/files/controller/PhabricatorFileTransformController.php
index ec78c7be8a..290889a8ff 100644
--- a/src/applications/files/controller/PhabricatorFileTransformController.php
+++ b/src/applications/files/controller/PhabricatorFileTransformController.php
@@ -1,141 +1,152 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorFileTransformController
extends PhabricatorFileController {
private $transform;
private $phid;
public function willProcessRequest(array $data) {
$this->transform = $data['transform'];
$this->phid = $data['phid'];
}
public function processRequest() {
$xform = id(new PhabricatorTransformedFile())
->loadOneWhere(
'originalPHID = %s AND transform = %s',
$this->phid,
$this->transform);
if ($xform) {
return $this->buildTransformedFileResponse($xform);
}
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $this->phid);
if (!$file) {
return new Aphront404Response();
}
$type = $file->getMimeType();
if (!$file->isViewableInBrowser() || !$file->isTransformableImage()) {
return $this->buildDefaultTransformation($file);
}
// We're essentially just building a cache here and don't need CSRF
// protection.
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
switch ($this->transform) {
+ case 'thumb-220x165':
+ $xformed_file = $this->executeThumbTransform($file, 220, 165);
+ break;
+ case 'preview-220':
+ $xformed_file = $this->executePreviewTransform($file, 220);
+ break;
case 'thumb-160x120':
$xformed_file = $this->executeThumbTransform($file, 160, 120);
break;
case 'thumb-60x45':
$xformed_file = $this->executeThumbTransform($file, 60, 45);
break;
default:
return new Aphront400Response();
}
if (!$xformed_file) {
return new Aphront400Response();
}
$xform = new PhabricatorTransformedFile();
$xform->setOriginalPHID($this->phid);
$xform->setTransform($this->transform);
$xform->setTransformedPHID($xformed_file->getPHID());
$xform->save();
return $this->buildTransformedFileResponse($xform);
}
private function buildDefaultTransformation(PhabricatorFile $file) {
static $regexps = array(
'@application/zip@' => 'zip',
'@image/@' => 'image',
'@application/pdf@' => 'pdf',
'@.*@' => 'default',
);
$type = $file->getMimeType();
$prefix = 'default';
foreach ($regexps as $regexp => $implied_prefix) {
if (preg_match($regexp, $type)) {
$prefix = $implied_prefix;
break;
}
}
switch ($this->transform) {
case 'thumb-160x120':
$suffix = '160x120';
break;
case 'thumb-60x45':
$suffix = '60x45';
break;
default:
throw new Exception("Unsupported transformation type!");
}
$path = celerity_get_resource_uri(
"/rsrc/image/icon/fatcow/thumbnails/{$prefix}{$suffix}.png");
return id(new AphrontRedirectResponse())
->setURI($path);
}
private function buildTransformedFileResponse(
PhabricatorTransformedFile $xform) {
$file = id(new PhabricatorFile())->loadOneWhere(
'phid = %s',
$xform->getTransformedPHID());
if ($file) {
$uri = $file->getBestURI();
} else {
$bad_phid = $xform->getTransformedPHID();
throw new Exception(
"Unable to load file with phid {$bad_phid}."
);
}
// TODO: We could just delegate to the file view controller instead,
// which would save the client a roundtrip, but is slightly more complex.
return id(new AphrontRedirectResponse())->setURI($uri);
}
+ private function executePreviewTransform(PhabricatorFile $file, $size) {
+ $xformer = new PhabricatorImageTransformer();
+ return $xformer->executePreviewTransform($file, $size);
+ }
+
private function executeThumbTransform(PhabricatorFile $file, $x, $y) {
$xformer = new PhabricatorImageTransformer();
return $xformer->executeThumbTransform($file, $x, $y);
}
}
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
index 983788a755..72e3612a74 100644
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -1,423 +1,430 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorFile extends PhabricatorFileDAO {
const STORAGE_FORMAT_RAW = 'raw';
protected $phid;
protected $name;
protected $mimeType;
protected $byteSize;
protected $authorPHID;
protected $secretKey;
protected $contentHash;
protected $storageEngine;
protected $storageFormat;
protected $storageHandle;
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_FILE);
}
public static function readUploadedFileData($spec) {
if (!$spec) {
throw new Exception("No file was uploaded!");
}
$err = idx($spec, 'error');
if ($err) {
throw new PhabricatorFileUploadException($err);
}
$tmp_name = idx($spec, 'tmp_name');
$is_valid = @is_uploaded_file($tmp_name);
if (!$is_valid) {
throw new Exception("File is not an uploaded file.");
}
$file_data = Filesystem::readFile($tmp_name);
$file_size = idx($spec, 'size');
if (strlen($file_data) != $file_size) {
throw new Exception("File size disagrees with uploaded size.");
}
self::validateFileSize(strlen($file_data));
return $file_data;
}
public static function newFromPHPUpload($spec, array $params = array()) {
$file_data = self::readUploadedFileData($spec);
$file_name = nonempty(
idx($params, 'name'),
idx($spec, 'name'));
$params = array(
'name' => $file_name,
) + $params;
return self::newFromFileData($file_data, $params);
}
public static function newFromXHRUpload($data, array $params = array()) {
self::validateFileSize(strlen($data));
return self::newFromFileData($data, $params);
}
private static function validateFileSize($size) {
$limit = PhabricatorEnv::getEnvConfig('storage.upload-size-limit');
if (!$limit) {
return;
}
$limit = phabricator_parse_bytes($limit);
if ($size > $limit) {
throw new PhabricatorFileUploadException(-1000);
}
}
/**
* Given a block of data, try to load an existing file with the same content
* if one exists. If it does not, build a new file.
*
* This method is generally used when we have some piece of semi-trusted data
* like a diff or a file from a repository that we want to show to the user.
* We can't just dump it out because it may be dangerous for any number of
* reasons; instead, we need to serve it through the File abstraction so it
* ends up on the CDN domain if one is configured and so on. However, if we
* simply wrote a new file every time we'd potentially end up with a lot
* of redundant data in file storage.
*
* To solve these problems, we use file storage as a cache and reuse the
* same file again if we've previously written it.
*
* NOTE: This method unguards writes.
*
* @param string Raw file data.
* @param dict Dictionary of file information.
*/
public static function buildFromFileDataOrHash(
$data,
array $params = array()) {
$file = id(new PhabricatorFile())->loadOneWhere(
'name = %s AND contentHash = %s LIMIT 1',
self::normalizeFileName(idx($params, 'name')),
PhabricatorHash::digest($data));
if (!$file) {
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$file = PhabricatorFile::newFromFileData($data, $params);
unset($unguarded);
}
return $file;
}
public static function newFromFileData($data, array $params = array()) {
$selector = PhabricatorEnv::newObjectFromConfig('storage.engine-selector');
$engines = $selector->selectStorageEngines($data, $params);
if (!$engines) {
throw new Exception("No valid storage engines are available!");
}
$data_handle = null;
$engine_identifier = null;
$exceptions = array();
foreach ($engines as $engine) {
$engine_class = get_class($engine);
try {
// Perform the actual write.
$data_handle = $engine->writeFile($data, $params);
if (!$data_handle || strlen($data_handle) > 255) {
// This indicates an improperly implemented storage engine.
throw new PhabricatorFileStorageConfigurationException(
"Storage engine '{$engine_class}' executed writeFile() but did ".
"not return a valid handle ('{$data_handle}') to the data: it ".
"must be nonempty and no longer than 255 characters.");
}
$engine_identifier = $engine->getEngineIdentifier();
if (!$engine_identifier || strlen($engine_identifier) > 32) {
throw new PhabricatorFileStorageConfigurationException(
"Storage engine '{$engine_class}' returned an improper engine ".
"identifier '{$engine_identifier}': it must be nonempty ".
"and no longer than 32 characters.");
}
// We stored the file somewhere so stop trying to write it to other
// places.
break;
} catch (Exception $ex) {
if ($ex instanceof PhabricatorFileStorageConfigurationException) {
// If an engine is outright misconfigured (or misimplemented), raise
// that immediately since it probably needs attention.
throw $ex;
}
// If an engine doesn't work, keep trying all the other valid engines
// in case something else works.
phlog($ex);
$exceptions[] = $ex;
}
}
if (!$data_handle) {
throw new PhutilAggregateException(
"All storage engines failed to write file:",
$exceptions);
}
$file_name = idx($params, 'name');
$file_name = self::normalizeFileName($file_name);
// If for whatever reason, authorPHID isn't passed as a param
// (always the case with newFromFileDownload()), store a ''
$authorPHID = idx($params, 'authorPHID');
$file = new PhabricatorFile();
$file->setName($file_name);
$file->setByteSize(strlen($data));
$file->setAuthorPHID($authorPHID);
$file->setContentHash(PhabricatorHash::digest($data));
$file->setStorageEngine($engine_identifier);
$file->setStorageHandle($data_handle);
// TODO: This is probably YAGNI, but allows for us to do encryption or
// compression later if we want.
$file->setStorageFormat(self::STORAGE_FORMAT_RAW);
if (isset($params['mime-type'])) {
$file->setMimeType($params['mime-type']);
} else {
$tmp = new TempFile();
Filesystem::writeFile($tmp, $data);
$file->setMimeType(Filesystem::getMimeType($tmp));
}
$file->save();
return $file;
}
public static function newFromFileDownload($uri, $name) {
$uri = new PhutilURI($uri);
$protocol = $uri->getProtocol();
switch ($protocol) {
case 'http':
case 'https':
break;
default:
// Make sure we are not accessing any file:// URIs or similar.
return null;
}
$timeout = 5;
$file_data = HTTPSFuture::loadContent($uri, $timeout);
if ($file_data === false) {
return null;
}
return self::newFromFileData($file_data, array('name' => $name));
}
public static function normalizeFileName($file_name) {
return preg_replace('/[^a-zA-Z0-9.~_-]/', '_', $file_name);
}
public function delete() {
$engine = $this->instantiateStorageEngine();
$ret = parent::delete();
$engine->deleteFile($this->getStorageHandle());
return $ret;
}
public function loadFileData() {
$engine = $this->instantiateStorageEngine();
$data = $engine->readFile($this->getStorageHandle());
switch ($this->getStorageFormat()) {
case self::STORAGE_FORMAT_RAW:
$data = $data;
break;
default:
throw new Exception("Unknown storage format.");
}
return $data;
}
public function getViewURI() {
if (!$this->getPHID()) {
throw new Exception(
"You must save a file before you can generate a view URI.");
}
$name = phutil_escape_uri($this->getName());
$path = '/file/data/'.$this->getSecretKey().'/'.$this->getPHID().'/'.$name;
return PhabricatorEnv::getCDNURI($path);
}
public function getInfoURI() {
return '/file/info/'.$this->getPHID().'/';
}
public function getBestURI() {
if ($this->isViewableInBrowser()) {
return $this->getViewURI();
} else {
return $this->getInfoURI();
}
}
public function getThumb60x45URI() {
return '/file/xform/thumb-60x45/'.$this->getPHID().'/';
}
public function getThumb160x120URI() {
return '/file/xform/thumb-160x120/'.$this->getPHID().'/';
}
+ public function getPreview220URI() {
+ return '/file/xform/preview-220/'.$this->getPHID().'/';
+ }
+
+ public function getThumb220x165URI() {
+ return '/file/xform/thumb-220x165/'.$this->getPHID().'/';
+ }
public function isViewableInBrowser() {
return ($this->getViewableMimeType() !== null);
}
public function isViewableImage() {
if (!$this->isViewableInBrowser()) {
return false;
}
$mime_map = PhabricatorEnv::getEnvConfig('files.image-mime-types');
$mime_type = $this->getMimeType();
return idx($mime_map, $mime_type);
}
public function isTransformableImage() {
// NOTE: The way the 'gd' extension works in PHP is that you can install it
// with support for only some file types, so it might be able to handle
// PNG but not JPEG. Try to generate thumbnails for whatever we can. Setup
// warns you if you don't have complete support.
$matches = null;
$ok = preg_match(
'@^image/(gif|png|jpe?g)@',
$this->getViewableMimeType(),
$matches);
if (!$ok) {
return false;
}
switch ($matches[1]) {
case 'jpg';
case 'jpeg':
return function_exists('imagejpeg');
break;
case 'png':
return function_exists('imagepng');
break;
case 'gif':
return function_exists('imagegif');
break;
default:
throw new Exception('Unknown type matched as image MIME type.');
}
}
public static function getTransformableImageFormats() {
$supported = array();
if (function_exists('imagejpeg')) {
$supported[] = 'jpg';
}
if (function_exists('imagepng')) {
$supported[] = 'png';
}
if (function_exists('imagegif')) {
$supported[] = 'gif';
}
return $supported;
}
protected function instantiateStorageEngine() {
$engines = id(new PhutilSymbolLoader())
->setType('class')
->setAncestorClass('PhabricatorFileStorageEngine')
->selectAndLoadSymbols();
foreach ($engines as $engine_class) {
$engine = newv($engine_class['name'], array());
if ($engine->getEngineIdentifier() == $this->getStorageEngine()) {
return $engine;
}
}
throw new Exception("File's storage engine could be located!");
}
public function getViewableMimeType() {
$mime_map = PhabricatorEnv::getEnvConfig('files.viewable-mime-types');
$mime_type = $this->getMimeType();
$mime_parts = explode(';', $mime_type);
$mime_type = trim(reset($mime_parts));
return idx($mime_map, $mime_type);
}
public function validateSecretKey($key) {
return ($key == $this->getSecretKey());
}
public function save() {
if (!$this->getSecretKey()) {
$this->setSecretKey($this->generateSecretKey());
}
return parent::save();
}
public function generateSecretKey() {
return Filesystem::readRandomCharacters(20);
}
}
diff --git a/src/applications/macro/controller/PhabricatorMacroListController.php b/src/applications/macro/controller/PhabricatorMacroListController.php
index 09fde89bab..f9ec3b9e6a 100644
--- a/src/applications/macro/controller/PhabricatorMacroListController.php
+++ b/src/applications/macro/controller/PhabricatorMacroListController.php
@@ -1,141 +1,140 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorMacroListController
extends PhabricatorMacroController {
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$macro_table = new PhabricatorFileImageMacro();
$filter = $request->getStr('name');
if (strlen($filter)) {
$macros = $macro_table->loadAllWhere(
'name LIKE %~',
$filter);
$nodata = pht(
'There are no macros matching the filter "%s".',
phutil_escape_html($filter));
} else {
$pager = new AphrontPagerView();
$pager->setOffset($request->getInt('page'));
$macros = $macro_table->loadAllWhere(
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
$pager->getOffset(),
$pager->getPageSize());
// Get an exact count since the size here is reasonably going to be a few
// thousand at most in any reasonable case.
$count = queryfx_one(
$macro_table->establishConnection('r'),
'SELECT COUNT(*) N FROM %T',
$macro_table->getTableName());
$count = $count['N'];
$pager->setCount($count);
$pager->setURI($request->getRequestURI(), 'page');
$nodata = pht('There are no image macros yet.');
}
$file_phids = mpull($macros, 'getFilePHID');
$files = array();
if ($file_phids) {
$files = id(new PhabricatorFile())->loadAllWhere(
"phid IN (%Ls)",
$file_phids);
$author_phids = mpull($files, 'getAuthorPHID', 'getPHID');
$this->loadHandles($author_phids);
}
$files_map = mpull($files, null, 'getPHID');
$filter_form = id(new AphrontFormView())
->setMethod('GET')
->setUser($request->getUser())
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel('Name')
->setValue($filter))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Filter Image Macros'));
$filter_view = new AphrontListFilterView();
$filter_view->appendChild($filter_form);
$nav = $this->buildSideNavView();
$nav->selectFilter('/');
$nav->appendChild($filter_view);
if ($macros) {
$pinboard = new PhabricatorPinboardView();
foreach ($macros as $macro) {
$file_phid = $macro->getFilePHID();
$file = idx($files_map, $file_phid);
$item = new PhabricatorPinboardItemView();
if ($file) {
- $item->setImageURI($file->getThumb160x120URI());
- $item->setImageSize(160, 120);
+ $item->setImageURI($file->getThumb220x165URI());
+ $item->setImageSize(220, 165);
if ($file->getAuthorPHID()) {
$author_handle = $this->getHandle($file->getAuthorPHID());
$item->appendChild(
'Created by '.$author_handle->renderLink());
}
$datetime = phabricator_date($file->getDateCreated(), $viewer);
$item->appendChild(
phutil_render_tag(
'div',
array(),
'Created on '.$datetime));
-
}
$item->setURI($this->getApplicationURI('/edit/'.$macro->getID().'/'));
$item->setHeader($macro->getName());
$pinboard->addItem($item);
}
$nav->appendChild($pinboard);
} else {
$list = new PhabricatorObjectItemListView();
$list->setNoDataString($nodata);
$nav->appendChild($list);
}
if ($filter === null) {
$nav->appendChild($pager);
}
return $this->buildApplicationPage(
$nav,
array(
'device' => true,
'title' => 'Image Macros',
));
}
}
diff --git a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php
index dae861341b..9b3a6e6598 100644
--- a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php
+++ b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php
@@ -1,141 +1,138 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group markup
*/
final class PhabricatorRemarkupRuleEmbedFile
extends PhutilRemarkupRule {
public function apply($text) {
return preg_replace_callback(
"@{F(\d+)([^}]+?)?}@",
array($this, 'markupEmbedFile'),
$text);
}
public function markupEmbedFile($matches) {
$file = null;
if ($matches[1]) {
// TODO: This is pretty inefficient if there are a bunch of files.
$file = id(new PhabricatorFile())->load($matches[1]);
}
if (!$file) {
return $matches[0];
}
$options = array(
'size' => 'thumb',
'layout' => 'left',
'float' => false,
'name' => null,
);
if (!empty($matches[2])) {
$matches[2] = trim($matches[2], ', ');
$options = PhutilSimpleOptions::parse($matches[2]) + $options;
}
$file_name = coalesce($options['name'], $file->getName());
if (!$file->isViewableImage() || $options['layout'] == 'link') {
// If a file isn't in image, just render a link to it.
$link = phutil_render_tag(
'a',
array(
'href' => $file->getBestURI(),
'target' => '_blank',
'class' => 'phabricator-remarkup-embed-layout-link',
),
phutil_escape_html($file_name));
return $this->getEngine()->storeText($link);
}
- $attrs = array(
- 'class' => 'phabricator-remarkup-embed-image',
- );
+ $attrs = array();
switch ($options['size']) {
case 'full':
$attrs['src'] = $file->getBestURI();
$link = null;
break;
case 'thumb':
default:
- $attrs['src'] = $file->getThumb160x120URI();
- $attrs['width'] = 160;
- $attrs['height'] = 120;
+ $attrs['src'] = $file->getPreview220URI();
$link = $file->getBestURI();
break;
}
$embed = phutil_render_tag('img', $attrs);
if ($link) {
$embed = phutil_render_tag(
'a',
array(
- 'href' => $link,
- 'target' => '_blank',
+ 'href' => $link,
+ 'class' => 'phabricator-remarkup-embed-image',
+ 'target' => '_blank',
),
$embed);
}
$layout_class = null;
switch ($options['layout']) {
case 'right':
case 'center':
case 'inline':
case 'left':
$layout_class = 'phabricator-remarkup-embed-layout-'.$options['layout'];
break;
default:
$layout_class = 'phabricator-remarkup-embed-layout-left';
break;
}
if ($options['float']) {
switch ($options['layout']) {
case 'center':
case 'inline':
break;
case 'right':
$layout_class .= ' phabricator-remarkup-embed-float-right';
break;
case 'left':
default:
$layout_class .= ' phabricator-remarkup-embed-float-left';
break;
}
}
if ($layout_class) {
$embed = phutil_render_tag(
'div',
array(
'class' => $layout_class,
),
$embed);
}
return $this->getEngine()->storeText($embed);
}
}
diff --git a/webroot/rsrc/css/core/remarkup.css b/webroot/rsrc/css/core/remarkup.css
index cc4705c726..3973f65b66 100644
--- a/webroot/rsrc/css/core/remarkup.css
+++ b/webroot/rsrc/css/core/remarkup.css
@@ -1,318 +1,314 @@
/**
* @provides phabricator-remarkup-css
*/
.phabricator-remarkup {
line-height: 1.45em;
}
.phabricator-remarkup p {
margin: 0 0 1em;
}
.phabricator-remarkup p:last-child {
margin-bottom: 0;
}
.phabricator-remarkup .remarkup-code-block {
margin: 1em 2em;
white-space: pre;
font-family: "Monaco", monospace;
font-size: 10px;
}
.phabricator-remarkup .remarkup-code-header {
padding: .25em 1em;
background: #edead7;
color: #444444;
}
.phabricator-remarkup .remarkup-code-block pre {
background: #fdfae7;
border: 1px solid #f5e178;
display: block;
color: #000000;
overflow: auto;
padding: .5em 1em;
font-family: "Monaco", monospace;
}
.phabricator-remarkup pre.remarkup-counterexample {
border: 1px solid #aa0000;
background-color: #ffaaaa;
}
.phabricator-remarkup tt {
color: #333333;
background: #ebebeb;
padding: 0 .25em;
white-space: pre-wrap;
}
.phabricator-remarkup ul {
list-style: disc;
margin: 1em 0 1em 3em;
}
.phabricator-remarkup ol {
list-style: decimal;
margin: 1em 0 1em 3em;
}
.phabricator-remarkup ul ol,
.phabricator-remarkup ul ul,
.phabricator-remarkup ol ol,
.phabricator-remarkup ol ul {
margin: .25em 0 .25em 2em;
}
.phabricator-remarkup li.phantom-item,
.phabricator-remarkup li.phantom-item {
list-style-type: none;
}
.phabricator-remarkup h1:first-child,
.phabricator-remarkup h2:first-child,
.phabricator-remarkup h3:first-child,
.phabricator-remarkup h4:first-child,
.phabricator-remarkup h5:first-child,
.phabricator-remarkup h6:first-child {
margin-top: 0;
}
.phabricator-remarkup h1:last-child,
.phabricator-remarkup h2:last-child,
.phabricator-remarkup h3:last-child,
.phabricator-remarkup h4:last-child,
.phabricator-remarkup h5:last-child,
.phabricator-remarkup h6:last-child {
margin-bottom: 0;
}
.phabricator-remarkup h1 {
font-size: 1.625em;
line-height: 1.625em;
margin: .8em 0;
}
.phabricator-remarkup h2 {
font-size: 1.5em;
line-height: 1.5em;
margin: .75em 0;
}
.phabricator-remarkup h3 {
font-size: 1.375em;
line-height: 1.375em;
margin: .69em 0;
}
.phabricator-remarkup h4 {
font-size: 1.25em;
line-height: 1.25em;
margin: .63em 0;
}
.phabricator-remarkup h5 {
font-size: 1.125em;
line-height: 1.125em;
margin: .56em 0;
}
.phabricator-remarkup h6 {
font-size: 1em;
line-height: 1em;
margin: .5em 0;
}
.phabricator-remarkup blockquote {
border-left: 1px solid #AAAAAA;
color: #333333;
font-style: italic;
margin: .5em 0em;
padding: .25em 1em;
}
.phabricator-remarkup img.remarkup-proxy-image {
max-width: 640px;
max-height: 640px;
}
.phabricator-remarkup-mention-exists {
font-weight: bold;
background: #e6f3ff;
}
.phabricator-remarkup-mention-disabled {
font-weight: bold;
background: #dddddd;
}
.aphront-panel-preview .phabricator-remarkup-mention-unknown {
font-weight: bold;
background: #ffaaaa;
}
.phabricator-remarkup .remarkup-note {
margin: 1em 1.5em;
padding: 0.5em 1em;
border: 1px solid #ddddff;
background: #f3f3ff;
}
.phabricator-remarkup-toc {
float: right;
border: 1px solid #999999;
background: #f9f9f9;
padding: 4px 12px;
width: 220px;
}
.phabricator-remarkup-toc-header {
font-size: 11px;
color: #444444;
border-bottom: 1px solid #bbbbbb;
margin-bottom: 4px;
}
.phabricator-remarkup-toc ul {
padding: 0;
margin: 0;
list-style: none;
overflow: hidden;
padding-left: 0.25em;
}
.phabricator-remarkup-toc ul ul {
margin-left: 1.25em;
}
.phabricator-remarkup-toc ul li {
padding: 0;
margin: 0;
}
.phabricator-remarkup-embed-layout-right {
text-align: right;
}
.phabricator-remarkup-embed-layout-center {
text-align: center;
}
.phabricator-remarkup-embed-layout-inline {
display: inline;
}
.phabricator-remarkup-embed-float-right {
float: right;
margin: .5em 1em 0;
}
.phabricator-remarkup-embed-layout-link {
padding-left: 20px;
background: url(/rsrc/image/icon/fatcow/page_white_put.png) 0 0 no-repeat;
}
.phabricator-remarkup-embed-float-left {
float: left;
margin: .5em 1em 0;
}
-img.phabricator-remarkup-embed-image {
- display: inline;
- border: 2px solid white;
- background: white;
-
- box-shadow: 1px 1px 6px rgba(0,0,0,.5);
- -moz-box-shadow: 1px 1px 6px rgba(0,0,0,.5);
- -webkit-box-shadow: 1px 1px 6px rgba(0,0,0,.5);
+.phabricator-remarkup-embed-image {
+ display: inline-block;
+ border: 3px solid white;
+ box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.20);
}
.phabricator-remarkup table.remarkup-table {
border-collapse: separate;
border-spacing: 1px;
background: #d3d3d3;
margin: 1em;
}
.phabricator-remarkup table.remarkup-table th {
font-weight: bold;
padding: 3px 6px;
background: #e3e3e3;
}
.phabricator-remarkup table.remarkup-table td {
background: #ffffff;
padding: 3px 6px;
}
.remarkup-assist-textarea {
border-width: 1px;
border-color: #e5e5e5 #999999 #999999;
/* Prevent Safari and Chrome users from dragging the textarea any wider,
because the top bar won't resize along with it. */
resize: vertical;
}
.remarkup-assist-bar {
height: 27px;
padding: 0 2px;
border-width: 1px 1px 0;
border-style: solid;
border-color: #737373 #999999;
background: #f5f5f5;
overflow: hidden;
}
.remarkup-assist-button {
display: block;
padding: 3px;
margin: 2px 1px;
float: left;
border: 1px solid transparent;
border-radius: 2px;
}
.remarkup-assist-button:hover {
background: #f7f7f7;
border-color: #c6c6c6;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.10);
}
.remarkup-assist-button:active {
outline: none;
background: #f3f3f3;
box-shadow: inset 1px 1px 1px rgba(0, 0, 0, 0.10);
}
.remarkup-assist-button:focus {
outline: none;
}
.remarkup-assist-separator {
display: block;
float: left;
margin: 7px 4px;
height: 14px;
width: 0px;
border-right: 1px solid #cccccc;
}
.remarkup-assist {
display: block;
width: 14px;
height: 14px;
overflow: hidden;
}
.remarkup-assist-right {
float: right;
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Feb 25, 1:29 AM (1 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
851805
Default Alt Text
(37 KB)

Event Timeline