[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/view/ -> DiffusionView.php (source)

   1  <?php
   2  
   3  abstract class DiffusionView extends AphrontView {
   4  
   5    private $diffusionRequest;
   6  
   7    final public function setDiffusionRequest(DiffusionRequest $request) {
   8      $this->diffusionRequest = $request;
   9      return $this;
  10    }
  11  
  12    final public function getDiffusionRequest() {
  13      return $this->diffusionRequest;
  14    }
  15  
  16    final public function linkChange($change_type, $file_type, $path = null,
  17                                     $commit_identifier = null) {
  18  
  19      $text = DifferentialChangeType::getFullNameForChangeType($change_type);
  20      if ($change_type == DifferentialChangeType::TYPE_CHILD) {
  21        // TODO: Don't link COPY_AWAY without a direct change.
  22        return $text;
  23      }
  24      if ($file_type == DifferentialChangeType::FILE_DIRECTORY) {
  25        return $text;
  26      }
  27  
  28      $href = $this->getDiffusionRequest()->generateURI(
  29        array(
  30          'action'  => 'change',
  31          'path'    => $path,
  32          'commit'  => $commit_identifier,
  33        ));
  34  
  35      return phutil_tag(
  36        'a',
  37        array(
  38          'href' => $href,
  39        ),
  40        $text);
  41    }
  42  
  43    final public function linkHistory($path) {
  44      $href = $this->getDiffusionRequest()->generateURI(
  45        array(
  46          'action' => 'history',
  47          'path'   => $path,
  48        ));
  49  
  50      return phutil_tag(
  51        'a',
  52        array(
  53          'href' => $href,
  54        ),
  55        pht('History'));
  56    }
  57  
  58    final public function linkBrowse($path, array $details = array()) {
  59  
  60      $href = $this->getDiffusionRequest()->generateURI(
  61        $details + array(
  62          'action' => 'browse',
  63          'path'   => $path,
  64        ));
  65  
  66      if (isset($details['text'])) {
  67        $text = $details['text'];
  68      } else {
  69        $text = pht('Browse');
  70      }
  71  
  72      return phutil_tag(
  73        'a',
  74        array(
  75          'href' => $href,
  76        ),
  77        $text);
  78    }
  79  
  80    final public function linkExternal($hash, $uri, $text) {
  81      $href = id(new PhutilURI('/diffusion/external/'))
  82        ->setQueryParams(
  83          array(
  84            'uri' => $uri,
  85            'id'  => $hash,
  86          ));
  87  
  88      return phutil_tag(
  89        'a',
  90        array(
  91          'href' => $href,
  92        ),
  93        $text);
  94    }
  95  
  96    final public static function nameCommit(
  97      PhabricatorRepository $repository,
  98      $commit) {
  99  
 100      switch ($repository->getVersionControlSystem()) {
 101        case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
 102        case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
 103          $commit_name = substr($commit, 0, 12);
 104          break;
 105        default:
 106          $commit_name = $commit;
 107          break;
 108      }
 109  
 110      $callsign = $repository->getCallsign();
 111      return "r{$callsign}{$commit_name}";
 112    }
 113  
 114    final public static function linkCommit(
 115      PhabricatorRepository $repository,
 116      $commit,
 117      $summary = '') {
 118  
 119      $commit_name = self::nameCommit($repository, $commit);
 120      $callsign = $repository->getCallsign();
 121  
 122      if (strlen($summary)) {
 123        $commit_name .= ': '.$summary;
 124      }
 125  
 126      return phutil_tag(
 127        'a',
 128        array(
 129          'href' => "/r{$callsign}{$commit}",
 130        ),
 131        $commit_name);
 132    }
 133  
 134    final public static function linkRevision($id) {
 135      if (!$id) {
 136        return null;
 137      }
 138  
 139      return phutil_tag(
 140        'a',
 141        array(
 142          'href' => "/D{$id}",
 143        ),
 144        "D{$id}");
 145    }
 146  
 147    final public static function renderName($name) {
 148      $email = new PhutilEmailAddress($name);
 149      if ($email->getDisplayName() && $email->getDomainName()) {
 150        Javelin::initBehavior('phabricator-tooltips', array());
 151        require_celerity_resource('aphront-tooltip-css');
 152        return javelin_tag(
 153          'span',
 154          array(
 155            'sigil' => 'has-tooltip',
 156            'meta'  => array(
 157              'tip'   => $email->getAddress(),
 158              'align' => 'E',
 159              'size'  => 'auto',
 160            ),
 161          ),
 162          $email->getDisplayName());
 163      }
 164      return hsprintf('%s', $name);
 165    }
 166  
 167  }


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