1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

Very basic Phriction history view

Summary: Provide a (mostly useless, currently) table of document edits.
Test Plan: Looked at document history for several of my high-quality sandbox
wiki pages.
Reviewed By: hsb
Reviewers: hsb, codeblock, jungejason, aran, tuomaspelkonen
CC: aran, hsb
Differential Revision: 644
This commit is contained in:
epriestley 2011-07-11 15:06:19 -07:00
parent 5704b2bc70
commit 7c21068c9f
8 changed files with 167 additions and 6 deletions

View file

@ -27,7 +27,7 @@ celerity_register_resource_map(array(
),
'aphront-dark-console-css' =>
array(
'uri' => '/res/a7d1dbf1/rsrc/css/aphront/dark-console.css',
'uri' => '/res/1a9f84bb/rsrc/css/aphront/dark-console.css',
'type' => 'css',
'requires' =>
array(
@ -1137,7 +1137,7 @@ celerity_register_resource_map(array(
),
'phriction-document-css' =>
array(
'uri' => '/res/b682cd2e/rsrc/css/application/phriction/phriction-document-css.css',
'uri' => '/res/e764414a/rsrc/css/application/phriction/phriction-document-css.css',
'type' => 'css',
'requires' =>
array(

View file

@ -585,6 +585,7 @@ phutil_register_library_map(array(
'PhrictionDocument' => 'applications/phriction/storage/document',
'PhrictionDocumentController' => 'applications/phriction/controller/document',
'PhrictionEditController' => 'applications/phriction/controller/edit',
'PhrictionHistoryController' => 'applications/phriction/controller/history',
),
'function' =>
array(
@ -1080,6 +1081,7 @@ phutil_register_library_map(array(
'PhrictionDocument' => 'PhrictionDAO',
'PhrictionDocumentController' => 'PhrictionController',
'PhrictionEditController' => 'PhrictionController',
'PhrictionHistoryController' => 'PhrictionController',
),
'requires_interface' =>
array(

View file

@ -347,6 +347,9 @@ class AphrontDefaultApplicationConfiguration
'/w/(?P<slug>.+/)$' => 'PhrictionDocumentController',
'/phriction/' => array(
'history(?P<slug>/)$' => 'PhrictionHistoryController',
'history/(?P<slug>.+/)$' => 'PhrictionHistoryController',
'edit/(?:(?P<id>\d+)/)?$' => 'PhrictionEditController',
),
);

View file

@ -27,6 +27,24 @@ abstract class PhrictionController extends PhabricatorController {
$page->setTitle(idx($data, 'title'));
$page->setGlyph("\xE2\x9A\xA1");
$tabs = array();
if (!empty($data['document'])) {
$tabs['document'] = array(
'name' => 'Document',
'href' => $data['document'],
);
}
if (!empty($data['history'])) {
$tabs['history'] = array(
'name' => 'History',
'href' => $data['history'],
);
}
if (!empty($tabs)) {
$page->setTabs($tabs, idx($data, 'tab'));
}
$page->appendChild($view);
$response = new AphrontWebpageResponse();

View file

@ -73,7 +73,8 @@ class PhrictionDocumentController
return $this->buildStandardPageResponse(
$page,
array(
'title' => 'Phriction - '.$page_title,
'title' => 'Phriction - '.$page_title,
'history' => PhrictionDocument::getSlugURI($slug, 'history'),
));
}

View file

@ -0,0 +1,103 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* 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.
*/
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',
PhrictionDocument::normalizeSlug($this->slug));
if (!$document) {
return new Aphront404Response();
}
$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());
$rows[] = array(
phabricator_date($content->getDateCreated(), $user),
phabricator_time($content->getDateCreated(), $user),
(int)$content->getVersion(),
$handles[$content->getAuthorPHID()]->renderLink(),
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
'Date',
'Time',
'Version',
'Author',
));
$table->setColumnClasses(
array(
'',
'right',
'',
'wide',
));
$panel = new AphrontPanelView();
$panel->setHeader('Document History');
$panel->appendChild($table);
$panel->appendChild($pager);
$slug = $document->getSlug();
return $this->buildStandardPageResponse(
$panel,
array(
'title' => 'Document History',
'history' => PhrictionDocument::getSlugURI($slug, 'history'),
'document' => PhrictionDocument::getSlugURI($slug),
'tab' => 'history',
));
}
}

View file

@ -0,0 +1,22 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'applications/phriction/controller/base');
phutil_require_module('phabricator', 'applications/phriction/storage/content');
phutil_require_module('phabricator', 'applications/phriction/storage/document');
phutil_require_module('phabricator', 'view/control/pager');
phutil_require_module('phabricator', 'view/control/table');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhrictionHistoryController.php');

View file

@ -36,14 +36,26 @@ class PhrictionDocument extends PhrictionDAO {
PhabricatorPHIDConstants::PHID_TYPE_WIKI);
}
public static function getSlugURI($slug) {
public static function getSlugURI($slug, $type = 'document') {
static $types = array(
'document' => '/w/',
'history' => '/phriction/history/',
);
if (empty($types[$type])) {
throw new Exception("Unknown URI type '{$type}'!");
}
$prefix = $types[$type];
if ($slug == '/') {
return '/w/';
return $prefix;
} else {
return '/w/'.$slug;
return $prefix.$slug;
}
}
public static function normalizeSlug($slug) {
// TODO: We need to deal with unicode at some point, this is just a very