[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionBrowseController.php (source)

   1  <?php
   2  
   3  abstract class DiffusionBrowseController extends DiffusionController {
   4  
   5    public function shouldAllowPublic() {
   6      return true;
   7    }
   8  
   9    protected function renderSearchForm($collapsed) {
  10      $drequest = $this->getDiffusionRequest();
  11  
  12      $forms = array();
  13      $form = id(new AphrontFormView())
  14        ->setUser($this->getRequest()->getUser())
  15        ->setMethod('GET');
  16  
  17      switch ($drequest->getRepository()->getVersionControlSystem()) {
  18        case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
  19          $forms[] = id(clone $form)
  20            ->appendChild(pht('Search is not available in Subversion.'));
  21          break;
  22        default:
  23          $forms[] = id(clone $form)
  24            ->appendChild(
  25              id(new AphrontFormTextWithSubmitControl())
  26                ->setLabel(pht('File Name'))
  27                ->setSubmitLabel(pht('Search File Names'))
  28                ->setName('find')
  29                ->setValue($this->getRequest()->getStr('find')));
  30          $forms[] = id(clone $form)
  31            ->appendChild(
  32              id(new AphrontFormTextWithSubmitControl())
  33                ->setLabel(pht('Pattern'))
  34                ->setSubmitLabel(pht('Grep File Content'))
  35                ->setName('grep')
  36                ->setValue($this->getRequest()->getStr('grep')));
  37          break;
  38      }
  39  
  40      $filter = new AphrontListFilterView();
  41      $filter->appendChild($forms);
  42  
  43      if ($collapsed) {
  44        $filter->setCollapsed(
  45          pht('Show Search'),
  46          pht('Hide Search'),
  47          pht('Search for file names or content in this directory.'),
  48          '#');
  49      }
  50  
  51      return $filter;
  52    }
  53  
  54    protected function markupText($text) {
  55      $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
  56      $engine->setConfig('viewer', $this->getRequest()->getUser());
  57      $text = $engine->markupText($text);
  58  
  59      $text = phutil_tag(
  60        'div',
  61        array(
  62          'class' => 'phabricator-remarkup',
  63        ),
  64        $text);
  65  
  66      return $text;
  67    }
  68  
  69    protected function buildHeaderView(DiffusionRequest $drequest) {
  70      $viewer = $this->getRequest()->getUser();
  71  
  72      $header = id(new PHUIHeaderView())
  73        ->setUser($viewer)
  74        ->setHeader($this->renderPathLinks($drequest, $mode = 'browse'))
  75        ->setPolicyObject($drequest->getRepository());
  76  
  77      return $header;
  78    }
  79  
  80    protected function buildActionView(DiffusionRequest $drequest) {
  81      $viewer = $this->getRequest()->getUser();
  82  
  83      $view = id(new PhabricatorActionListView())
  84        ->setUser($viewer);
  85  
  86      $history_uri = $drequest->generateURI(
  87        array(
  88          'action' => 'history',
  89        ));
  90  
  91      $view->addAction(
  92        id(new PhabricatorActionView())
  93          ->setName(pht('View History'))
  94          ->setHref($history_uri)
  95          ->setIcon('fa-list'));
  96  
  97      $behind_head = $drequest->getSymbolicCommit();
  98      $head_uri = $drequest->generateURI(
  99        array(
 100          'commit' => '',
 101          'action' => 'browse',
 102        ));
 103      $view->addAction(
 104        id(new PhabricatorActionView())
 105          ->setName(pht('Jump to HEAD'))
 106          ->setHref($head_uri)
 107          ->setIcon('fa-home')
 108          ->setDisabled(!$behind_head));
 109  
 110      // TODO: Ideally, this should live in Owners and be event-triggered, but
 111      // there's no reasonable object for it to react to right now.
 112  
 113      $owners = 'PhabricatorOwnersApplication';
 114      if (PhabricatorApplication::isClassInstalled($owners)) {
 115        $owners_uri = id(new PhutilURI('/owners/view/search/'))
 116          ->setQueryParams(
 117            array(
 118              'repository' => $drequest->getCallsign(),
 119              'path' => '/'.$drequest->getPath(),
 120            ));
 121  
 122        $view->addAction(
 123          id(new PhabricatorActionView())
 124            ->setName(pht('Find Owners'))
 125            ->setHref((string)$owners_uri)
 126            ->setIcon('fa-users'));
 127      }
 128  
 129      return $view;
 130    }
 131  
 132    protected function buildPropertyView(
 133      DiffusionRequest $drequest,
 134      PhabricatorActionListView $actions) {
 135  
 136      $viewer = $this->getRequest()->getUser();
 137  
 138      $view = id(new PHUIPropertyListView())
 139        ->setUser($viewer)
 140        ->setActionList($actions);
 141  
 142      $stable_commit = $drequest->getStableCommit();
 143      $callsign = $drequest->getRepository()->getCallsign();
 144  
 145      $view->addProperty(
 146        pht('Commit'),
 147        phutil_tag(
 148          'a',
 149          array(
 150            'href' => $drequest->generateURI(
 151              array(
 152                'action' => 'commit',
 153                'commit' => $stable_commit,
 154              )),
 155          ),
 156          $drequest->getRepository()->formatCommitName($stable_commit)));
 157  
 158      if ($drequest->getSymbolicType() == 'tag') {
 159        $symbolic = $drequest->getSymbolicCommit();
 160        $view->addProperty(pht('Tag'), $symbolic);
 161  
 162        $tags = $this->callConduitWithDiffusionRequest(
 163          'diffusion.tagsquery',
 164          array(
 165            'names' => array($symbolic),
 166            'needMessages' => true,
 167          ));
 168        $tags = DiffusionRepositoryTag::newFromConduit($tags);
 169  
 170        $tags = mpull($tags, null, 'getName');
 171        $tag = idx($tags, $symbolic);
 172  
 173        if ($tag && strlen($tag->getMessage())) {
 174          $view->addSectionHeader(pht('Tag Content'));
 175          $view->addTextContent($this->markupText($tag->getMessage()));
 176        }
 177      }
 178  
 179      return $view;
 180    }
 181  
 182    protected function buildOpenRevisions() {
 183      $user = $this->getRequest()->getUser();
 184  
 185      $drequest = $this->getDiffusionRequest();
 186      $repository = $drequest->getRepository();
 187      $path = $drequest->getPath();
 188  
 189      $path_map = id(new DiffusionPathIDQuery(array($path)))->loadPathIDs();
 190      $path_id = idx($path_map, $path);
 191      if (!$path_id) {
 192        return null;
 193      }
 194  
 195      $revisions = id(new DifferentialRevisionQuery())
 196        ->setViewer($user)
 197        ->withPath($repository->getID(), $path_id)
 198        ->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
 199        ->setOrder(DifferentialRevisionQuery::ORDER_PATH_MODIFIED)
 200        ->setLimit(10)
 201        ->needRelationships(true)
 202        ->needFlags(true)
 203        ->needDrafts(true)
 204        ->execute();
 205  
 206      if (!$revisions) {
 207        return null;
 208      }
 209  
 210      $view = id(new DifferentialRevisionListView())
 211        ->setRevisions($revisions)
 212        ->setUser($user);
 213  
 214      $phids = $view->getRequiredHandlePHIDs();
 215      $handles = $this->loadViewerHandles($phids);
 216      $view->setHandles($handles);
 217  
 218      return id(new PHUIObjectBoxView())
 219        ->setHeaderText(pht('Pending Differential Revisions'))
 220        ->appendChild($view);
 221    }
 222  
 223  }


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