[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/files/controller/ -> PhabricatorFileInfoController.php (source)

   1  <?php
   2  
   3  final class PhabricatorFileInfoController extends PhabricatorFileController {
   4  
   5    private $phid;
   6    private $id;
   7  
   8    public function shouldAllowPublic() {
   9      return true;
  10    }
  11  
  12    public function willProcessRequest(array $data) {
  13      $this->phid = idx($data, 'phid');
  14      $this->id = idx($data, 'id');
  15    }
  16  
  17    public function processRequest() {
  18      $request = $this->getRequest();
  19      $user = $request->getUser();
  20  
  21      if ($this->phid) {
  22        $file = id(new PhabricatorFileQuery())
  23          ->setViewer($user)
  24          ->withPHIDs(array($this->phid))
  25          ->executeOne();
  26  
  27        if (!$file) {
  28          return new Aphront404Response();
  29        }
  30        return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
  31      }
  32      $file = id(new PhabricatorFileQuery())
  33        ->setViewer($user)
  34        ->withIDs(array($this->id))
  35        ->executeOne();
  36      if (!$file) {
  37        return new Aphront404Response();
  38      }
  39  
  40      $phid = $file->getPHID();
  41      $xactions = id(new PhabricatorFileTransactionQuery())
  42        ->setViewer($user)
  43        ->withObjectPHIDs(array($phid))
  44        ->execute();
  45  
  46      $handle_phids = array_merge(
  47        array($file->getAuthorPHID()),
  48        $file->getObjectPHIDs());
  49  
  50      $this->loadHandles($handle_phids);
  51      $header = id(new PHUIHeaderView())
  52        ->setUser($user)
  53        ->setPolicyObject($file)
  54        ->setHeader($file->getName());
  55  
  56      $ttl = $file->getTTL();
  57      if ($ttl !== null) {
  58        $ttl_tag = id(new PHUITagView())
  59          ->setType(PHUITagView::TYPE_OBJECT)
  60          ->setName(pht('Temporary'));
  61        $header->addTag($ttl_tag);
  62      }
  63  
  64      $actions = $this->buildActionView($file);
  65      $timeline = $this->buildTransactionView($file, $xactions);
  66      $crumbs = $this->buildApplicationCrumbs();
  67      $crumbs->setActionList($actions);
  68      $crumbs->addTextCrumb(
  69        'F'.$file->getID(),
  70        $this->getApplicationURI("/info/{$phid}/"));
  71  
  72      $object_box = id(new PHUIObjectBoxView())
  73        ->setHeader($header);
  74  
  75      $this->buildPropertyViews($object_box, $file, $actions);
  76  
  77      return $this->buildApplicationPage(
  78        array(
  79          $crumbs,
  80          $object_box,
  81          $timeline,
  82        ),
  83        array(
  84          'title' => $file->getName(),
  85          'pageObjects' => array($file->getPHID()),
  86        ));
  87    }
  88  
  89    private function buildTransactionView(
  90      PhabricatorFile $file,
  91      array $xactions) {
  92  
  93      $user = $this->getRequest()->getUser();
  94      $engine = id(new PhabricatorMarkupEngine())
  95        ->setViewer($user);
  96      foreach ($xactions as $xaction) {
  97        if ($xaction->getComment()) {
  98          $engine->addObject(
  99            $xaction->getComment(),
 100            PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
 101        }
 102      }
 103      $engine->process();
 104  
 105      $timeline = id(new PhabricatorApplicationTransactionView())
 106        ->setUser($user)
 107        ->setObjectPHID($file->getPHID())
 108        ->setTransactions($xactions)
 109        ->setMarkupEngine($engine);
 110  
 111      $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
 112  
 113      $add_comment_header = $is_serious
 114        ? pht('Add Comment')
 115        : pht('Question File Integrity');
 116  
 117      $draft = PhabricatorDraft::newFromUserAndKey($user, $file->getPHID());
 118  
 119      $add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
 120        ->setUser($user)
 121        ->setObjectPHID($file->getPHID())
 122        ->setDraft($draft)
 123        ->setHeaderText($add_comment_header)
 124        ->setAction($this->getApplicationURI('/comment/'.$file->getID().'/'))
 125        ->setSubmitButtonName(pht('Add Comment'));
 126  
 127      return array(
 128        $timeline,
 129        $add_comment_form,
 130      );
 131    }
 132  
 133    private function buildActionView(PhabricatorFile $file) {
 134      $request = $this->getRequest();
 135      $viewer = $request->getUser();
 136  
 137      $id = $file->getID();
 138  
 139      $can_edit = PhabricatorPolicyFilter::hasCapability(
 140        $viewer,
 141        $file,
 142        PhabricatorPolicyCapability::CAN_EDIT);
 143  
 144      $view = id(new PhabricatorActionListView())
 145        ->setUser($viewer)
 146        ->setObjectURI($this->getRequest()->getRequestURI())
 147        ->setObject($file);
 148  
 149      if ($file->isViewableInBrowser()) {
 150        $view->addAction(
 151          id(new PhabricatorActionView())
 152            ->setName(pht('View File'))
 153            ->setIcon('fa-file-o')
 154            ->setHref($file->getViewURI()));
 155      } else {
 156        $view->addAction(
 157          id(new PhabricatorActionView())
 158            ->setUser($viewer)
 159            ->setRenderAsForm(true)
 160            ->setDownload(true)
 161            ->setName(pht('Download File'))
 162            ->setIcon('fa-download')
 163            ->setHref($file->getViewURI()));
 164      }
 165  
 166      $view->addAction(
 167        id(new PhabricatorActionView())
 168          ->setName(pht('Edit File'))
 169          ->setIcon('fa-pencil')
 170          ->setHref($this->getApplicationURI("/edit/{$id}/"))
 171          ->setWorkflow(!$can_edit)
 172          ->setDisabled(!$can_edit));
 173  
 174      $view->addAction(
 175        id(new PhabricatorActionView())
 176          ->setName(pht('Delete File'))
 177          ->setIcon('fa-times')
 178          ->setHref($this->getApplicationURI("/delete/{$id}/"))
 179          ->setWorkflow(true)
 180          ->setDisabled(!$can_edit));
 181  
 182      return $view;
 183    }
 184  
 185    private function buildPropertyViews(
 186      PHUIObjectBoxView $box,
 187      PhabricatorFile $file,
 188      PhabricatorActionListView $actions) {
 189      $request = $this->getRequest();
 190      $user = $request->getUser();
 191  
 192  
 193      $properties = id(new PHUIPropertyListView());
 194      $properties->setActionList($actions);
 195      $box->addPropertyList($properties, pht('Details'));
 196  
 197      if ($file->getAuthorPHID()) {
 198        $properties->addProperty(
 199          pht('Author'),
 200          $this->getHandle($file->getAuthorPHID())->renderLink());
 201      }
 202  
 203      $properties->addProperty(
 204        pht('Created'),
 205        phabricator_datetime($file->getDateCreated(), $user));
 206  
 207  
 208      $finfo = id(new PHUIPropertyListView());
 209      $box->addPropertyList($finfo, pht('File Info'));
 210  
 211      $finfo->addProperty(
 212        pht('Size'),
 213        phutil_format_bytes($file->getByteSize()));
 214  
 215      $finfo->addProperty(
 216        pht('Mime Type'),
 217        $file->getMimeType());
 218  
 219      $width = $file->getImageWidth();
 220      if ($width) {
 221        $finfo->addProperty(
 222          pht('Width'),
 223          pht('%s px', new PhutilNumber($width)));
 224      }
 225  
 226      $height = $file->getImageHeight();
 227      if ($height) {
 228        $finfo->addProperty(
 229          pht('Height'),
 230          pht('%s px', new PhutilNumber($height)));
 231      }
 232  
 233      $is_image = $file->isViewableImage();
 234      if ($is_image) {
 235        $image_string = pht('Yes');
 236        $cache_string = $file->getCanCDN() ? pht('Yes') : pht('No');
 237      } else {
 238        $image_string = pht('No');
 239        $cache_string = pht('Not Applicable');
 240      }
 241  
 242      $finfo->addProperty(pht('Viewable Image'), $image_string);
 243      $finfo->addProperty(pht('Cacheable'), $cache_string);
 244  
 245      $storage_properties = new PHUIPropertyListView();
 246      $box->addPropertyList($storage_properties, pht('Storage'));
 247  
 248      $storage_properties->addProperty(
 249        pht('Engine'),
 250        $file->getStorageEngine());
 251  
 252      $storage_properties->addProperty(
 253        pht('Format'),
 254        $file->getStorageFormat());
 255  
 256      $storage_properties->addProperty(
 257        pht('Handle'),
 258        $file->getStorageHandle());
 259  
 260  
 261      $phids = $file->getObjectPHIDs();
 262      if ($phids) {
 263        $attached = new PHUIPropertyListView();
 264        $box->addPropertyList($attached, pht('Attached'));
 265  
 266        $attached->addProperty(
 267          pht('Attached To'),
 268          $this->renderHandlesForPHIDs($phids));
 269      }
 270  
 271  
 272      if ($file->isViewableImage()) {
 273        $image = phutil_tag(
 274          'img',
 275          array(
 276            'src' => $file->getViewURI(),
 277            'class' => 'phui-property-list-image',
 278          ));
 279  
 280        $linked_image = phutil_tag(
 281          'a',
 282          array(
 283            'href' => $file->getViewURI(),
 284          ),
 285          $image);
 286  
 287        $media = id(new PHUIPropertyListView())
 288          ->addImageContent($linked_image);
 289  
 290        $box->addPropertyList($media);
 291      } else if ($file->isAudio()) {
 292        $audio = phutil_tag(
 293          'audio',
 294          array(
 295            'controls' => 'controls',
 296            'class' => 'phui-property-list-audio',
 297          ),
 298          phutil_tag(
 299            'source',
 300            array(
 301              'src' => $file->getViewURI(),
 302              'type' => $file->getMimeType(),
 303            )));
 304        $media = id(new PHUIPropertyListView())
 305          ->addImageContent($audio);
 306  
 307        $box->addPropertyList($media);
 308      }
 309    }
 310  
 311  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1