~ubuntu-branches/ubuntu/wily/phabricator/wily

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

final class PhragmentHistoryController extends PhragmentController {

  private $dblob;

  public function shouldAllowPublic() {
    return true;
  }

  public function willProcessRequest(array $data) {
    $this->dblob = idx($data, 'dblob', '');
  }

  public function processRequest() {
    $request = $this->getRequest();
    $viewer = $request->getUser();

    $parents = $this->loadParentFragments($this->dblob);
    if ($parents === null) {
      return new Aphront404Response();
    }
    $current = idx($parents, count($parents) - 1, null);

    $path = $current->getPath();

    $crumbs = $this->buildApplicationCrumbsWithPath($parents);
    if ($this->hasApplicationCapability(
      PhragmentCanCreateCapability::CAPABILITY)) {
      $crumbs->addAction(
        id(new PHUIListItemView())
          ->setName(pht('Create Fragment'))
          ->setHref($this->getApplicationURI('/create/'.$path))
          ->setIcon('fa-plus-square'));
    }

    $current_box = $this->createCurrentFragmentView($current, true);

    $versions = id(new PhragmentFragmentVersionQuery())
      ->setViewer($viewer)
      ->withFragmentPHIDs(array($current->getPHID()))
      ->execute();

    $list = id(new PHUIObjectItemListView())
      ->setUser($viewer);

    $file_phids = mpull($versions, 'getFilePHID');
    $files = id(new PhabricatorFileQuery())
      ->setViewer($viewer)
      ->withPHIDs($file_phids)
      ->execute();
    $files = mpull($files, null, 'getPHID');

    $can_edit = PhabricatorPolicyFilter::hasCapability(
      $viewer,
      $current,
      PhabricatorPolicyCapability::CAN_EDIT);

    $first = true;
    foreach ($versions as $version) {
      $item = id(new PHUIObjectItemView());
      $item->setHeader(pht('Version %s', $version->getSequence()));
      $item->setHref($version->getURI());
      $item->addAttribute(phabricator_datetime(
        $version->getDateCreated(),
        $viewer));

      if ($version->getFilePHID() === null) {
        $item->setDisabled(true);
        $item->addAttribute(pht('Deletion'));
      }

      if (!$first && $can_edit) {
        $item->addAction(id(new PHUIListItemView())
          ->setIcon('fa-refresh')
          ->setRenderNameAsTooltip(true)
          ->setWorkflow(true)
          ->setName(pht('Revert to Here'))
          ->setHref($this->getApplicationURI(
            'revert/'.$version->getID().'/'.$current->getPath())));
      }

      $disabled = !isset($files[$version->getFilePHID()]);
      $action = id(new PHUIListItemView())
        ->setIcon('fa-download')
        ->setDisabled($disabled || !$this->isCorrectlyConfigured())
        ->setRenderNameAsTooltip(true)
        ->setName(pht('Download'));
      if (!$disabled && $this->isCorrectlyConfigured()) {
        $action->setHref($files[$version->getFilePHID()]
          ->getDownloadURI($version->getURI()));
      }
      $item->addAction($action);

      $list->addItem($item);

      $first = false;
    }

    return $this->buildApplicationPage(
      array(
        $crumbs,
        $this->renderConfigurationWarningIfRequired(),
        $current_box,
        $list,
      ),
      array(
        'title' => pht('Fragment History'),
      ));
  }

}