1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 02:02:41 +01:00
phorge-phorge/src/applications/phriction/controller/PhrictionHistoryController.php
vrana 20768d65d5 Convert phutil_render_tag(X, Y, '...') to phutil_tag
Summary:
Created with spatch:

  lang=diff
  - phutil_render_tag
  + phutil_tag
    (X, Y, '...')

Then searched for `&` and `<` in the output and replaced them.

Test Plan: Loaded homepage.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4503
2013-01-24 19:20:27 -08:00

151 lines
3.7 KiB
PHP

<?php
/**
* @group phriction
*/
final class PhrictionHistoryController
extends PhrictionController {
private $slug;
public function willProcessRequest(array $data) {
$this->slug = $data['slug'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$document = id(new PhrictionDocument())->loadOneWhere(
'slug = %s',
PhabricatorSlug::normalize($this->slug));
if (!$document) {
return new Aphront404Response();
}
$current = id(new PhrictionContent())->load($document->getContentID());
$pager = new AphrontPagerView();
$pager->setOffset($request->getInt('page'));
$pager->setURI($request->getRequestURI(), 'page');
$history = id(new PhrictionContent())->loadAllWhere(
'documentID = %d ORDER BY version DESC LIMIT %d, %d',
$document->getID(),
$pager->getOffset(),
$pager->getPageSize() + 1);
$history = $pager->sliceResults($history);
$author_phids = mpull($history, 'getAuthorPHID');
$handles = $this->loadViewerHandles($author_phids);
$rows = array();
foreach ($history as $content) {
$slug_uri = PhrictionDocument::getSlugURI($document->getSlug());
$version = $content->getVersion();
$diff_uri = new PhutilURI('/phriction/diff/'.$document->getID().'/');
$vs_previous = '<em>Created</em>';
if ($content->getVersion() != 1) {
$uri = $diff_uri
->alter('l', $content->getVersion() - 1)
->alter('r', $content->getVersion());
$vs_previous = phutil_tag(
'a',
array(
'href' => $uri,
),
'Show Change');
}
$vs_head = '<em>Current</em>';
if ($content->getID() != $document->getContentID()) {
$uri = $diff_uri
->alter('l', $content->getVersion())
->alter('r', $current->getVersion());
$vs_head = phutil_tag(
'a',
array(
'href' => $uri,
),
'Show Later Changes');
}
$change_type = PhrictionChangeType::getChangeTypeLabel(
$content->getChangeType());
$rows[] = array(
phabricator_date($content->getDateCreated(), $user),
phabricator_time($content->getDateCreated(), $user),
phutil_render_tag(
'a',
array(
'href' => $slug_uri.'?v='.$version,
),
'Version '.$version),
$handles[$content->getAuthorPHID()]->renderLink(),
$change_type,
phutil_escape_html($content->getDescription()),
$vs_previous,
$vs_head,
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
'Date',
'Time',
'Version',
'Author',
'Type',
'Description',
'Against Previous',
'Against Current',
));
$table->setColumnClasses(
array(
'',
'right',
'pri',
'',
'',
'wide',
'',
'',
));
$crumbs = $this->buildApplicationCrumbs();
$crumb_views = $this->renderBreadcrumbs($document->getSlug());
foreach ($crumb_views as $view) {
$crumbs->addCrumb($view);
}
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('History'))
->setHref(
PhrictionDocument::getSlugURI($document->getSlug(), 'history')));
$panel = new AphrontPanelView();
$panel->setHeader('Document History');
$panel->appendChild($table);
$panel->appendChild($pager);
return $this->buildApplicationPage(
array(
$crumbs,
$panel,
),
array(
'title' => 'Document History',
'device' => true,
));
}
}