1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00
phorge-phorge/src/applications/files/controller/PhabricatorFileInfoController.php

162 lines
4.5 KiB
PHP
Raw Normal View History

2011-01-23 03:33:00 +01:00
<?php
final class PhabricatorFileInfoController extends PhabricatorFileController {
2011-01-23 03:33:00 +01:00
private $phid;
public function willProcessRequest(array $data) {
$this->phid = $data['phid'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
2011-01-23 03:33:00 +01:00
$file = id(new PhabricatorFile())->loadOneWhere(
'phid = %s',
$this->phid);
if (!$file) {
return new Aphront404Response();
}
$author_child = null;
if ($file->getAuthorPHID()) {
$author = id(new PhabricatorUser())->loadOneWhere(
'phid = %s',
$file->getAuthorPHID());
if ($author) {
$author_child = id(new AphrontFormStaticControl())
->setLabel('Author')
->setName('author')
->setValue($author->getUserName());
}
}
2011-01-23 03:33:00 +01:00
$form = new AphrontFormView();
$submit = new AphrontFormSubmitControl();
$form->setAction($file->getViewURI());
if ($file->isViewableInBrowser()) {
$submit->setValue('View File');
} else {
$submit->setValue('Download File');
}
if (($user->getPHID() == $file->getAuthorPHID()) ||
($user->getIsAdmin())) {
$submit->addCancelButton(
'/file/delete/'.$file->getID().'/',
'Delete File');
}
$file_id = 'F'.$file->getID();
$form->setUser($user);
2011-01-23 03:33:00 +01:00
$form
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Name')
->setName('name')
->setValue($file->getName()))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('ID')
->setName('id')
->setValue($file_id)
->setCaption(
'Download this file with: <tt>arc download '.
phutil_escape_html($file_id).'</tt>'))
2011-01-23 03:33:00 +01:00
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('PHID')
->setName('phid')
->setValue($file->getPHID()))
->appendChild($author_child)
2011-01-23 03:33:00 +01:00
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Created')
->setName('created')
->setValue(phabricator_datetime($file->getDateCreated(), $user)))
2011-01-23 03:33:00 +01:00
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Mime Type')
->setName('mime')
->setValue($file->getMimeType()))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Size')
->setName('size')
->setValue($file->getByteSize().' bytes'))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Engine')
->setName('storageEngine')
->setValue($file->getStorageEngine()))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Format')
->setName('storageFormat')
->setValue($file->getStorageFormat()))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel('Handle')
->setName('storageHandle')
->setValue($file->getStorageHandle()))
->appendChild(
id($submit));
2011-01-23 03:33:00 +01:00
$panel = new AphrontPanelView();
$panel->setHeader('File Info - '.$file->getName());
$panel->appendChild($form);
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
$xform_panel = null;
$transformations = id(new PhabricatorTransformedFile())->loadAllWhere(
'originalPHID = %s',
$file->getPHID());
if ($transformations) {
$transformed_phids = mpull($transformations, 'getTransformedPHID');
$transformed_files = id(new PhabricatorFile())->loadAllWhere(
'phid in (%Ls)',
$transformed_phids);
$transformed_map = mpull($transformed_files, null, 'getPHID');
$rows = array();
foreach ($transformations as $transformed) {
$phid = $transformed->getTransformedPHID();
$rows[] = array(
phutil_escape_html($transformed->getTransform()),
phutil_render_tag(
'a',
array(
'href' => $transformed_map[$phid]->getBestURI(),
),
$phid));
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
'Transform',
'File',
));
$xform_panel = new AphrontPanelView();
$xform_panel->appendChild($table);
$xform_panel->setWidth(AphrontPanelView::WIDTH_FORM);
$xform_panel->setHeader('Transformations');
}
2011-01-23 03:33:00 +01:00
return $this->buildStandardPageResponse(
array($panel, $xform_panel),
2011-01-23 03:33:00 +01:00
array(
'title' => 'File Info - '.$file->getName(),
));
}
}