diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index affbb8284..5814c0db9 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -10,7 +10,15 @@ - Fixed a bug in articles where articles with no content would fail to display their images. - bugfix [966466] WebGUI::Session. System crash when user language setting missing. - - Eliminated the need for Data::Serializer. + - Eliminated the need for Data::Serializer which results in a small amount of + less memory usage. + - Rewrote the template API which resulted in a 30% performance increase. See + docs/migration.txt for details. + - Added five new caching mechanisms for templates. Each has their own + benefits and detriments. This allows you to increase scalability and + performance at a cost of either memory or disk space or both. The gains + here are primarily enjoyed by large heavy traffic sites that use lots of + templates. 6.0.3 diff --git a/docs/gotcha.txt b/docs/gotcha.txt index ed52b3b21..cf7ed110e 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -14,6 +14,8 @@ save you many hours of grief. * You no longer need Data::Serializer. + * See docs/migration.txt for changes in the template system. + 6.0.2 -------------------------------------------------------------------- diff --git a/docs/migration.txt b/docs/migration.txt index 278ff93b4..6c54e44d1 100644 --- a/docs/migration.txt +++ b/docs/migration.txt @@ -113,11 +113,16 @@ to load the plug-in at use time. 5.5 Privilege API Change -In 6.1 we move isInGroup from WebGUI::Privilege to WebGUI::Grouping, where it +In 6.1 we moved isInGroup from WebGUI::Privilege to WebGUI::Grouping, where it belongs. We also moved canViewPage and canEditPage to WebGUI::Page and renamed them to canView and canEdit. And finally, we moved canEditWobject and canViewWobject to WebGUI::Wobject and renamed them canView and canEdit and converted them from regular functions into methods. +5.6 Template API Change + +In 6.1 we completely rewrote the underlying template framework to add template +caching. Any plug-ins that use WebGUI::Template, must be updated to reflect +the new API. diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 86bd6de62..ee4e55339 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -14,6 +14,8 @@ uploadsPath = /data/WebGUI/www/uploads useSharedInternationalCache = 1 +templateCacheType=file + emailRecoveryLoggingEnabled = 1 passwordChangeLoggingEnabled = 1 diff --git a/lib/WebGUI/Attachment.pm b/lib/WebGUI/Attachment.pm index 7bbd7f8a8..e211288a7 100644 --- a/lib/WebGUI/Attachment.pm +++ b/lib/WebGUI/Attachment.pm @@ -66,6 +66,7 @@ Package to manipulate WebGUI Attachments. $filename = $attachment->save("formImage"); $filename = $attachment->saveFromFilesystem($pathToFile); + $filename = $attachment->saveFromScalar($content); $filename = $attachment->saveFromHashref($hashRef); $hashRef = $attachment->getHashref; @@ -681,6 +682,32 @@ sub saveFromHashref { return $self->getFilename; } + +#------------------------------------------------------------------- + +=head2 saveFromScalar ( scalar ) + +Stores a scalar as a text attachment. + +=over + +=item scalar + +A scalar variable containing the content to write to the filesystem. + +=back + +=cut + +sub saveFromScalar { + my ($self, $content) = @_; + $self->getNode->create(); + open(FILE,">".$self->getPath); + print FILE $content; + close(FILE); + return $self->getFilename; +} + 1; diff --git a/lib/WebGUI/Auth.pm b/lib/WebGUI/Auth.pm index ae0223992..d47846402 100644 --- a/lib/WebGUI/Auth.pm +++ b/lib/WebGUI/Auth.pm @@ -218,7 +218,7 @@ sub createAccount { $vars->{'login.url'} = WebGUI::URL::page('op=auth&method=init'); $vars->{'login.label'} = WebGUI::International::get(58); - return WebGUI::Template::process(WebGUI::Template::get(1,$template), $vars); + return WebGUI::Template::process(1,$template, $vars); } #------------------------------------------------------------------- @@ -306,7 +306,7 @@ sub deactivateAccount { $var{'yes.label'} = WebGUI::International::get(44); $var{'no.url'} = WebGUI::URL::page(); $var{'no.label'} = WebGUI::International::get(45); - return WebGUI::Template::process(WebGUI::Template::get(1,"prompt"), \%var); + return WebGUI::Template::process(1,"prompt", \%var); } #------------------------------------------------------------------- @@ -379,7 +379,7 @@ sub displayAccount { $vars->{'account.form.footer'} = ""; $vars->{'account.options'} = WebGUI::Operation::Shared::accountOptions(); - return WebGUI::Template::process(WebGUI::Template::get(1,$template), $vars); + return WebGUI::Template::process(1,$template, $vars); } #------------------------------------------------------------------- @@ -430,7 +430,7 @@ sub displayLogin { $vars->{'anonymousRegistration.isAllowed'} = ($session{setting}{anonymousRegistration}); $vars->{'createAccount.url'} = WebGUI::URL::page('op=createAccount'); $vars->{'createAccount.label'} = WebGUI::International::get(67); - return WebGUI::Template::process(WebGUI::Template::get(1,$template), $vars); + return WebGUI::Template::process(1,$template, $vars); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Auth/LDAP.pm b/lib/WebGUI/Auth/LDAP.pm index bca2fe31b..bdb2b8d30 100644 --- a/lib/WebGUI/Auth/LDAP.pm +++ b/lib/WebGUI/Auth/LDAP.pm @@ -261,7 +261,7 @@ sub displayAccount { $vars->{'account.form.karma.label'} = WebGUI::International::get(537); } $vars->{'account.options'} = WebGUI::Operation::Shared::accountOptions(); - return WebGUI::Template::process(WebGUI::Template::get(1,'Auth/LDAP/Account'), $vars); + return WebGUI::Template::process(1,'Auth/LDAP/Account', $vars); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Auth/SMB.pm b/lib/WebGUI/Auth/SMB.pm index a44275f45..cc3c34658 100644 --- a/lib/WebGUI/Auth/SMB.pm +++ b/lib/WebGUI/Auth/SMB.pm @@ -169,7 +169,7 @@ sub displayAccount { $vars->{'account.form.karma.label'} = WebGUI::International::get(537); } $vars->{'account.options'} = WebGUI::Operation::Shared::accountOptions(); - return WebGUI::Template::process(WebGUI::Template::get(1,'Auth/SMB/Account'), $vars); + return WebGUI::Template::process(1,'Auth/SMB/Account', $vars); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Auth/WebGUI.pm b/lib/WebGUI/Auth/WebGUI.pm index 5c999a13a..92a456d1f 100644 --- a/lib/WebGUI/Auth/WebGUI.pm +++ b/lib/WebGUI/Auth/WebGUI.pm @@ -400,7 +400,7 @@ sub recoverPassword { $vars->{'recover.message'} = $_[0] if ($_[0]); $vars->{'recover.form.email'} = WebGUI::Form::text({"name"=>"email"}); $vars->{'recover.form.email.label'} = WebGUI::International::get(56); - return WebGUI::Template::process(WebGUI::Template::get(1,$template), $vars); + return WebGUI::Template::process(1,$template, $vars); } #------------------------------------------------------------------- @@ -459,7 +459,7 @@ sub resetExpiredPassword { $vars->{'expired.form.submit'} = WebGUI::Form::submit({}); $vars->{'expired.form.footer'} = ""; - return WebGUI::Template::process(WebGUI::Template::get(1,'Auth/WebGUI/Expired'), $vars); + return WebGUI::Template::process(1,'Auth/WebGUI/Expired', $vars); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index f1dd9527d..3d818a33c 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -991,7 +991,7 @@ sub HTMLArea { if ($session{user}{richEditor} eq 'none') { return $var{textarea}; } else { - return WebGUI::Template::process(WebGUI::Template::get($session{user}{richEditor},'richEditor'),\%var); + return WebGUI::Template::process($session{user}{richEditor},'richEditor',\%var); } } diff --git a/lib/WebGUI/Forum/UI.pm b/lib/WebGUI/Forum/UI.pm index 2cef91b94..117f4d2c8 100644 --- a/lib/WebGUI/Forum/UI.pm +++ b/lib/WebGUI/Forum/UI.pm @@ -1249,7 +1249,7 @@ sub getPostTemplateVars { $var->{'post.deny.url'} = formatDenyPostURL($callback,$post->get("forumPostId")); $var->{'forum.title'} = $callback->{title}; $var->{'forum.description'} = $callback->{description}; - $var->{'post.full'} = WebGUI::Template::process(WebGUI::Template::get($forum->get("postTemplateId"),"Forum/Post"), $var); + $var->{'post.full'} = WebGUI::Template::process($forum->get("postTemplateId"),"Forum/Post", $var); return $var; } @@ -1382,7 +1382,7 @@ sub notifySubscribers { $lang{$u->profileField("language")}{var} = getPostTemplateVars($post, $thread, $forum, $caller, $lang{$u->profileField("language")}{var}); $lang{$u->profileField("language")}{subject} = WebGUI::International::get(523,"WebGUI",$u->profileField("language")); $lang{$u->profileField("language")}{message} = WebGUI::Template::process( - WebGUI::Template::get($forum->get("notificationTemplateId"),"Forum/Notification"), + $forum->get("notificationTemplateId"),"Forum/Notification", $lang{$u->profileField("language")}{var} ); } @@ -1886,7 +1886,7 @@ sub www_post { value=>$subject }); $var->{'form.end'} = ''; - return WebGUI::Template::process(WebGUI::Template::get($forum->get("postformTemplateId"),"Forum/PostForm"), $var); + return WebGUI::Template::process($forum->get("postformTemplateId"),"Forum/PostForm", $var); } #------------------------------------------------------------------- @@ -2119,7 +2119,7 @@ sub www_search { $var{numberOfPages} = $p->getNumberOfPages; $var{pageNumber} = $p->getPageNumber; } - return WebGUI::Template::process(WebGUI::Template::get($forum->get("searchTemplateId"),"Forum/Search"), \%var); + return WebGUI::Template::process($forum->get("searchTemplateId"),"Forum/Search", \%var); } #------------------------------------------------------------------- @@ -2293,7 +2293,7 @@ sub www_viewForum { my $forum = WebGUI::Forum->new($forumId); return WebGUI::Privilege::insufficient() unless ($forum->canView); my $var = getForumTemplateVars($caller, $forum); - return WebGUI::Template::process(WebGUI::Template::get($forum->get("forumTemplateId"),"Forum"), $var); + return WebGUI::Template::process($forum->get("forumTemplateId"),"Forum", $var); } #------------------------------------------------------------------- @@ -2332,7 +2332,7 @@ sub www_viewThread { if ($post->get("forumPostId") == $post->getThread->get("rootPostId") && !$post->canView) { return www_viewForum($caller, $post->getThread->getForum->get("forumId")); } else { - return WebGUI::Template::process(WebGUI::Template::get($post->getThread->getForum->get("threadTemplateId"),"Forum/Thread"), $var); + return WebGUI::Template::process($post->getThread->getForum->get("threadTemplateId"),"Forum/Thread", $var); } } diff --git a/lib/WebGUI/Macro/AdminBar.pm b/lib/WebGUI/Macro/AdminBar.pm index bedef9203..fbbc49c48 100644 --- a/lib/WebGUI/Macro/AdminBar.pm +++ b/lib/WebGUI/Macro/AdminBar.pm @@ -209,7 +209,7 @@ sub process { $i++; } $var{'admin_loop'} = \@admin; - return WebGUI::Template::process(WebGUI::Template::get($templateId,"Macro/AdminBar"),\%var); + return WebGUI::Template::process($templateId,"Macro/AdminBar",\%var); } diff --git a/lib/WebGUI/Macro/L_loginBox.pm b/lib/WebGUI/Macro/L_loginBox.pm index f43fddf6a..b3f3fd6e9 100644 --- a/lib/WebGUI/Macro/L_loginBox.pm +++ b/lib/WebGUI/Macro/L_loginBox.pm @@ -64,7 +64,7 @@ sub process { $var{'account.create.url'} = WebGUI::URL::page('op=createAccount'); $var{'account.create.label'} = WebGUI::International::get(407); $var{'form.footer'} = ''; - return WebGUI::Template::process(WebGUI::Template::get($templateId,"Macro/L_loginBox"),\%var); + return WebGUI::Template::process($templateId,"Macro/L_loginBox",\%var); } 1; diff --git a/lib/WebGUI/Navigation.pm b/lib/WebGUI/Navigation.pm index 8a826bd08..41a7694d5 100644 --- a/lib/WebGUI/Navigation.pm +++ b/lib/WebGUI/Navigation.pm @@ -337,8 +337,11 @@ sub build { # Configure button $var->{'config.button'} = $self->_getEditButton(); - - return WebGUI::Template::process($self->{_template} || WebGUI::Template::get($self->{_templateId}, "Navigation"), $var); + if ($self->{_template}) { + return WebGUI::Template::processRaw($self->{_template}, $var); + } else { + return WebGUI::Template::process($self->{_templateId}, "Navigation", $var); + } } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Operation/MessageLog.pm b/lib/WebGUI/Operation/MessageLog.pm index ba84a3464..0b85e3ff3 100644 --- a/lib/WebGUI/Operation/MessageLog.pm +++ b/lib/WebGUI/Operation/MessageLog.pm @@ -68,7 +68,7 @@ sub www_viewMessageLog { $vars->{'message.multiplePages'} = ($p->getNumberOfPages > 1); $vars->{'message.accountOptions'} = WebGUI::Operation::Shared::accountOptions(); - return WebGUI::Template::process(WebGUI::Template::get(1,'Operation/MessageLog/View'), $vars); + return WebGUI::Template::process(1,'Operation/MessageLog/View', $vars); } #------------------------------------------------------------------- @@ -95,7 +95,7 @@ sub www_viewMessageLogMessage { $vars->{'message.text'} = $data->{message}; $vars->{'message.accountOptions'} = WebGUI::Operation::Shared::accountOptions(); - return WebGUI::Template::process(WebGUI::Template::get(1,'Operation/MessageLog/Message'), $vars); + return WebGUI::Template::process(1,'Operation/MessageLog/Message', $vars); } 1; diff --git a/lib/WebGUI/Operation/Profile.pm b/lib/WebGUI/Operation/Profile.pm index 2ff13385f..881fb29b1 100644 --- a/lib/WebGUI/Operation/Profile.pm +++ b/lib/WebGUI/Operation/Profile.pm @@ -195,7 +195,7 @@ sub www_editProfile { $vars->{'profile.form.elements'} = \@array; $vars->{'profile.form.submit'} = WebGUI::Form::submit({}); $vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions(); - return WebGUI::Template::process(WebGUI::Template::get(1,'Operation/Profile/Edit'), $vars); + return WebGUI::Template::process(1,'Operation/Profile/Edit', $vars); } #------------------------------------------------------------------- @@ -257,7 +257,7 @@ sub www_viewProfile { if ($session{user}{userId} == $session{form}{uid}) { $vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions(); } - return WebGUI::Template::process(WebGUI::Template::get(1,'Operation/Profile/View'), $vars); + return WebGUI::Template::process(1,'Operation/Profile/View', $vars); } 1; diff --git a/lib/WebGUI/Operation/Template.pm b/lib/WebGUI/Operation/Template.pm index 4bb559fa2..c452d08d5 100644 --- a/lib/WebGUI/Operation/Template.pm +++ b/lib/WebGUI/Operation/Template.pm @@ -53,13 +53,11 @@ sub _submenu { #------------------------------------------------------------------- sub www_copyTemplate { - my (%template); if (WebGUI::Grouping::isInGroup(8)) { - %template = WebGUI::SQL->quickHash("select * from template where templateId=$session{form}{tid} and namespace=".quote($session{form}{namespace})); - WebGUI::SQL->write("insert into template (templateId,name,template,namespace) - values ("._getNextTemplateId($session{form}{namespace}).", - ".quote('Copy of '.$template{name}).", ".quote($template{template}).", - ".quote($template{namespace}).")"); + my $template = WebGUI::Template::get($session{form}{tid},$session{form}{namespace}); + $template->{name} .= " (copy)"; + $template->{templateId} = "new"; + WebGUI::Template::set($template); return www_listTemplates(); } else { return WebGUI::Privilege::adminOnly(); @@ -157,17 +155,15 @@ sub www_editTemplate { #------------------------------------------------------------------- sub www_editTemplateSave { if (WebGUI::Grouping::isInGroup(8)) { - if ($session{form}{tid} eq "new") { - $session{form}{tid} = _getNextTemplateId($session{form}{namespace}); - WebGUI::SQL->write("insert into template (templateId,namespace) values - ($session{form}{tid}, ".quote($session{form}{namespace}).")"); - } if ($session{form}{template} eq "" && $session{form}{namespace} eq "Page") { $session{form}{template} = "
| \n\n | \n