[dw-free] Add style for sitescheme-wrapped views to replace views handled in S2
[commit: http://hg.dwscoalition.org/dw-free/rev/4388e4653fad]
http://bugs.dwscoalition.org/show_bug.cgi?id=1448
This adds basic support for routing S2 output through BML so we can have
sitescheme S2.
Patch by
exor674.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1448
This adds basic support for routing S2 output through BML so we can have
sitescheme S2.
Patch by
Files modified:
- bin/upgrading/s2layers.dat
- bin/upgrading/s2layers/siteviews/layout.s2
- bin/upgrading/s2layers/siteviews/themes.s2
- cgi-bin/Apache/LiveJournal.pm
- cgi-bin/DW/Hooks/NavStrip.pm
- cgi-bin/LJ/S2.pm
- cgi-bin/LJ/User.pm
- htdocs/misc/siteviews.bml
--------------------------------------------------------------------------------
diff -r f50d67506b08 -r 4388e4653fad bin/upgrading/s2layers.dat
--- a/bin/upgrading/s2layers.dat Sun Sep 06 17:53:16 2009 +0000
+++ b/bin/upgrading/s2layers.dat Sun Sep 06 18:04:56 2009 +0000
@@ -3,6 +3,9 @@
core1 core -
core2 core -
+
+siteviews/layout layout core2
+siteviews/themes theme+ siteviews/layout
bases/layout layout core2
bases/themes theme+ bases/layout
diff -r f50d67506b08 -r 4388e4653fad bin/upgrading/s2layers/siteviews/layout.s2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/upgrading/s2layers/siteviews/layout.s2 Sun Sep 06 18:04:56 2009 +0000
@@ -0,0 +1,29 @@
+layerinfo "type" = "layout";
+layerinfo "name" = "Sitescheme views";
+layerinfo redist_uniq = "siteviews/layout";
+layerinfo is_internal = "1";
+
+property builtin bool SITEVIEWS_RENDERED {
+ noui = 1;
+ doc_flags = "[sys]";
+ des = "Will be 1 if this layout is going to be parsed for BML once it's done";
+}
+
+function Page::print() {
+ if ($*SITEVIEWS_RENDERED) {
+ """<?page
+body<=\n""";
+$this->print_body();
+"""\n<=body\n""";
+$this->print_head_title();
+"""page?>""";
+ } else {
+ print safe "<b>This style is not intended for direct use.</b>";
+ }
+}
+
+function Page::print_head_title() {
+ print "title=>";
+ print safe $this->view_title();
+ print "\n";
+}
diff -r f50d67506b08 -r 4388e4653fad bin/upgrading/s2layers/siteviews/themes.s2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/upgrading/s2layers/siteviews/themes.s2 Sun Sep 06 18:04:56 2009 +0000
@@ -0,0 +1,4 @@
+#NEWLAYER: siteviews/default
+layerinfo type = "theme";
+layerinfo name = "Default Theme";
+layerinfo redist_uniq = "siteviews/default";
diff -r f50d67506b08 -r 4388e4653fad cgi-bin/Apache/LiveJournal.pm
--- a/cgi-bin/Apache/LiveJournal.pm Sun Sep 06 17:53:16 2009 +0000
+++ b/cgi-bin/Apache/LiveJournal.pm Sun Sep 06 18:04:56 2009 +0000
@@ -1339,6 +1339,10 @@ sub journal_content
# case it's our job to invoke the legacy BML page.
my $handle_with_bml = 0;
+ # or this flag for pages that are from siteviews and expect
+ # to be processed by /misc/siteviews to get sitescheme around them
+ my $handle_with_siteviews = 0;
+
my %headers = ();
my $opts = {
'r' => $r,
@@ -1351,6 +1355,7 @@ sub journal_content
'If-Modified-Since' => $r->headers_in->{"If-Modified-Since"},
},
'handle_with_bml_ref' => \$handle_with_bml,
+ 'handle_with_siteviews_ref' => \$handle_with_siteviews,
'ljentry' => $RQ{'ljentry'},
};
@@ -1360,13 +1365,19 @@ sub journal_content
my $html = LJ::make_journal($user, $RQ{'mode'}, $remote, $opts);
# Allow to add extra http-header or even modify html
- LJ::run_hooks("after_journal_content_created", $opts, \$html);
+ LJ::run_hooks("after_journal_content_created", $opts, \$html) unless $handle_with_siteviews;
return redir($r, $opts->{'redir'}) if $opts->{'redir'};
return $opts->{'handler_return'} if defined $opts->{'handler_return'};
# if LJ::make_journal() indicated it can't handle the request:
- if ($handle_with_bml) {
+ # only if HTML is set, otherwise leave it alone so the user
+ # gets "messed up template definition", cause something went wrong.
+ if ( $handle_with_siteviews && $html ) {
+ $r->pnotes->{siteview_code} = $html;
+ $r->notes->{bml_filename} = "$LJ::HOME/htdocs/misc/siteviews.bml";
+ return Apache::BML::handler($r);
+ } elsif ($handle_with_bml) {
my $args = $r->args;
my $args_wq = $args ? "?$args" : "";
diff -r f50d67506b08 -r 4388e4653fad cgi-bin/DW/Hooks/NavStrip.pm
--- a/cgi-bin/DW/Hooks/NavStrip.pm Sun Sep 06 17:53:16 2009 +0000
+++ b/cgi-bin/DW/Hooks/NavStrip.pm Sun Sep 06 18:04:56 2009 +0000
@@ -35,9 +35,11 @@ LJ::register_hook( 'show_control_strip',
my $r = DW::Request->get;
my $journal = LJ::get_active_journal();
+ return undef if $r->note( 'no_control_strip' );
+
# don't display if any of these are unavailable
return undef unless $r && $journal;
-
+
my @pageoptions = LJ::run_hook( 'page_control_strip_options' );
return undef unless @pageoptions;
diff -r f50d67506b08 -r 4388e4653fad cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Sun Sep 06 17:53:16 2009 +0000
+++ b/cgi-bin/LJ/S2.pm Sun Sep 06 18:04:56 2009 +0000
@@ -41,14 +41,6 @@ sub make_journal
my ( $entry, $page, $use_modtime );
if ($view eq "res") {
-
- # the s1shortcomings virtual styleid doesn't have a styleid
- # so we're making the rule that it can't have resource URLs.
- if ($styleid eq "s1short") {
- $opts->{'handler_return'} = 404;
- return;
- }
-
if ($opts->{'pathextra'} =~ m!/(\d+)/stylesheet$!) {
$styleid = $1;
$entry = "print_stylesheet()";
@@ -79,8 +71,17 @@ sub make_journal
BML::set_language($lang, \&LJ::Lang::get_text);
# let layouts disable EntryPage / ReplyPage, using the BML version
- # instead.
- unless ($styleid eq "s1short") {
+ # instead. Unless we are using siteviews, because that is what
+ # will be handling the "BML" views.
+ if ($styleid eq "siteviews") {
+ $r->notes->{ 'no_control_strip' } = 1;
+
+ # kill the flag
+ ${$opts->{'handle_with_bml_ref'}} = 0;
+ ${$opts->{'handle_with_siteviews_ref'}} = 1;
+
+ $ctx->[S2::PROPS]->{'SITEVIEWS_RENDERED'} = 1;
+ } else {
if ( ! $ctx->[S2::PROPS]->{use_journalstyle_entry_page} && ( $view eq "entry" || $view eq "reply" ) ) {
${$opts->{'handle_with_bml_ref'}} = 1;
return;
@@ -670,6 +671,7 @@ sub s2_context
# get arguments we'll use frequently
my $r = DW::Request->get;
my $u = $opts{u} || LJ::get_active_journal();
+ my $remote = $opts{remote} || LJ::get_remote();
my $style_u = $opts{style_u} || $u;
# but it doesn't matter if we're using the minimal style ...
@@ -686,10 +688,8 @@ sub s2_context
}
};
- # styleid of "s1short" is special in that it makes a
- # dynamically-created s2 context
- if ($styleid eq "s1short") {
- %style = s1_shortcomings_style($u);
+ if ($styleid eq "siteviews") {
+ %style = siteviews_style( $u, $remote, $opts{mode} );
}
if (ref($styleid) eq "CODE") {
@@ -840,15 +840,16 @@ sub escape_prop_value {
}
}
-sub s1_shortcomings_style {
- my $u = shift;
+sub siteviews_style {
+ my ( $u, $remote, $mode ) = @_;
my %style;
my $public = get_public_layers();
%style = (
- core => "core1",
- layout => "s1shortcomings/layout",
- );
+ core => "core2",
+ layout => "siteviews/layout",
+ theme => "siteviews/default",
+ );
# convert the value names to s2layerid
while (my ($layer, $name) = each %style) {
@@ -1249,6 +1250,8 @@ sub populate_system_props
$ctx->[S2::PROPS]->{'SITENAMEABBREV'} = $LJ::SITENAMEABBREV;
$ctx->[S2::PROPS]->{'IMGDIR'} = $LJ::IMGPREFIX;
$ctx->[S2::PROPS]->{'STATDIR'} = $LJ::STATPREFIX;
+
+ $ctx->[S2::PROPS]->{'SITEVIEWS_RENDERED'} = 0;
}
# renamed some props from core1 => core2. Make sure that S2 still handles these variables correctly when working with a core1 layer
diff -r f50d67506b08 -r 4388e4653fad cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm Sun Sep 06 17:53:16 2009 +0000
+++ b/cgi-bin/LJ/User.pm Sun Sep 06 18:04:56 2009 +0000
@@ -7907,17 +7907,11 @@ sub make_journal
}
# signal to LiveJournal.pm that we can't handle this
- if (($stylesys == 1 || $geta->{'format'} eq 'light' || $geta->{'style'} eq 'light') &&
- ({ entry=>1, reply=>1, month=>1, tag=>1 }->{$view} || ($view eq 'lastn' && ($geta->{tag} || $geta->{security})))) {
-
- # pick which fallback method (s2 or bml) we'll use by default, as configured with
- # $S1_SHORTCOMINGS
- my $fallback = $LJ::S1_SHORTCOMINGS ? "s2" : "bml";
-
- # but if the user specifies which they want, override the fallback we picked
- if ($geta->{'fallback'} && $geta->{'fallback'} =~ /^s2|bml$/) {
- $fallback = $geta->{'fallback'};
- }
+ # FIXME: Make this properly invoke siteviews all the time -- once all the views are ready.
+ # Most of this if and tons of messy conditionals can go away once all views are done.
+ if ( ( ($stylesys == 1 || $geta->{'style'} eq 'site' || $geta->{'style'} eq 'default' ) &&
+ ( { entry=>1, reply=>1, month=>1, tag=>1 }->{$view} || ($view eq 'lastn' && ($geta->{tag} || $geta->{security})))) || ( $geta->{'format'} eq 'light' || $geta->{'style'} eq 'light' ) ) {
+ my $fallback = "bml"; # FIXME: Should be S2 once everything's done
# if we are in this path, and they have style=mine set, it means
# they either think they can get a S2 styled page but their account
@@ -7934,23 +7928,27 @@ sub make_journal
$r->note(bml_use_scheme => 'lynx');
}
+ # but if the user specifies which they want, override the fallback we picked
+ if ($geta->{'fallback'} && $geta->{'fallback'} =~ /^s2|bml$/) {
+ $fallback = $geta->{'fallback'};
+ }
+
# there are no BML handlers for these views, so force s2
- if ($view eq 'tag' || $view eq 'lastn') {
+ # FIXME: Temporaray until talkread/talkpost/month views are converted
+ if ( !( { entry => 1, reply => 1, month => 1 }->{$view} ) ) {
$fallback = "s2";
}
- # fall back to BML unless we're using S2
- # fallback (the "s1shortcomings/layout")
+ # fall back to legacy BML unless we're using BML-wrapped s2
if ($fallback eq "bml") {
${$opts->{'handle_with_bml_ref'}} = 1;
return;
}
- # S1 can't handle these views, so we fall back to a
- # system-owned S2 style (magic value "s1short") that renders
- # this content
+ # Render a system-owned S2 style that renders
+ # this content, then passes it to get treated as BML
$stylesys = 2;
- $styleid = "s1short";
+ $styleid = "siteviews";
}
# now, if there's a GET argument for tags, split those out
@@ -8068,18 +8066,17 @@ sub make_journal
if $r;
eval { LJ::S2->can("dostuff") }; # force Class::Autouse
- my $mj = LJ::S2::make_journal($u, $styleid, $view, $remote, $opts);
-
- # intercept flag to handle_with_bml_ref and instead use S1 shortcomings
- # if BML is disabled
- if ($opts->{'handle_with_bml_ref'} && ${$opts->{'handle_with_bml_ref'}} &&
- ($LJ::S1_SHORTCOMINGS || $geta->{fallback} eq "s2"))
- {
- # kill the flag
- ${$opts->{'handle_with_bml_ref'}} = 0;
-
- # and proceed with s1shortcomings (which looks like BML) instead of BML
- $mj = LJ::S2::make_journal($u, "s1short", $view, $remote, $opts);
+
+ my $mj;
+
+ unless ( $opts->{'handle_with_bml_ref'} && ${$opts->{'handle_with_bml_ref'}} ) {
+ $mj = LJ::S2::make_journal($u, $styleid, $view, $remote, $opts);
+ }
+
+ # intercept flag to handle_with_bml_ref and instead use siteviews
+ # FIXME: Temporary, till everything is converted.
+ if ( $opts->{'handle_with_bml_ref'} && ${$opts->{'handle_with_bml_ref'}} && $geta->{fallback} eq "s2" ) {
+ $mj = LJ::S2::make_journal($u, "siteviews", $view, $remote, $opts);
}
return $mj;
diff -r f50d67506b08 -r 4388e4653fad htdocs/misc/siteviews.bml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/misc/siteviews.bml Sun Sep 06 18:04:56 2009 +0000
@@ -0,0 +1,23 @@
+<?_code
+#
+# misc/siteviews.bml
+#
+# Internal page to run bml code from a pnote through the BML parser
+# without having to duplicate a fair bit of code.
+#
+# Authors:
+# Andrea Nall <anall@andreanall.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+{
+ my $r = DW::Request->get;
+ my $code = $r->pnote( 'siteview_code' );
+ return BML::redirect($LJ::SITEROOT) unless $code;
+ return $code;
+}
+_code?>
--------------------------------------------------------------------------------

no subject