[dw-free] Entry options page broken when user is not logged in
[commit: http://hg.dwscoalition.org/dw-free/rev/45e3112599b3]
http://bugs.dwscoalition.org/show_bug.cgi?id=4043
Remove status/content_type setting from DW::Template. Instead, explicitly
set on $r. Also changes a few instances of DW::Template->render_string( ...
{ no_sitescheme} ) to $r->print; return $r->OK
Patch by
exor674.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=4043
Remove status/content_type setting from DW::Template. Instead, explicitly
set on $r. Also changes a few instances of DW::Template->render_string( ...
{ no_sitescheme} ) to $r->print; return $r->OK
Patch by
Files modified:
- cgi-bin/DW/Controller/Entry.pm
- cgi-bin/DW/Controller/Interface/AtomAPI.pm
- cgi-bin/DW/Routing.pm
- cgi-bin/DW/Template.pm
--------------------------------------------------------------------------------
diff -r 845524541110 -r 45e3112599b3 cgi-bin/DW/Controller/Entry.pm
--- a/cgi-bin/DW/Controller/Entry.pm Mon Nov 07 17:03:05 2011 +0800
+++ b/cgi-bin/DW/Controller/Entry.pm Mon Nov 07 17:22:42 2011 +0800
@@ -23,6 +23,7 @@
use DW::Template;
use Hash::MultiValue;
+use HTTP::Status qw( :constants );
=head1 NAME
@@ -1044,7 +1045,8 @@
LJ::S2::s2_run( $r, $ctx, $opts, "EntryPage::print()", $p );
- return DW::Template->render_string( $ret, { no_sitescheme => 1 } );
+ $r->print( $ret );
+ return $r->OK;
}
}
@@ -1073,9 +1075,10 @@
my $vars = _options( $rv->{remote} );
$vars->{use_js} = 1;
- my $status = @{$vars->{error_list} || []} ? DW::Request->get->HTTP_BAD_REQUEST : DW::Request->get->HTTP_OK;
+ my $r = DW::Request->get;
+ $r->status( @{$vars->{error_list} || []} ? HTTP_BAD_REQUEST : HTTP_OK );
- return DW::Template->render_template( 'entry/options.tt', $vars, { no_sitescheme => 1, status => $status } );
+ return DW::Template->render_template( 'entry/options.tt', $vars, { no_sitescheme => 1 } );
}
sub _load_visible_panels {
diff -r 845524541110 -r 45e3112599b3 cgi-bin/DW/Controller/Interface/AtomAPI.pm
--- a/cgi-bin/DW/Controller/Interface/AtomAPI.pm Mon Nov 07 17:03:05 2011 +0800
+++ b/cgi-bin/DW/Controller/Interface/AtomAPI.pm Mon Nov 07 17:22:42 2011 +0800
@@ -25,6 +25,8 @@
use Digest::SHA1;
use MIME::Base64;
+use HTTP::Status qw( :constants );
+
require 'ljprotocol.pl';
# service document URL is the same for all users
@@ -37,29 +39,31 @@
format => "atom", methods => { POST => 1, GET => 1 } );
DW::Routing->register_string( "/interface/atom/entries/tags", \&categories_document, user => 1,
format => "atom", methods => { GET => 1 } );
-DW::Routing->register_regex( qr#/interface/atom/entries/(\d+)#, \&entry_handler, user => 1,
+DW::Routing->register_regex( qr#^/interface/atom/entries/(\d+)$#, \&entry_handler, user => 1,
format => "atom", methods => { GET => 1, PUT => 1, DELETE => 1 } );
sub ok {
my ( $message, $status, $content_type ) = @_;
- return DW::Template->render_string(
- $message,
- { status => $status || DW::Request->get->HTTP_OK,
- content_type => $content_type || "application/atom+xml",
- no_sitescheme => 1,
- }
- );
+
+ my $r = DW::Request->get;
+ $r->status( $status || HTTP_OK );
+ $r->content_type( $content_type || "application/atom+xml" );
+
+ $r->print( $message );
+
+ return $r->OK;
}
sub err {
my ( $message, $status ) = @_;
- return DW::Template->render_string(
- $message,
- { status => $status || DW::Request->get->NOT_FOUND,
- content_type => "text/plain",
- no_sitescheme => 1,
- }
- );
+
+ my $r = DW::Request->get;
+ $r->status( $status || HTTP_NOT_FOUND );
+ $r->content_type( 'text/plain' );
+
+ $r->print($message);
+
+ return $r->OK;
}
sub check_enabled {
diff -r 845524541110 -r 45e3112599b3 cgi-bin/DW/Routing.pm
--- a/cgi-bin/DW/Routing.pm Mon Nov 07 17:03:05 2011 +0800
+++ b/cgi-bin/DW/Routing.pm Mon Nov 07 17:22:42 2011 +0800
@@ -210,12 +210,11 @@
$msg .= " \@ $LJ::SERVER_NAME" if $LJ::SERVER_NAME;
$r->status( 500 );
+ $r->content_type( $default_content_types->{html} );
+
my $text = $LJ::MSG_ERROR || "Sorry, there was a problem.";
my $remote = LJ::get_remote();
$text = "<b>[Error: $msg]</b>" if ( $remote && $remote->show_raw_errors ) || $LJ::IS_DEV_SERVER;
-
- my $opts = { status=>500, content_type=>'text/html' };
-
$opts->{no_sitescheme} = 1 if $T_TESTING_ERRORS;
return DW::Template->render_string( $text, $opts );
@@ -229,11 +228,11 @@
my $remote = LJ::get_remote();
$text = "Error: $msg" if ( $remote && $remote->show_raw_errors ) || $LJ::IS_DEV_SERVER;
- return DW::Template->render_string( $text, {
- status => 500,
- content_type => 'text/plain',
- no_sitescheme => 1
- } );
+ $r->status( 500 );
+ $r->content_type( 'text/plain' );
+ $r->print( $text );
+
+ return $r->OK;
}
}
diff -r 845524541110 -r 45e3112599b3 cgi-bin/DW/Template.pm
--- a/cgi-bin/DW/Template.pm Mon Nov 07 17:03:05 2011 +0800
+++ b/cgi-bin/DW/Template.pm Mon Nov 07 17:22:42 2011 +0800
@@ -169,10 +169,6 @@
=item B< title / windowtitle / head / bodyopts / ... > == text to get thrown in the section if inside sitescheme
-=item B< content_type > = content type
-
-=item B< status > = HTTP status code
-
=item B< lock_failed > = subref for lock failed.
=item B< expire > - Number of seconds the fragment is valid for
@@ -203,10 +199,6 @@
=item B< title / windowtitle / head / bodyopts / ... > == text to get thrown in the section if inside sitescheme
-=item B< content_type > = content type
-
-=item B< status > = HTTP status code
-
=back
=cut
@@ -235,12 +227,14 @@
=item B< no_sitescheme > == render alone
+=over
+
+This will be ignored for 'bml' scopes.
+
+=back
+
=item B< title / windowtitle / head / bodyopts / ... > == text to get thrown in the section if inside sitescheme
-=item B< content_type > = content type
-
-=item B< status > = HTTP status code
-
=item B< scope > = Scope, accepts nothing, 'bml', or 'journal'
=item B< scope_data > = Depends on B< scope >
@@ -271,16 +265,13 @@
my $r = DW::Request->get;
my $bml = $extra->{scope_data};
- $r->status( $extra->{status} ) if $extra->{status};
- $r->content_type( $extra->{content_type} ) if $extra->{content_type};
-
for my $item ( qw(title windowtitle head bodyopts) ) {
${$bml->{$item}} = $extra->{$item} || "";
}
return $out;
}
- my $rv = $class->render_string( $out, $extra );
+ my $rv = $class->render_string( $out, $extra );
if ( $scope eq 'journal' ) {
$extra->{scope_data}->{handler_return} = $rv;
return;
@@ -299,12 +290,17 @@
=item B< no_sitescheme > == render alone
+=over
+
+If you are just printing text or other data, do not call DW::Template->render_string and instead just
+$r->print and return $r->OK.
+
+This is mostly for being used from render_template.
+
+=back
+
=item B< title / windowtitle / head / bodyopts / ... > == text to get thrown in the section if inside sitescheme
-=item B< content_type > = content type
-
-=item B< status > = HTTP status code
-
=back
=cut
@@ -313,8 +309,6 @@
my ( $class, $out, $extra ) = @_;
my $r = DW::Request->get;
- $r->status( $extra->{status} ) if $extra->{status};
- $r->content_type( $extra->{content_type} ) if $extra->{content_type};
my $scheme = DW::SiteScheme->get;
--------------------------------------------------------------------------------
