forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorPasteListController.php
123 lines (95 loc) · 3.18 KB
/
PhabricatorPasteListController.php
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
113
114
115
116
117
118
119
120
121
122
123
<?php
final class PhabricatorPasteListController extends PhabricatorPasteController {
public function shouldRequireLogin() {
return false;
}
private $filter;
public function willProcessRequest(array $data) {
$this->filter = idx($data, 'filter');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$query = id(new PhabricatorPasteQuery())
->setViewer($user)
->needContent(true);
$nav = $this->buildSideNavView($this->filter);
$filter = $nav->getSelectedFilter();
switch ($filter) {
case 'my':
$query->withAuthorPHIDs(array($user->getPHID()));
$title = pht('My Pastes');
$nodata = pht("You haven't created any Pastes yet.");
break;
case 'all':
$title = pht('All Pastes');
$nodata = pht("There are no Pastes yet.");
break;
}
$pager = new AphrontCursorPagerView();
$pager->readFromRequest($request);
$pastes = $query->executeWithCursorPager($pager);
$list = $this->buildPasteList($pastes);
$list->setPager($pager);
$list->setNoDataString($nodata);
$header = id(new PhabricatorHeaderView())
->setHeader($title);
$nav->appendChild(
array(
$header,
$list,
));
$crumbs = $this
->buildApplicationCrumbs($nav)
->addCrumb(
id(new PhabricatorCrumbView())
->setName($title)
->setHref($this->getApplicationURI('filter/'.$filter.'/')));
$nav->setCrumbs($crumbs);
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
'device' => true,
));
}
private function buildPasteList(array $pastes) {
assert_instances_of($pastes, 'PhabricatorPaste');
$user = $this->getRequest()->getUser();
$this->loadHandles(mpull($pastes, 'getAuthorPHID'));
$lang_map = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
$list = new PhabricatorObjectItemListView();
$list->setUser($user);
foreach ($pastes as $paste) {
$created = phabricator_date($paste->getDateCreated(), $user);
$author = $this->getHandle($paste->getAuthorPHID())->renderLink();
$source_code = $this->buildSourceCodeView($paste, 5)->render();
$source_code = phutil_tag(
'div',
array(
'class' => 'phabricator-source-code-summary',
),
$source_code);
$line_count = count(explode("\n", $paste->getContent()));
$line_count = pht(
'%s Line(s)',
new PhutilNumber($line_count));
$title = nonempty($paste->getTitle(), pht('(An Untitled Masterwork)'));
$item = id(new PhabricatorObjectItemView())
->setObjectName('P'.$paste->getID())
->setHeader($title)
->setHref('/P'.$paste->getID())
->setObject($paste)
->addAttribute(pht('Created %s by %s', $created, $author))
->addIcon('none', $line_count)
->appendChild($source_code);
$lang_name = $paste->getLanguage();
if ($lang_name) {
$lang_name = idx($lang_map, $lang_name, $lang_name);
$item->addIcon('none', $lang_name);
}
$list->addItem($item);
}
return $list;
}
}