+ * @throws NotFoundException
+ */
+ public function destroyDraft($bookSlug, $pageId)
+ {
+ $page = $this->entityRepo->getById('page', $pageId, true);
+ $book = $page->book;
+ $this->checkOwnablePermission('page-update', $page);
+ session()->flash('success', trans('entities.pages_delete_draft_success'));
+ $this->entityRepo->destroyPage($page);
+ return redirect($book->getUrl());
+ }
+
+ /**
+ * Shows the last revisions for this page.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return \Illuminate\View\View
+ */
+ public function showRevisions($bookSlug, $pageSlug)
+ {
+ $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
+ $this->setPageTitle(trans('entities.pages_revisions_named', ['pageName'=>$page->getShortName()]));
+ return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]);
+ }
+
+ /**
+ * Shows a preview of a single revision
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @param int $revisionId
+ * @return \Illuminate\View\View
+ */
+ public function showRevision($bookSlug, $pageSlug, $revisionId)
+ {
+ $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
+ $revision = $page->revisions()->where('id', '=', $revisionId)->first();
+ if ($revision === null) {
+ abort(404);
+ }
+
+ $page->fill($revision->toArray());
+ $this->setPageTitle(trans('entities.pages_revision_named', ['pageName' => $page->getShortName()]));
+
+ return view('pages/revision', [
+ 'page' => $page,
+ 'book' => $page->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)
+ {
+ $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
+ $revision = $page->revisions()->where('id', '=', $revisionId)->first();
+ if ($revision === null) {
+ abort(404);
+ }
+
+ $prev = $revision->getPrevious();
+ $prevContent = ($prev === null) ? '' : $prev->html;
+ $diff = (new Htmldiff)->diff($prevContent, $revision->html);
+
+ $page->fill($revision->toArray());
+ $this->setPageTitle(trans('entities.pages_revision_named', ['pageName'=>$page->getShortName()]));
+
+ return view('pages/revision', [
+ 'page' => $page,
+ 'book' => $page->book,
+ 'diff' => $diff,
+ ]);
+ }
+
+ /**
+ * Restores a page using the content of the specified revision.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @param int $revisionId
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function restoreRevision($bookSlug, $pageSlug, $revisionId)
+ {
+ $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
+ $this->checkOwnablePermission('page-update', $page);
+ $page = $this->entityRepo->restorePageRevision($page, $page->book, $revisionId);
+ Activity::add($page, 'page_restore', $page->book->id);
+ return redirect($page->getUrl());
+ }
+
+ /**
+ * Exports a page to a PDF.
+ * https://github.com/barryvdh/laravel-dompdf
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return \Illuminate\Http\Response
+ */
+ public function exportPdf($bookSlug, $pageSlug)
+ {
+ $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
+ $pdfContent = $this->exportService->pageToPdf($page);
+ return response()->make($pdfContent, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="' . $pageSlug . '.pdf'
+ ]);
+ }
+
+ /**
+ * Export a page to a self-contained HTML file.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return \Illuminate\Http\Response
+ */
+ public function exportHtml($bookSlug, $pageSlug)
+ {
+ $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
+ $containedHtml = $this->exportService->pageToContainedHtml($page);
+ return response()->make($containedHtml, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="' . $pageSlug . '.html'
+ ]);
+ }
+
+ /**
+ * Export a page to a simple plaintext .txt file.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return \Illuminate\Http\Response
+ */
+ public function exportPlainText($bookSlug, $pageSlug)
+ {
+ $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
+ $containedHtml = $this->exportService->pageToPlainText($page);
+ return response()->make($containedHtml, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="' . $pageSlug . '.txt'
+ ]);
+ }
+
+ /**
+ * Show a listing of recently created pages
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View