2011-07-11 15:06:19 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-09 15:46:25 -08:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-07-11 15:06:19 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-09-14 08:02:31 -07:00
|
|
|
/**
|
|
|
|
* @group phriction
|
|
|
|
*/
|
2012-03-09 15:46:25 -08:00
|
|
|
final class PhrictionHistoryController
|
2011-07-11 15:06:19 -07:00
|
|
|
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',
|
2012-04-10 14:18:20 -07:00
|
|
|
PhabricatorSlug::normalize($this->slug));
|
2011-07-11 15:06:19 -07:00
|
|
|
|
|
|
|
if (!$document) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2011-07-17 11:06:02 -07:00
|
|
|
$current = id(new PhrictionContent())->load($document->getContentID());
|
|
|
|
|
2011-07-11 15:06:19 -07:00
|
|
|
$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 = id(new PhabricatorObjectHandleData($author_phids))
|
|
|
|
->loadHandles();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($history as $content) {
|
|
|
|
|
|
|
|
$uri = PhrictionDocument::getSlugURI($document->getSlug());
|
2011-07-12 18:03:20 -07:00
|
|
|
$version = $content->getVersion();
|
2011-07-11 15:06:19 -07:00
|
|
|
|
2011-07-17 11:06:02 -07:00
|
|
|
$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_render_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_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $uri,
|
|
|
|
),
|
|
|
|
'Show Later Changes');
|
|
|
|
}
|
|
|
|
|
2011-12-17 09:19:08 -08:00
|
|
|
$change_type = PhrictionChangeType::getChangeTypeLabel(
|
|
|
|
$content->getChangeType());
|
|
|
|
|
2011-07-11 15:06:19 -07:00
|
|
|
$rows[] = array(
|
|
|
|
phabricator_date($content->getDateCreated(), $user),
|
|
|
|
phabricator_time($content->getDateCreated(), $user),
|
2011-07-12 18:03:20 -07:00
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $uri.'?v='.$version,
|
|
|
|
),
|
|
|
|
'Version '.$version),
|
2011-07-11 15:06:19 -07:00
|
|
|
$handles[$content->getAuthorPHID()]->renderLink(),
|
2011-12-17 09:19:08 -08:00
|
|
|
$change_type,
|
2011-07-21 15:32:54 -07:00
|
|
|
phutil_escape_html($content->getDescription()),
|
2011-07-17 11:06:02 -07:00
|
|
|
$vs_previous,
|
|
|
|
$vs_head,
|
2011-07-11 15:06:19 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-12-15 12:00:17 -08:00
|
|
|
$crumbs = new AphrontCrumbsView();
|
|
|
|
$crumbs->setCrumbs(
|
|
|
|
array(
|
|
|
|
'Phriction',
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => PhrictionDocument::getSlugURI($document->getSlug()),
|
|
|
|
),
|
|
|
|
phutil_escape_html($current->getTitle())
|
|
|
|
),
|
|
|
|
'History',
|
|
|
|
));
|
|
|
|
|
|
|
|
|
2011-07-11 15:06:19 -07:00
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Date',
|
|
|
|
'Time',
|
|
|
|
'Version',
|
|
|
|
'Author',
|
2011-12-17 09:19:08 -08:00
|
|
|
'Type',
|
2011-07-17 11:06:02 -07:00
|
|
|
'Description',
|
|
|
|
'Against Previous',
|
|
|
|
'Against Current',
|
2011-07-11 15:06:19 -07:00
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'',
|
|
|
|
'right',
|
2011-07-17 11:06:02 -07:00
|
|
|
'pri',
|
2011-07-11 15:06:19 -07:00
|
|
|
'',
|
2011-12-17 09:19:08 -08:00
|
|
|
'',
|
2011-07-11 15:06:19 -07:00
|
|
|
'wide',
|
2011-07-17 11:06:02 -07:00
|
|
|
'',
|
|
|
|
'',
|
2011-07-11 15:06:19 -07:00
|
|
|
));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Document History');
|
|
|
|
$panel->appendChild($table);
|
|
|
|
$panel->appendChild($pager);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
2011-12-15 12:00:17 -08:00
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$panel,
|
|
|
|
),
|
2011-07-11 15:06:19 -07:00
|
|
|
array(
|
|
|
|
'title' => 'Document History',
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|