From 29bd26a975cc995b6b4db620d6de643d310d1ff6 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 25 Mar 2006 21:39:15 +0000 Subject: [PATCH] - Added a wiki-like feature that will automatically bring a user to the create a page form if they are in admin mode, and click on a link to a page that doesn't exist yet. --- docs/changelog/6.x.x.txt | 3 +++ lib/WebGUI.pm | 31 ++++++++++++++++++++----------- lib/WebGUI/Asset.pm | 1 + lib/WebGUI/Session/Url.pm | 23 +++++++++++++++++++++++ 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 84bb1944b..d41b762aa 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -10,6 +10,9 @@ - Addded a lock menu item to explicitly lock an asset from editing. - Run on registration and alert on new user have been converted to a single workflow. + - Added a wiki-like feature that will automatically bring a user to the + create a page form if they are in admin mode, and click on a link to + a page that doesn't exist yet. - Many changes for better XHTML compliance. - Refactored admin bar to be more dynamic. - Removed start/end dates from assets in favor of the workflow system. diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index ca35fa36d..6993bdf9b 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -136,7 +136,7 @@ sub fixupHandler { #------------------------------------------------------------------- -=head2 page ( session ) +=head2 page ( session , [ assetUrl ] ) Processes operations (if any), then tries the requested method on the asset corresponding to the requested URL. If that asset fails to be created, it tries the default page. @@ -144,16 +144,20 @@ Processes operations (if any), then tries the requested method on the asset corr The current WebGUI::Session object. +=head3 assetUrl + +Optionally pass in a URL to be loaded. + =cut sub page { my $session = shift; - my $assetUrl = shift; + my $assetUrl = shift || $session->url->getRequestedUrl; my $output = processOperations($session); if ($output eq "") { my $asset = eval{WebGUI::Asset->newByUrl($session,$assetUrl,$session->form->process("revision"))}; if ($@) { - $session->errorHandler->warn("Couldn't instantiate asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@); + $session->errorHandler->warn("Couldn't instantiate asset for url: ".$assetUrl." Root cause: ".$@); } if (defined $asset) { my $method = "view"; @@ -169,15 +173,20 @@ sub page { } } if (defined($output) and $output eq "") { - $session->http->setStatus("404","Page Not Found"); - my $notFound = WebGUI::Asset->getNotFound($session); - if (defined $notFound) { - $output = tryAssetMethod($session,$notFound,'view'); - } else { - $session->errorHandler->error("The notFound page failed to be created!"); - $output = "An error was encountered while processing your request."; + if ($session->var->isAdminOn) { # they're expecting it to be there, so let's help them add it + my $asset = WebGUI::Asset->newByUrl($session, $session->url->getRefererUrl) || WebGUI::Asset->getDefault($session); + $session->http->setRedirect($asset->getUrl("func=add;assetId=new;class=WebGUI::Asset::Wobject::Layout;url=".$assetUrl)); + } else { # not in admin mode, so can't create it, so display not found + $session->http->setStatus("404","Page Not Found"); + my $notFound = WebGUI::Asset->getNotFound($session); + if (defined $notFound) { + $output = tryAssetMethod($session,$notFound,'view'); + } else { + $session->errorHandler->error("The notFound page could not be instanciated!"); + $output = "An error was encountered while processing your request."; + } + $output = "An error was encountered while processing your request." if $output eq ''; } - $output = "An error was encountered while processing your request." if $output eq ''; } if ($output eq "chunked") { $output = undef; diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index f3f033e86..566c59086 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1696,6 +1696,7 @@ sub www_add { printableStyleTemplateId => $self->get("printableStyleTemplateId"), isHidden => $self->get("isHidden"), className=>$class, + url=>$self->session->form->param("url"), assetId=>"new" ); $properties{isHidden} = 1 unless (WebGUI::Utility::isIn($class, @{$self->session->config->get("assetContainers")})); diff --git a/lib/WebGUI/Session/Url.pm b/lib/WebGUI/Session/Url.pm index fc92ea1db..9760dd826 100644 --- a/lib/WebGUI/Session/Url.pm +++ b/lib/WebGUI/Session/Url.pm @@ -155,6 +155,29 @@ sub gateway { return $url; } +#------------------------------------------------------------------- + +=head2 getRefererUrl ( ) + +Returns the URL of the page this request was refered from (no gateway, no query params, just the page url). Returns undef if there was no referer. + +=cut + +sub getRefererUrl { + my $self = shift; + my $referer = $self->session->env->get("HTTP_REFERER"); + return undef unless ($referer); + my $url = $referer; + my $gateway = $self->session->config->get("gateway"); + $url =~ s/htt\w+\:\/\/[A-Za-z0-9\.\-]+$gateway\/*(\S*)/$1/;; + if ($url eq $referer) { + return undef; + } else { + return $url; + } +} + + #------------------------------------------------------------------- =head2 getRequestedUrl ( )