From c29892c87573e0575b9a4a13210c562e08411148 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 11 Aug 2009 22:48:35 -0400 Subject: [PATCH] Return a 404 when a page is request that has no notices --- actions/all.php | 30 ++++++++++++++++++-------- actions/public.php | 2 +- actions/replies.php | 13 ++++++++---- actions/showfavorites.php | 44 +++++++++++++++++++++------------------ actions/tag.php | 13 +++++++++--- 5 files changed, 65 insertions(+), 37 deletions(-) diff --git a/actions/all.php b/actions/all.php index 5db09a0e61..38aee65b64 100644 --- a/actions/all.php +++ b/actions/all.php @@ -25,11 +25,31 @@ require_once INSTALLDIR.'/lib/feedlist.php'; class AllAction extends ProfileAction { + var $notice; + function isReadOnly($args) { return true; } + function prepare($args) + { + parent::prepare($args); + $cur = common_current_user(); + + if (!empty($cur) && $cur->id == $this->user->id) { + $this->notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + } else { + $this->notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + } + + if($this->page > 1 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + + return true; + } + function handle($args) { parent::handle($args); @@ -100,15 +120,7 @@ class AllAction extends ProfileAction function showContent() { - $cur = common_current_user(); - - if (!empty($cur) && $cur->id == $this->user->id) { - $notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); - } else { - $notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); - } - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); diff --git a/actions/public.php b/actions/public.php index ca352faf85..2cf2e96e68 100644 --- a/actions/public.php +++ b/actions/public.php @@ -93,7 +93,7 @@ class PublicAction extends Action return; } - if($this->page > 0 && $this->notice->N == 0){ + if($this->page > 1 && $this->notice->N == 0){ $this->serverError(_('No such page'),$code=404); } diff --git a/actions/replies.php b/actions/replies.php index f14383d33b..fcfc3a2725 100644 --- a/actions/replies.php +++ b/actions/replies.php @@ -48,6 +48,7 @@ require_once INSTALLDIR.'/lib/feedlist.php'; class RepliesAction extends OwnerDesignAction { var $page = null; + var $notice; /** * Prepare the object @@ -84,6 +85,13 @@ class RepliesAction extends OwnerDesignAction common_set_returnto($this->selfUrl()); + $this->notice = $this->user->getReplies(($this->page-1) * NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1); + + if($this->page > 1 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + return true; } @@ -159,10 +167,7 @@ class RepliesAction extends OwnerDesignAction function showContent() { - $notice = $this->user->getReplies(($this->page-1) * NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1); - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); if (0 === $cnt) { diff --git a/actions/showfavorites.php b/actions/showfavorites.php index 9f549baf24..91287cc963 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -114,6 +114,29 @@ class ShowfavoritesAction extends OwnerDesignAction common_set_returnto($this->selfUrl()); + $cur = common_current_user(); + + if (!empty($cur) && $cur->id == $this->user->id) { + + // Show imported/gateway notices as well as local if + // the user is looking at his own favorites + + $this->notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1, true); + } else { + $this->notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1, false); + } + + if (empty($this->notice)) { + $this->serverError(_('Could not retrieve favorite notices.')); + return; + } + + if($this->page > 1 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + return true; } @@ -193,26 +216,7 @@ class ShowfavoritesAction extends OwnerDesignAction function showContent() { - $cur = common_current_user(); - - if (!empty($cur) && $cur->id == $this->user->id) { - - // Show imported/gateway notices as well as local if - // the user is looking at his own favorites - - $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1, true); - } else { - $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1, false); - } - - if (empty($notice)) { - $this->serverError(_('Could not retrieve favorite notices.')); - return; - } - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show(); if (0 == $cnt) { diff --git a/actions/tag.php b/actions/tag.php index 020399d9ee..771eb2861e 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -21,6 +21,9 @@ if (!defined('LACONICA')) { exit(1); } class TagAction extends Action { + + var $notice; + function prepare($args) { parent::prepare($args); @@ -42,6 +45,12 @@ class TagAction extends Action common_set_returnto($this->selfUrl()); + $this->notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); + + if($this->page > 1 && $this->notice->N == 0){ + $this->serverError(_('No such page'),$code=404); + } + return true; } @@ -94,9 +103,7 @@ class TagAction extends Action function showContent() { - $notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); - - $nl = new NoticeList($notice, $this); + $nl = new NoticeList($this->notice, $this); $cnt = $nl->show();