[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * group paste 5 */ 6 final class PhabricatorPasteViewController extends PhabricatorPasteController { 7 8 private $id; 9 private $highlightMap; 10 11 public function shouldAllowPublic() { 12 return true; 13 } 14 15 public function willProcessRequest(array $data) { 16 $this->id = $data['id']; 17 $raw_lines = idx($data, 'lines'); 18 $map = array(); 19 if ($raw_lines) { 20 $lines = explode('-', $raw_lines); 21 $first = idx($lines, 0, 0); 22 $last = idx($lines, 1); 23 if ($last) { 24 $min = min($first, $last); 25 $max = max($first, $last); 26 $map = array_fuse(range($min, $max)); 27 } else { 28 $map[$first] = $first; 29 } 30 } 31 $this->highlightMap = $map; 32 } 33 34 public function processRequest() { 35 $request = $this->getRequest(); 36 $user = $request->getUser(); 37 38 $paste = id(new PhabricatorPasteQuery()) 39 ->setViewer($user) 40 ->withIDs(array($this->id)) 41 ->needContent(true) 42 ->executeOne(); 43 if (!$paste) { 44 return new Aphront404Response(); 45 } 46 47 $file = id(new PhabricatorFileQuery()) 48 ->setViewer($user) 49 ->withPHIDs(array($paste->getFilePHID())) 50 ->executeOne(); 51 if (!$file) { 52 return new Aphront400Response(); 53 } 54 55 $forks = id(new PhabricatorPasteQuery()) 56 ->setViewer($user) 57 ->withParentPHIDs(array($paste->getPHID())) 58 ->execute(); 59 $fork_phids = mpull($forks, 'getPHID'); 60 61 $this->loadHandles( 62 array_merge( 63 array( 64 $paste->getAuthorPHID(), 65 $paste->getParentPHID(), 66 ), 67 $fork_phids)); 68 69 $header = $this->buildHeaderView($paste); 70 $actions = $this->buildActionView($user, $paste, $file); 71 $properties = $this->buildPropertyView($paste, $fork_phids, $actions); 72 73 $object_box = id(new PHUIObjectBoxView()) 74 ->setHeader($header) 75 ->addPropertyList($properties); 76 77 $source_code = $this->buildSourceCodeView( 78 $paste, 79 null, 80 $this->highlightMap); 81 82 $source_code = id(new PHUIBoxView()) 83 ->appendChild($source_code) 84 ->setBorder(true) 85 ->addMargin(PHUI::MARGIN_LARGE_LEFT) 86 ->addMargin(PHUI::MARGIN_LARGE_RIGHT) 87 ->addMargin(PHUI::MARGIN_LARGE_TOP); 88 89 $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView()) 90 ->setActionList($actions) 91 ->addTextCrumb('P'.$paste->getID(), '/P'.$paste->getID()); 92 93 $xactions = id(new PhabricatorPasteTransactionQuery()) 94 ->setViewer($request->getUser()) 95 ->withObjectPHIDs(array($paste->getPHID())) 96 ->execute(); 97 98 $engine = id(new PhabricatorMarkupEngine()) 99 ->setViewer($user); 100 foreach ($xactions as $xaction) { 101 if ($xaction->getComment()) { 102 $engine->addObject( 103 $xaction->getComment(), 104 PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); 105 } 106 } 107 $engine->process(); 108 109 $timeline = id(new PhabricatorApplicationTransactionView()) 110 ->setUser($user) 111 ->setObjectPHID($paste->getPHID()) 112 ->setTransactions($xactions) 113 ->setMarkupEngine($engine); 114 115 $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 116 117 $add_comment_header = $is_serious 118 ? pht('Add Comment') 119 : pht('Eat Paste'); 120 121 $draft = PhabricatorDraft::newFromUserAndKey($user, $paste->getPHID()); 122 123 $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) 124 ->setUser($user) 125 ->setObjectPHID($paste->getPHID()) 126 ->setDraft($draft) 127 ->setHeaderText($add_comment_header) 128 ->setAction($this->getApplicationURI('/comment/'.$paste->getID().'/')) 129 ->setSubmitButtonName(pht('Add Comment')); 130 131 return $this->buildApplicationPage( 132 array( 133 $crumbs, 134 $object_box, 135 $source_code, 136 $timeline, 137 $add_comment_form, 138 ), 139 array( 140 'title' => $paste->getFullName(), 141 'pageObjects' => array($paste->getPHID()), 142 )); 143 } 144 145 private function buildHeaderView(PhabricatorPaste $paste) { 146 $title = (nonempty($paste->getTitle())) ? 147 $paste->getTitle() : pht('(An Untitled Masterwork)'); 148 $header = id(new PHUIHeaderView()) 149 ->setHeader($title) 150 ->setUser($this->getRequest()->getUser()) 151 ->setPolicyObject($paste); 152 153 return $header; 154 } 155 156 private function buildActionView( 157 PhabricatorUser $user, 158 PhabricatorPaste $paste, 159 PhabricatorFile $file) { 160 161 $can_edit = PhabricatorPolicyFilter::hasCapability( 162 $user, 163 $paste, 164 PhabricatorPolicyCapability::CAN_EDIT); 165 166 $can_fork = $user->isLoggedIn(); 167 $fork_uri = $this->getApplicationURI('/create/?parent='.$paste->getID()); 168 169 return id(new PhabricatorActionListView()) 170 ->setUser($user) 171 ->setObject($paste) 172 ->setObjectURI($this->getRequest()->getRequestURI()) 173 ->addAction( 174 id(new PhabricatorActionView()) 175 ->setName(pht('Edit Paste')) 176 ->setIcon('fa-pencil') 177 ->setDisabled(!$can_edit) 178 ->setWorkflow(!$can_edit) 179 ->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/'))) 180 ->addAction( 181 id(new PhabricatorActionView()) 182 ->setName(pht('Fork This Paste')) 183 ->setIcon('fa-code-fork') 184 ->setDisabled(!$can_fork) 185 ->setWorkflow(!$can_fork) 186 ->setHref($fork_uri)) 187 ->addAction( 188 id(new PhabricatorActionView()) 189 ->setName(pht('View Raw File')) 190 ->setIcon('fa-file-text-o') 191 ->setHref($file->getBestURI())); 192 } 193 194 private function buildPropertyView( 195 PhabricatorPaste $paste, 196 array $child_phids, 197 PhabricatorActionListView $actions) { 198 199 $user = $this->getRequest()->getUser(); 200 $properties = id(new PHUIPropertyListView()) 201 ->setUser($user) 202 ->setObject($paste) 203 ->setActionList($actions); 204 205 $properties->addProperty( 206 pht('Author'), 207 $this->getHandle($paste->getAuthorPHID())->renderLink()); 208 209 $properties->addProperty( 210 pht('Created'), 211 phabricator_datetime($paste->getDateCreated(), $user)); 212 213 if ($paste->getParentPHID()) { 214 $properties->addProperty( 215 pht('Forked From'), 216 $this->getHandle($paste->getParentPHID())->renderLink()); 217 } 218 219 if ($child_phids) { 220 $properties->addProperty( 221 pht('Forks'), 222 $this->renderHandlesForPHIDs($child_phids)); 223 } 224 225 $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 226 $user, 227 $paste); 228 229 return $properties; 230 } 231 232 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |