Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/paste/controller/PhabricatorPasteController.php b/src/applications/paste/controller/PhabricatorPasteController.php
index 4063282aa0..da6624078f 100644
--- a/src/applications/paste/controller/PhabricatorPasteController.php
+++ b/src/applications/paste/controller/PhabricatorPasteController.php
@@ -1,42 +1,69 @@
<?php
abstract class PhabricatorPasteController extends PhabricatorController {
public function buildSideNavView($filter = null, $for_app = false) {
$user = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI('filter/')));
if ($for_app) {
$nav->addFilter('', 'Create Paste', $this->getApplicationURI('/create/'));
}
$nav->addLabel('Filters');
$nav->addFilter('all', 'All Pastes');
if ($user->isLoggedIn()) {
$nav->addFilter('my', 'My Pastes');
}
$nav->selectFilter($filter, 'all');
return $nav;
}
public function buildApplicationMenu() {
return $this->buildSideNavView(null, true)->getMenu();
}
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PhabricatorMenuItemView())
->setName(pht('Create Paste'))
->setHref($this->getApplicationURI('create/'))
->setIcon('create'));
return $crumbs;
}
+ public function buildSourceCodeView(
+ PhabricatorPaste $paste,
+ PhabricatorFile $file,
+ $max_lines = null) {
+
+ $language = $paste->getLanguage();
+ $source = $file->loadFileData();
+
+ if (empty($language)) {
+ $source = PhabricatorSyntaxHighlighter::highlightWithFilename(
+ $paste->getTitle(),
+ $source);
+ } else {
+ $source = PhabricatorSyntaxHighlighter::highlightWithLanguage(
+ $language,
+ $source);
+ }
+
+ $lines = explode("\n", $source);
+
+ if ($max_lines) {
+ $lines = array_slice($lines, 0, $max_lines);
+ }
+
+ return id(new PhabricatorSourceCodeView())
+ ->setLines($lines);
+ }
}
diff --git a/src/applications/paste/controller/PhabricatorPasteListController.php b/src/applications/paste/controller/PhabricatorPasteListController.php
index 0d86292a3e..84167245a4 100644
--- a/src/applications/paste/controller/PhabricatorPasteListController.php
+++ b/src/applications/paste/controller/PhabricatorPasteListController.php
@@ -1,96 +1,111 @@
<?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 = new PhabricatorPasteQuery();
$query->setViewer($user);
$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'));
+ $file_phids = mpull($pastes, 'getFilePHID');
+ $files = array();
+ if ($file_phids) {
+ $files = id(new PhabricatorFile())->loadAllWhere(
+ "phid IN (%Ls)",
+ $file_phids);
+ }
+ $files_map = mpull($files, null, 'getPHID');
+
$list = new PhabricatorObjectItemListView();
$list->setViewer($user);
foreach ($pastes as $paste) {
$created = phabricator_date($paste->getDateCreated(), $user);
$author = $this->getHandle($paste->getAuthorPHID())->renderLink();
+ $file_phid = $paste->getFilePHID();
+ $file = idx($files_map, $file_phid);
+
+ $source_code = $this->buildSourceCodeView($paste, $file, 5)->render();
+
$item = id(new PhabricatorObjectItemView())
->setHeader($paste->getFullName())
->setHref('/P'.$paste->getID())
->setObject($paste)
- ->addAttribute(pht('Created %s by %s', $created, $author));
+ ->addAttribute(pht('Created %s by %s', $created, $author))
+ ->appendChild($source_code);
$list->addItem($item);
}
return $list;
}
}
diff --git a/src/applications/paste/controller/PhabricatorPasteViewController.php b/src/applications/paste/controller/PhabricatorPasteViewController.php
index be4083e050..9c9537b1ef 100644
--- a/src/applications/paste/controller/PhabricatorPasteViewController.php
+++ b/src/applications/paste/controller/PhabricatorPasteViewController.php
@@ -1,178 +1,155 @@
<?php
final class PhabricatorPasteViewController extends PhabricatorPasteController {
public function shouldAllowPublic() {
return true;
}
private $id;
private $handles;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$paste = id(new PhabricatorPasteQuery())
->setViewer($user)
->withIDs(array($this->id))
->executeOne();
if (!$paste) {
return new Aphront404Response();
}
$file = id(new PhabricatorFile())->loadOneWhere(
'phid = %s',
$paste->getFilePHID());
if (!$file) {
return new Aphront400Response();
}
$forks = id(new PhabricatorPasteQuery())
->setViewer($user)
->withParentPHIDs(array($paste->getPHID()))
->execute();
$fork_phids = mpull($forks, 'getPHID');
$this->loadHandles(
array_merge(
array(
$paste->getAuthorPHID(),
$paste->getParentPHID(),
),
$fork_phids));
$header = $this->buildHeaderView($paste);
$actions = $this->buildActionView($user, $paste, $file);
$properties = $this->buildPropertyView($paste, $fork_phids);
$source_code = $this->buildSourceCodeView($paste, $file);
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView())
->addCrumb(
id(new PhabricatorCrumbView())
->setName('P'.$paste->getID())
->setHref('/P'.$paste->getID()));
return $this->buildApplicationPage(
array(
$crumbs,
$header,
$actions,
$properties,
$source_code,
),
array(
'title' => $paste->getFullName(),
'device' => true,
));
}
private function buildHeaderView(PhabricatorPaste $paste) {
return id(new PhabricatorHeaderView())
->setObjectName('P'.$paste->getID())
->setHeader($paste->getTitle());
}
private function buildActionView(
PhabricatorUser $user,
PhabricatorPaste $paste,
PhabricatorFile $file) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$user,
$paste,
PhabricatorPolicyCapability::CAN_EDIT);
$can_fork = $user->isLoggedIn();
$fork_uri = $this->getApplicationURI('/create/?parent='.$paste->getID());
return id(new PhabricatorActionListView())
->setUser($user)
->setObject($paste)
->addAction(
id(new PhabricatorActionView())
->setName(pht('Fork This Paste'))
->setIcon('fork')
->setDisabled(!$can_fork)
->setWorkflow(!$can_fork)
->setHref($fork_uri))
->addAction(
id(new PhabricatorActionView())
->setName(pht('View Raw File'))
->setIcon('file')
->setHref($file->getBestURI()))
->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Paste'))
->setIcon('edit')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/')));
}
private function buildPropertyView(
PhabricatorPaste $paste,
array $child_phids) {
$user = $this->getRequest()->getUser();
$properties = new PhabricatorPropertyListView();
$properties->addProperty(
pht('Author'),
$this->getHandle($paste->getAuthorPHID())->renderLink());
$properties->addProperty(
pht('Created'),
phabricator_datetime($paste->getDateCreated(), $user));
if ($paste->getParentPHID()) {
$properties->addProperty(
pht('Forked From'),
$this->getHandle($paste->getParentPHID())->renderLink());
}
if ($child_phids) {
$properties->addProperty(
pht('Forks'),
$this->renderHandlesForPHIDs($child_phids));
}
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
$user,
$paste);
$properties->addProperty(
pht('Visible To'),
$descriptions[PhabricatorPolicyCapability::CAN_VIEW]);
return $properties;
}
- private function buildSourceCodeView(
- PhabricatorPaste $paste,
- PhabricatorFile $file) {
-
- $language = $paste->getLanguage();
- $source = $file->loadFileData();
-
- if (empty($language)) {
- $source = PhabricatorSyntaxHighlighter::highlightWithFilename(
- $paste->getTitle(),
- $source);
- } else {
- $source = PhabricatorSyntaxHighlighter::highlightWithLanguage(
- $language,
- $source);
- }
-
- $lines = explode("\n", $source);
-
- return id(new PhabricatorSourceCodeView())
- ->setLines($lines);
- }
-
}
diff --git a/src/view/layout/PhabricatorObjectItemView.php b/src/view/layout/PhabricatorObjectItemView.php
index 76b768b793..e0d674e4c4 100644
--- a/src/view/layout/PhabricatorObjectItemView.php
+++ b/src/view/layout/PhabricatorObjectItemView.php
@@ -1,150 +1,150 @@
<?php
final class PhabricatorObjectItemView extends AphrontView {
private $header;
private $href;
private $attributes = array();
private $details = array();
private $dates = array();
private $icons = array();
private $barColor;
private $object;
public function setObject($object) {
$this->object = $object;
return $this;
}
public function getObject() {
return $this->object;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function getHref() {
return $this->href;
}
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function getHeader() {
return $this->header;
}
public function addIcon($icon, $label = null) {
$this->icons[] = array(
'icon' => $icon,
'label' => $label,
);
return $this;
}
public function setBarColor($bar_color) {
$this->barColor = $bar_color;
return $this;
}
public function getBarColor() {
return $this->barColor;
}
public function addAttribute($attribute) {
$this->attributes[] = $attribute;
return $this;
}
public function render() {
$header = phutil_render_tag(
'a',
array(
'href' => $this->href,
'class' => 'phabricator-object-item-name',
),
phutil_escape_html($this->header));
$icons = null;
if ($this->icons) {
$icon_list = array();
foreach ($this->icons as $spec) {
$icon = $spec['icon'];
$icon = phutil_render_tag(
'span',
array(
'class' => 'phabricator-object-item-icon-image '.
'sprite-icon action-'.$icon,
),
'');
$label = phutil_render_tag(
'span',
array(
'class' => 'phabricator-object-item-icon-label',
),
phutil_escape_html($spec['label']));
$icon_list[] = phutil_render_tag(
'li',
array(
'class' => 'phabricator-object-item-icon',
),
$label.$icon);
}
$icons = phutil_render_tag(
'ul',
array(
'class' => 'phabricator-object-item-icons',
),
implode('', $icon_list));
}
$attrs = null;
if ($this->attributes) {
$attrs = array();
$spacer = phutil_render_tag(
'span',
array(
'class' => 'phabricator-object-item-attribute-spacer',
),
'&middot;');
$first = true;
foreach ($this->attributes as $attribute) {
$attrs[] = phutil_render_tag(
'li',
array(
'class' => 'phabricator-object-item-attribute',
),
($first ? null : $spacer).$attribute);
$first = false;
}
$attrs = phutil_render_tag(
'ul',
array(
'class' => 'phabricator-object-item-attributes',
),
implode('', $attrs));
}
$classes = array();
$classes[] = 'phabricator-object-item';
if ($this->barColor) {
$classes[] = 'phabricator-object-item-bar-color-'.$this->barColor;
}
return phutil_render_tag(
'div',
array(
'class' => implode(' ', $classes),
),
- $icons.$header.$attrs);
+ $icons.$header.$attrs.$this->renderChildren());
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Mar 17, 12:19 AM (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
963758
Default Alt Text
(14 KB)

Event Timeline