<?php namespace BookStack\Http\Controllers;
-use Activity;
-use BookStack\Entities\Managers\BookContents;
-use BookStack\Entities\Managers\PageContent;
-use BookStack\Entities\Managers\PageEditActivity;
-use BookStack\Entities\Page;
+use BookStack\Actions\View;
+use BookStack\Entities\Tools\BookContents;
+use BookStack\Entities\Tools\NextPreviousContentLocator;
+use BookStack\Entities\Tools\PageContent;
+use BookStack\Entities\Tools\PageEditActivity;
+use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\PageRepo;
+use BookStack\Entities\Tools\PermissionsUpdater;
use BookStack\Exceptions\NotFoundException;
-use BookStack\Exceptions\NotifyException;
use BookStack\Exceptions\PermissionsException;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Throwable;
-use Views;
class PageController extends Controller
{
public function __construct(PageRepo $pageRepo)
{
$this->pageRepo = $pageRepo;
- parent::__construct();
}
/**
$this->checkOwnablePermission('page-create', $draftPage->getParent());
$page = $this->pageRepo->publishDraft($draftPage, $request->all());
- Activity::add($page, 'page_create', $draftPage->book->id);
return redirect($page->getUrl());
}
$page->load(['comments.createdBy']);
}
- Views::add($page);
+ $nextPreviousLocator = new NextPreviousContentLocator($page, $sidebarTree);
+
+ View::incrementFor($page);
$this->setPageTitle($page->getShortName());
return view('pages.show', [
'page' => $page,
'current' => $page,
'sidebarTree' => $sidebarTree,
'commentsEnabled' => $commentsEnabled,
- 'pageNav' => $pageNav
+ 'pageNav' => $pageNav,
+ 'next' => $nextPreviousLocator->getNext(),
+ 'previous' => $nextPreviousLocator->getPrevious(),
]);
}
$this->checkOwnablePermission('page-update', $page);
$this->pageRepo->update($page, $request->all());
- Activity::add($page, 'page_update', $page->book->id);
return redirect($page->getUrl());
}
$updateTime = $draft->updated_at->timestamp;
return response()->json([
- 'status' => 'success',
- 'message' => trans('entities.pages_edit_draft_save_at'),
+ 'status' => 'success',
+ 'message' => trans('entities.pages_edit_draft_save_at'),
'timestamp' => $updateTime
]);
}
{
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-delete', $page);
- $this->setPageTitle(trans('entities.pages_delete_named', ['pageName'=>$page->getShortName()]));
+ $this->setPageTitle(trans('entities.pages_delete_named', ['pageName' => $page->getShortName()]));
return view('pages.delete', [
'book' => $page->book,
'page' => $page,
{
$page = $this->pageRepo->getById($pageId);
$this->checkOwnablePermission('page-update', $page);
- $this->setPageTitle(trans('entities.pages_delete_draft_named', ['pageName'=>$page->getShortName()]));
+ $this->setPageTitle(trans('entities.pages_delete_draft_named', ['pageName' => $page->getShortName()]));
return view('pages.delete', [
'book' => $page->book,
'page' => $page,
* Remove the specified page from storage.
* @throws NotFoundException
* @throws Throwable
- * @throws NotifyException
*/
public function destroy(string $bookSlug, string $pageSlug)
{
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-delete', $page);
+ $parent = $page->getParent();
- $book = $page->book;
- $parent = $page->chapter ?? $book;
$this->pageRepo->destroy($page);
- Activity::addMessage('page_delete', $page->name, $book->id);
- $this->showSuccessNotification(trans('entities.pages_delete_success'));
return redirect($parent->getUrl());
}
/**
* Remove the specified draft page from storage.
* @throws NotFoundException
- * @throws NotifyException
* @throws Throwable
*/
public function destroyDraft(string $bookSlug, int $pageId)
->paginate(20)
->setPath(url('/pages/recently-updated'));
- return view('pages.detailed-listing', [
+ return view('common.detailed-listing-paginated', [
'title' => trans('entities.recently_updated_pages'),
- 'pages' => $pages
+ 'entities' => $pages
]);
}
try {
$parent = $this->pageRepo->move($page, $entitySelection);
} catch (Exception $exception) {
- if ($exception instanceof PermissionsException) {
+ if ($exception instanceof PermissionsException) {
$this->showPermissionError();
}
return redirect()->back();
}
- Activity::add($page, 'page_move', $page->book->id);
$this->showSuccessNotification(trans('entities.pages_move_success', ['parentName' => $parent->name]));
return redirect($page->getUrl());
}
try {
$pageCopy = $this->pageRepo->copy($page, $entitySelection, $newName);
} catch (Exception $exception) {
- if ($exception instanceof PermissionsException) {
+ if ($exception instanceof PermissionsException) {
$this->showPermissionError();
}
return redirect()->back();
}
- Activity::add($pageCopy, 'page_create', $pageCopy->book->id);
-
$this->showSuccessNotification(trans('entities.pages_copy_success'));
return redirect($pageCopy->getUrl());
}
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('restrictions-manage', $page);
return view('pages.permissions', [
- 'page' => $page,
+ 'page' => $page,
]);
}
* @throws NotFoundException
* @throws Throwable
*/
- public function permissions(Request $request, string $bookSlug, string $pageSlug)
+ public function permissions(Request $request, PermissionsUpdater $permissionsUpdater, string $bookSlug, string $pageSlug)
{
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('restrictions-manage', $page);
- $restricted = $request->get('restricted') === 'true';
- $permissions = $request->filled('restrictions') ? collect($request->get('restrictions')) : null;
- $this->pageRepo->updatePermissions($page, $restricted, $permissions);
+ $permissionsUpdater->updateFromPermissionsForm($page, $request);
$this->showSuccessNotification(trans('entities.pages_permissions_success'));
return redirect($page->getUrl());