[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhrictionHistoryController 4 extends PhrictionController { 5 6 private $slug; 7 8 public function shouldAllowPublic() { 9 return true; 10 } 11 12 public function willProcessRequest(array $data) { 13 $this->slug = $data['slug']; 14 } 15 16 public function processRequest() { 17 18 $request = $this->getRequest(); 19 $user = $request->getUser(); 20 21 $document = id(new PhrictionDocumentQuery()) 22 ->setViewer($user) 23 ->withSlugs(array(PhabricatorSlug::normalize($this->slug))) 24 ->needContent(true) 25 ->executeOne(); 26 if (!$document) { 27 return new Aphront404Response(); 28 } 29 30 $current = $document->getContent(); 31 32 $pager = new AphrontPagerView(); 33 $pager->setOffset($request->getInt('page')); 34 $pager->setURI($request->getRequestURI(), 'page'); 35 36 $history = id(new PhrictionContent())->loadAllWhere( 37 'documentID = %d ORDER BY version DESC LIMIT %d, %d', 38 $document->getID(), 39 $pager->getOffset(), 40 $pager->getPageSize() + 1); 41 $history = $pager->sliceResults($history); 42 43 $author_phids = mpull($history, 'getAuthorPHID'); 44 $handles = $this->loadViewerHandles($author_phids); 45 46 $list = new PHUIObjectItemListView(); 47 $list->setFlush(true); 48 49 foreach ($history as $content) { 50 51 $author = $handles[$content->getAuthorPHID()]->renderLink(); 52 $slug_uri = PhrictionDocument::getSlugURI($document->getSlug()); 53 $version = $content->getVersion(); 54 55 $diff_uri = new PhutilURI('/phriction/diff/'.$document->getID().'/'); 56 57 $vs_previous = null; 58 if ($content->getVersion() != 1) { 59 $vs_previous = $diff_uri 60 ->alter('l', $content->getVersion() - 1) 61 ->alter('r', $content->getVersion()); 62 } 63 64 $vs_head = null; 65 if ($content->getID() != $document->getContentID()) { 66 $vs_head = $diff_uri 67 ->alter('l', $content->getVersion()) 68 ->alter('r', $current->getVersion()); 69 } 70 71 $change_type = PhrictionChangeType::getChangeTypeLabel( 72 $content->getChangeType()); 73 switch ($content->getChangeType()) { 74 case PhrictionChangeType::CHANGE_DELETE: 75 $color = 'red'; 76 break; 77 case PhrictionChangeType::CHANGE_EDIT: 78 $color = 'blue'; 79 break; 80 case PhrictionChangeType::CHANGE_MOVE_HERE: 81 $color = 'yellow'; 82 break; 83 case PhrictionChangeType::CHANGE_MOVE_AWAY: 84 $color = 'orange'; 85 break; 86 case PhrictionChangeType::CHANGE_STUB: 87 $color = 'green'; 88 break; 89 default: 90 throw new Exception('Unknown change type!'); 91 break; 92 } 93 94 $item = id(new PHUIObjectItemView()) 95 ->setHeader(pht('%s by %s', $change_type, $author)) 96 ->setBarColor($color) 97 ->addAttribute( 98 phutil_tag( 99 'a', 100 array( 101 'href' => $slug_uri.'?v='.$version, 102 ), 103 pht('Version %s', $version))) 104 ->addAttribute(pht('%s %s', 105 phabricator_date($content->getDateCreated(), $user), 106 phabricator_time($content->getDateCreated(), $user))); 107 108 if ($content->getDescription()) { 109 $item->addAttribute($content->getDescription()); 110 } 111 112 if ($vs_previous) { 113 $item->addIcon( 114 'fa-reply', 115 pht('Show Change'), 116 array( 117 'href' => $vs_previous, 118 )); 119 } else { 120 $item->addIcon( 121 'fa-reply grey', 122 phutil_tag('em', array(), pht('No previous change'))); 123 } 124 125 if ($vs_head) { 126 $item->addIcon( 127 'fa-reply-all', 128 pht('Show Later Changes'), 129 array( 130 'href' => $vs_head, 131 )); 132 } else { 133 $item->addIcon( 134 'fa-reply-all grey', 135 phutil_tag('em', array(), pht('No later changes'))); 136 } 137 138 $list->addItem($item); 139 } 140 141 $crumbs = $this->buildApplicationCrumbs(); 142 $crumb_views = $this->renderBreadcrumbs($document->getSlug()); 143 foreach ($crumb_views as $view) { 144 $crumbs->addCrumb($view); 145 } 146 $crumbs->addTextCrumb( 147 pht('History'), 148 PhrictionDocument::getSlugURI($document->getSlug(), 'history')); 149 150 $header = new PHUIHeaderView(); 151 $header->setHeader(pht('Document History for %s', 152 phutil_tag( 153 'a', 154 array('href' => PhrictionDocument::getSlugURI($document->getSlug())), 155 head($history)->getTitle()))); 156 157 $obj_box = id(new PHUIObjectBoxView()) 158 ->setHeader($header) 159 ->appendChild($list) 160 ->appendChild($pager); 161 162 return $this->buildApplicationPage( 163 array( 164 $crumbs, 165 $obj_box, 166 ), 167 array( 168 'title' => pht('Document History'), 169 )); 170 171 } 172 173 }
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 |