diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 6081d1b27..033377a4d 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -336,13 +336,36 @@ class PageController extends Controller $book = $this->bookRepo->getBySlug($bookSlug); $page = $this->pageRepo->getBySlug($pageSlug, $book->id); $revision = $this->pageRepo->getRevisionById($revisionId); - - $next = $revision->getNext() ?: $page; - $diff = (new Htmldiff)->diff($revision->html, $next->html); $page->fill($revision->toArray()); $this->setPageTitle('Page Revision For ' . $page->getShortName()); + return view('pages/revision', [ + 'page' => $page, + 'book' => $book, + ]); + } + + /** + * Shows the changes of a single revision + * @param string $bookSlug + * @param string $pageSlug + * @param int $revisionId + * @return \Illuminate\View\View + */ + public function showRevisionChanges($bookSlug, $pageSlug, $revisionId) + { + $book = $this->bookRepo->getBySlug($bookSlug); + $page = $this->pageRepo->getBySlug($pageSlug, $book->id); + $revision = $this->pageRepo->getRevisionById($revisionId); + + $prev = $revision->getPrevious(); + $prevContent = ($prev === null) ? '' : $prev->html; + $diff = (new Htmldiff)->diff($prevContent, $revision->html); + + $page->fill($revision->toArray()); + $this->setPageTitle('Page Revision For ' . $page->getShortName()); + return view('pages/revision', [ 'page' => $page, 'book' => $book, diff --git a/app/PageRevision.php b/app/PageRevision.php index e5721f5aa..ff469f0ed 100644 --- a/app/PageRevision.php +++ b/app/PageRevision.php @@ -25,32 +25,26 @@ class PageRevision extends Model /** * Get the url for this revision. + * @param null|string $path * @return string */ - public function getUrl() + public function getUrl($path = null) { - return $this->page->getUrl() . '/revisions/' . $this->id; + $url = $this->page->getUrl() . '/revisions/' . $this->id; + if ($path) return $url . '/' . trim($path, '/'); + return $url; } /** - * Get previous revision - * @return \BookStack\PageRevision + * Get the previous revision for the same page if existing + * @return \BookStack\PageRevision|null */ public function getPrevious() { - if ($id = PageRevision::where('id', '<', $this->id)->max('id')) { - return PageRevision::find($id); + if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) { + return static::find($id); } + return null; } - /** - * Get next revision - * @return \BookStack\PageRevision - */ - public function getNext() - { - if ($id = PageRevision::where('id', '>', $this->id)->min('id')) { - return PageRevision::find($id); - } - } } diff --git a/app/Repos/PageRepo.php b/app/Repos/PageRepo.php index c64da1267..93ff61b62 100644 --- a/app/Repos/PageRepo.php +++ b/app/Repos/PageRepo.php @@ -548,7 +548,7 @@ class PageRepo extends EntityRepo /** * Gets a single revision via it's id. * @param $id - * @return mixed + * @return PageRevision */ public function getRevisionById($id) { diff --git a/resources/views/pages/revisions.blade.php b/resources/views/pages/revisions.blade.php index 926affffc..720e34fea 100644 --- a/resources/views/pages/revisions.blade.php +++ b/resources/views/pages/revisions.blade.php @@ -32,11 +32,11 @@
Name | -Created By | +Name | +Created By | Revision Date | Changelog | -Actions | +Actions | ||
---|---|---|---|---|---|---|---|---|---|
@if($revision->createdBy) {{ $revision->createdBy->name }} @else Deleted User @endif | {{ $revision->created_at->format('jS F, Y H:i:s') }} ({{ $revision->created_at->diffForHumans() }}) |
{{ $revision->summary }} | - @if ($index !== 0) -+ | + Changes + | + + @if ($index === 0) + Current Version + @else Preview | - Restore - | - @else -Current Version | - @endif + Restore + @endif +