Adds two new options to let you choose whether to view journals and
entries (separate options) in your own style, in the light style, or in the
original style (default). URL parameters still override, so you can choose to
have entries show up in light style by default, but still get a look at the
original formatting by adding ?style=original. Also adds links to other view
formats in the nav strip as appropriate.
Patch by foxfirefey.
diffs (635 lines):
diff -r cc1671fdf70e -r e8e390fd9d08 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat Thu Dec 30 19:54:55 2010 +0800
+++ b/bin/upgrading/en.dat Fri Dec 31 14:51:57 2010 +0800
@@ -2788,6 +2788,24 @@ setting.display.username.option.list=See
setting.display.username.option.openidusername=(internal username: [[user]])
+setting.display.viewentrystyle.label=Entry View Style
+
+setting.display.viewentrystyle.option=When viewing entry pages (including
yours), use this style:
+
+setting.display.viewjournalstyle.label=Journal View Style
+
+setting.display.viewjournalstyle.option=When viewing journals (including
yours), use this style:
+
+setting.display.viewstyle.invalid=Invalid style view setting option
+
+setting.display.viewstyle.original=Original style
+
+setting.display.viewstyle.site=Site skin
+
+setting.display.viewstyle.mine=My own style
+
+setting.display.viewstyle.light=Light format
+
setting.emailalias.label=Email Alias
setting.emailalias.option=Receive email sent to [[use...@[[domain]]
@@ -4237,13 +4255,17 @@ web.controlstrip.nouserpic.alt=Upload Us
web.controlstrip.nouserpic.title=Edit Userpics
-web.controlstrip.reloadpage=Reload page in:
-
-web.controlstrip.reloadpage.lightstyle=light style
-
-web.controlstrip.reloadpage.mystyle=my style
-
-web.controlstrip.reloadpage.origstyle=original style
+web.controlstrip.reloadpage2=Reload page in style:
+
+web.controlstrip.reloadpage.originalstyle=original
+
+web.controlstrip.reloadpage.lightstyle2=light
+
+web.controlstrip.reloadpage.mystyle2=mine
+
+web.controlstrip.reloadpage.sitestyle=site
+
+web.controlstrip.reloadpage.origstyle2=original
web.controlstrip.select.friends.all=All Subscriptions
diff -r cc1671fdf70e -r e8e390fd9d08 bin/upgrading/proplists.dat
--- a/bin/upgrading/proplists.dat Thu Dec 30 19:54:55 2010 +0800
+++ b/bin/upgrading/proplists.dat Fri Dec 31 14:51:57 2010 +0800
@@ -886,6 +886,22 @@ userproplist.opt_usesharedpic:
multihomed: 0
prettyname: Use Shared Journal Pic
+userproplist.opt_viewentrystyle:
+ cldversion: 4
+ datatype: char
+ des: Preference for the default style for viewing entries. O for original, S
for site, M for mine, L for light.
+ indexed: 0
+ multihomed: 0
+ prettyname: View Entry Style
+
+userproplist.opt_viewjournalstyle:
+ cldversion: 4
+ datatype: char
+ des: Preference for the default style for viewing journals. O for original,
S for site, M for mine, L for light.
+ indexed: 0
+ multihomed: 0
+ prettyname: View Journal Style
+
userproplist.opt_whatemailshow:
cldversion: 4
datatype: char
@@ -1125,7 +1141,7 @@ userproplist.urlname:
indexed: 0
multihomed: 0
prettyname: Website Name
-
+
userproplist.who_invited:
cldversion: 4
datatype: char
diff -r cc1671fdf70e -r e8e390fd9d08 cgi-bin/DW/Setting/ViewEntryStyle.pm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Setting/ViewEntryStyle.pm Fri Dec 31 14:51:57 2010 +0800
@@ -0,0 +1,80 @@
+#!/usr/bin/perl
+#
+# DW::Setting::ViewEntryStyle
+#
+# LJ::Setting module for specifying what style entries are
+# displayed in for a user, such as mine, light, site, or original.
+#
+# Authors:
+# foxfirefey <[email protected]>
+#
+# Copyright (c) 2010 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'.
+#
+
+package DW::Setting::ViewEntryStyle;
+use base 'LJ::Setting';
+use strict;
+use warnings;
+
+sub should_render {
+ my ( $class, $u ) = @_;
+
+ return $u->is_community ? 0 : 1;
+}
+
+sub label {
+ my ( $class, $u ) = @_;
+
+ return $class->ml( 'setting.display.viewentrystyle.label' );
+}
+
+sub option {
+ my ( $class, $u, $errs, $args ) = @_;
+ my $key = $class->pkgkey;
+
+ my $viewentrystyle = $class->get_arg( $args, "viewentrystyle" ) ||
$u->opt_viewentrystyle;
+
+ my @options = (
+ O => $class->ml( 'setting.display.viewstyle.original' ),
+ S => $class->ml( 'setting.display.viewstyle.site' ),
+ M => $class->ml( 'setting.display.viewstyle.mine' ),
+ L => $class->ml( 'setting.display.viewstyle.light' ),
+ );
+
+ my $ret = "<label for='${key}viewentrystyle'>" . $class->ml(
'setting.display.viewentrystyle.option' ) . "</label> ";
+ $ret .= LJ::html_select({
+ name => "${key}viewentrystyle",
+ id => "${key}viewentrystyle",
+ selected => $viewentrystyle,
+ }, @options );
+
+ return $ret;
+}
+
+sub error_check {
+ my ( $class, $u, $args ) = @_;
+ my $val = $class->get_arg( $args, "viewentrystyle" );
+ $class->errors( viewentrystyle => $class->ml(
'.setting.display.viewstyle.invalid' ) ) unless $val =~ /^[OSML]$/;
+ return 1;
+}
+
+sub save {
+ my ( $class, $u, $args ) = @_;
+ $class->error_check( $u, $args );
+
+ my $val = $class->get_arg( $args, "viewentrystyle" );
+
+ # don't save if this is the value we are already using
+ return 1 if $u->prop( 'opt_viewentrystyle' ) and $val eq $u->prop(
'opt_viewentrystyle' );
+
+ # delete if we are turning it back to the default
+ $val = "" if $val eq "O";
+
+ $u->set_prop( "opt_viewentrystyle", $val );
+}
+
+1;
diff -r cc1671fdf70e -r e8e390fd9d08 cgi-bin/DW/Setting/ViewJournalStyle.pm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Setting/ViewJournalStyle.pm Fri Dec 31 14:51:57 2010 +0800
@@ -0,0 +1,81 @@
+#!/usr/bin/perl
+#
+# DW::Setting::ViewJournalStyle
+#
+# LJ::Setting module for specifying what style entries are
+# displayed in for a user.
+#
+# Authors:
+# foxfirefey <[email protected]>
+#
+# Copyright (c) 2010 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'.
+#
+
+package DW::Setting::ViewJournalStyle;
+use base 'LJ::Setting';
+use strict;
+use warnings;
+
+sub should_render {
+ my ( $class, $u ) = @_;
+
+ return $u->is_community ? 0 : 1;
+}
+
+sub label {
+ my ( $class, $u ) = @_;
+
+ return $class->ml( 'setting.display.viewjournalstyle.label' );
+}
+
+sub option {
+ my ( $class, $u, $errs, $args ) = @_;
+ my $key = $class->pkgkey;
+
+ my $viewjournalstyle = $class->get_arg( $args, "viewjournalstyle" ) ||
$u->opt_viewjournalstyle;
+
+ my @options = (
+ O => $class->ml( 'setting.display.viewstyle.original' ),
+ M => $class->ml( 'setting.display.viewstyle.mine' ),
+ # Todo: make this a viable option! Needs some styling.
+ #S => $class->ml( 'setting.display.viewstyle.site' ),
+ L => $class->ml( 'setting.display.viewstyle.light' ),
+ );
+
+ my $ret = "<label for='${key}viewjournalstyle'>" . $class->ml(
'setting.display.viewjournalstyle.option' ) . "</label> ";
+ $ret .= LJ::html_select({
+ name => "${key}viewjournalstyle",
+ id => "${key}viewjournalstyle",
+ selected => $viewjournalstyle,
+ }, @options );
+
+ return $ret;
+}
+
+sub error_check {
+ my ( $class, $u, $args ) = @_;
+ my $val = $class->get_arg( $args, "viewjournalstyle" );
+ $class->errors( viewjournalstyle => $class->ml(
'.setting.display.viewstyle.invalid' ) ) unless $val =~ /^[OSML]$/;
+ return 1;
+}
+
+sub save {
+ my ( $class, $u, $args ) = @_;
+ $class->error_check( $u, $args );
+
+ my $val = $class->get_arg( $args, "viewjournalstyle" );
+
+ # don't save if this is the value we are already using
+ return 1 if $u->prop( 'opt_viewjournalstyle' ) and $val eq $u->prop(
'opt_viewjournalstyle' );
+
+ # delete if we are turning it back to the default
+ $val = "" if $val eq "O";
+
+ $u->set_prop( "opt_viewjournalstyle", $val );
+}
+
+1;
diff -r cc1671fdf70e -r e8e390fd9d08 cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm Thu Dec 30 19:54:55 2010 +0800
+++ b/cgi-bin/LJ/User.pm Fri Dec 31 14:51:57 2010 +0800
@@ -5526,6 +5526,13 @@ sub revoke_priv_all {
return 1;
}
+sub opt_viewentrystyle {
+ return ( $_[0]->prop( 'opt_viewentrystyle' ) || "O" );
+}
+
+sub opt_viewjournalstyle {
+ return ( $_[0]->prop( 'opt_viewjournalstyle' ) || "O" );
+}
########################################################################
### 24. Styles and S2-Related Functions
@@ -5712,6 +5719,27 @@ sub view_priv_check {
return wantarray ? ( $viewall, $viewsome ) : $viewsome;
}
+=head2 C<< $u->viewing_style( $view ) >>
+Takes a user and a view argument and returns what that user's preferred
+style is for a given view.
+=cut
+sub viewing_style {
+ my ( $u, $view ) = @_;
+
+ $view ||= 'entry';
+
+ my %style_types = ( O => "original", M => "mine", S => "site", L =>
"light" );
+
+ my $style;
+ if ( $view eq "entry" ) {
+ $style = $style_types{ $u->opt_viewentrystyle };
+ } else {
+ $style = $style_types{ $u->opt_viewjournalstyle };
+ }
+ $style ||= 'original';
+
+ return $style;
+}
########################################################################
### 25. Subscription, Notifiction, and Messaging Functions
@@ -8541,10 +8569,6 @@ sub make_journal {
}
LJ::set_active_journal($u);
- # S1 style hashref. won't be loaded now necessarily,
- # only if via customview.
- my $style;
-
my ($styleid);
if ($opts->{'styleid'}) { # s1 styleid
confess 'S1 was removed, sorry.';
@@ -8568,7 +8592,7 @@ sub make_journal {
my @needed_props = ("stylesys", "s2_style", "url", "urlname",
"opt_nctalklinks",
"renamedto", "opt_blockrobots", "opt_usesharedpic",
"icbm",
"journaltitle", "journalsubtitle", "external_foaf_url",
- "adult_content");
+ "adult_content", "opt_viewjournalstyle",
"opt_viewentrystyle");
# preload props the view creation code will need later (combine two
selects)
if (ref $LJ::viewinfo{$eff_view}->{'owner_props'} eq "ARRAY") {
@@ -8584,7 +8608,10 @@ sub make_journal {
$remote->{opt_nctalklinks} = $u->{opt_nctalklinks}
if $remote && $remote->equals( $u );
+ # What style are we shooting for, based on user preferences and get
arguments?
+ my $stylearg = LJ::determine_viewing_style( $geta, $view, $remote );
my $stylesys = 1;
+
if ($styleid == -1) {
my $get_styleinfo = sub {
@@ -8623,9 +8650,8 @@ sub make_journal {
return ( 2, $geta->{s2id} ) if LJ::S2::style_is_public( $style
);
}
- # style=mine passed in GET?
- if ( $remote && ( lc( $geta->{'style'} ) eq 'mine' ) ) {
-
+ # style=mine passed in GET or userprop to use mine?
+ if ( $remote && $stylearg eq 'mine' ) {
# get remote props and decide what style remote uses
$remote->preload_props("stylesys", "s2_style");
@@ -8761,20 +8787,20 @@ sub make_journal {
# signal to LiveJournal.pm that we can't handle this
# 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->{'format'} eq
'light' || $geta->{'style'} eq 'light' ) {
+ if ( $stylesys == 1 || $stylearg eq 'site' || $stylearg 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
# type won't let them, or they really want this to fallback to bml
- if ( $remote && ( $geta->{'style'} eq 'mine' ) ) {
+ if ( $remote && ( $stylearg eq 'mine' ) ) {
$fallback = 'bml';
}
# If they specified ?format=light, it means they want a page easy
# to deal with text-only or on a mobile device. For now that means
# render it in the lynx site scheme.
- if ( $geta->{'format'} eq 'light' || $geta->{'style'} eq 'light' ) {
+ if ( $stylearg eq 'light' ) {
$fallback = 'bml';
$r->note(bml_use_scheme => 'lynx');
}
diff -r cc1671fdf70e -r e8e390fd9d08 cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl Thu Dec 30 19:54:55 2010 +0800
+++ b/cgi-bin/weblib.pl Fri Dec 31 14:51:57 2010 +0800
@@ -1124,6 +1124,29 @@ sub deemp {
"<span class='de'>$_[0]</span>";
}
+=head2 C<< LJ::determine_viewing_style( $args, $view, $u ) >>
+Takes a hashref of get args, and the current view, and an optional user.
+Returns "original", "mine", "site", or "light" as the style.
+=cut
+sub determine_viewing_style {
+ my ( $args, $view, $u ) = @_;
+
+ my $style = 'original';
+
+ # incorporate any user preferences
+ $style = $u->viewing_style( $view ) if $u;
+
+ # incorporate any style arguments
+ my %style_getargs = %{ LJ::viewing_style_opts( %$args ) };
+ $style = $style_getargs{'style'} if $style_getargs{'style'};
+
+ # keep format=light for backwards compatibility -- override and
+ # assume that somebody using it really wants the light version
+ $style = $style_getargs{'format'} if $style_getargs{'format'};
+
+ return $style;
+}
+
=head2 C<< LJ::viewing_style_args( %arguments ) >>
Takes a list of viewing styles arguments from a list, makes sure they are
valid values,
and returns them as a string that can be appended to the URL. Looks for
"s2id", "format", "style"
@@ -1150,8 +1173,8 @@ sub viewing_style_opts {
return {} unless %args;
my $valid_style_args = {
+ style => { light => 1, site => 1, mine => 1, original => 1 },
format => { light => 1 },
- style => { light => 1, site => 1, mine => 1 },
};
my %ret;
@@ -1206,6 +1229,9 @@ sub create_url {
}
$opts{keep_args} = [ keys %$orig_args ] if defined $opts{keep_args} and
$opts{keep_args} == 1;
+ $opts{keep_args} = [] if ref $opts{keep_args} ne 'ARRAY';
+
+ $opts{keep_args} = [ keys %$orig_args ] if $opts{keep_args} == 1;
$opts{keep_args} = [] if ref $opts{keep_args} ne 'ARRAY';
# Move over arguments that we need to keep
@@ -3029,48 +3055,45 @@ LOGIN_BAR
$ret .= "</td>";
}
- # search box and ?style=mine/?style=light options
+ # search box and ?style=mine/?style=light/?style=original/?style=site
options
my @view_options;
- #determine whether style is "mine", and define new uri variable to
manipulate
- #note: all expressions case-insensitive
- my $currentstylemine = ($uri =~ m/style=mine/i);
- my $newuri = LJ::ehtml( $uri );
- #manipulate destination URI for the style links
- if ($currentstylemine) {
- #if last character before style=mine is a &, it can be deleted
together with style=mine,
- #since a ? will still be in front of the other arguments in the string
- if ($newuri =~ m/\&style=mine/i) {
- $newuri =~ s/\&style=mine//i;
- } else {
- #else the last character before style=mine was a "?" and should
not be deleted.
- #also, delete "&" after style=mine if there is one
- $newuri =~ s/style=mine\&?//i;
- }
- #delete any trailing character - for example
- #trailing "?" if only "?style=mine" was present in the first place
- $newuri =~ s/\W$//;
+ # determine whether style is "mine", and define new uri variable to
manipulate
+ # note: all expressions case-insensitive
+ my $current_style = determine_viewing_style( $r->get_args, $view, $remote
);
+
+ # a quick little routine to use when cycling through the options
+ # to create the style links for the nav bar
+ sub make_style_link {
+ return create_url( undef,
+ # change the style arg
+ 'args' => { 'style' => $_[0] },
+ # keep any other existing arguments
+ 'keep_args' => 1,
+ );
}
- my $querysep2;
- #check whether newuri still has arguments to determine whether "?" or "&"
needs to be used for next argument added
- if ($newuri =~ m/\?/) {
- $querysep2 = "&";
- } else {
- $querysep2 = "?";
- }
- #appropriate links depending on whether style is "mine"
- if ($remote) {
- if ($currentstylemine) {
- push @view_options, "<a href='$newuri'>" . LJ::Lang::ml(
'web.controlstrip.reloadpage.origstyle' ) . "</a>"
- } else {
- push @view_options, "<a href='$newuri${querysep2}style=mine'>" .
LJ::Lang::ml( 'web.controlstrip.reloadpage.mystyle' ) . "</a>"
+
+ # cycle through all possibilities, add the valid ones
+ foreach my $view_type qw( mine site light original ) {
+ # only want to offer this option if user is logged in and it's not
their own journal, since
+ # original will take care of that
+ if ( $view_type eq "mine" and $current_style ne $view_type and $remote
and not $remote->equals( $journal ) ) {
+ push @view_options, "<a href='" . make_style_link( $view_type ) .
"'>" .
+ LJ::Lang::ml( 'web.controlstrip.reloadpage.mystyle2' ) .
"</a>";
+ } elsif ( $view_type eq "site" and $current_style ne $view_type and
$view eq "entry" ) {
+ push @view_options, "<a href='" . make_style_link( $view_type ) .
"'>" .
+ LJ::Lang::ml( 'web.controlstrip.reloadpage.sitestyle' ) .
"</a>";
+ } elsif ( $view_type eq "light" and $current_style ne $view_type ) {
+ push @view_options, "<a href='" . make_style_link( $view_type ) .
"'>" .
+ LJ::Lang::ml( 'web.controlstrip.reloadpage.lightstyle2' ) .
"</a>";
+ } elsif ( $view_type eq "original" and $current_style ne $view_type ) {
+ push @view_options, "<a href='" . make_style_link( $view_type ) .
"'>" .
+ LJ::Lang::ml( 'web.controlstrip.reloadpage.origstyle2' ) .
"</a>";
}
}
- #style=light available on every page that supports showing the navstrip
- push @view_options, "<a href='$newuri${querysep2}style=light'>" .
LJ::Lang::ml( 'web.controlstrip.reloadpage.lightstyle' ) . "</a>";
$ret .= "<td id='lj_controlstrip_search'>";
$ret .= LJ::Widget::Search->render;
- $ret .= LJ::Lang::ml( 'web.controlstrip.reloadpage' ) . " "
+ $ret .= LJ::Lang::ml( 'web.controlstrip.reloadpage2' ) . " "
if @view_options;
$ret .= join( " ", @view_options );
$ret .= "</td>";
diff -r cc1671fdf70e -r e8e390fd9d08 htdocs/manage/settings/index.bml
--- a/htdocs/manage/settings/index.bml Thu Dec 30 19:54:55 2010 +0800
+++ b/htdocs/manage/settings/index.bml Fri Dec 31 14:51:57 2010 +0800
@@ -69,18 +69,20 @@ body<=
desc => $ML{'.cat.display.desc'},
settings => [qw(
LJ::Setting::TimeZone
+ DW::Setting::TimeFormat
LJ::Setting::ImagePlaceholders
LJ::Setting::EmbedPlaceholders
DW::Setting::CutDisable
DW::Setting::CutInbox
LJ::Setting::EmailFormat
LJ::Setting::EntryEditor
- DW::Setting::TimeFormat
+ LJ::Setting::SiteScheme
+ DW::Setting::ViewEntryStyle
+ DW::Setting::ViewJournalStyle
+ LJ::Setting::NavStrip
LJ::Setting::NCTalkLinks
LJ::Setting::StyleMine
- LJ::Setting::NavStrip
LJ::Setting::CtxPopup
- LJ::Setting::SiteScheme
LJ::Setting::AdultContent
DW::Setting::AdultContentReason
LJ::Setting::ViewingAdultContent
diff -r cc1671fdf70e -r e8e390fd9d08 t/create-url.t
--- a/t/create-url.t Thu Dec 30 19:54:55 2010 +0800
+++ b/t/create-url.t Fri Dec 31 14:51:57 2010 +0800
@@ -1,6 +1,6 @@
# -*-perl-*-
use strict;
-use Test::More tests => 5 * 15; # replace last number with the number of
check_req calls
+use Test::More tests => 5 * 19; # replace last number with the number of
check_req calls
use lib "$ENV{LJHOME}/cgi-bin";
require 'ljlib.pl';
@@ -63,8 +63,8 @@ check_req(
foo => "bar",
bar => "baz",
s2id => 5,
+ style => "site",
format => "light",
- style => "site",
},
);
@@ -83,8 +83,8 @@ check_req(
{
foo => "bar",
bar => "kitten",
+ style => "site",
format => "light",
- style => "site",
},
);
@@ -183,6 +183,73 @@ check_req(
{},
);
+check_req(
+
"http://www.example.com/?bar=baz&s2id=5&format=light&style=site&ping=pong&no=1",
+ undef, {
+ args => {
+ foo => 'bar',
+ no => undef,
+ },
+ keep_args => 1,
+ },
+ { ssl => 0, host => "www.example.com", uri=>"/", },
+ {
+ foo => "bar",
+ bar => "baz",
+ s2id => 5,
+ format => "light",
+ style => "site",
+ ping => "pong",
+ },
+);
+
+check_req(
+
"http://www.example.com/?bar=baz&s2id=5&format=light&style=site&ping=pong&no=1",
+ undef, {
+ args => {
+ foo => 'bar',
+ no => undef,
+ },
+ keep_args => 1,
+ viewing_style => 1,
+ },
+ { ssl => 0, host => "www.example.com", uri=>"/", },
+ {
+ foo => "bar",
+ bar => "baz",
+ s2id => 5,
+ format => "light",
+ style => "site",
+ ping => "pong",
+ },
+);
+
+check_req(
+
"http://www.example.com/?bar=baz&s2id=5&format=light&style=site&ping=pong&no=1",
+ undef, {
+ args => {
+ foo => 'bar',
+ no => undef,
+ },
+ keep_args => 0,
+ },
+ { ssl => 0, host => "www.example.com", uri => "/", },
+ {
+ foo => "bar",
+ },
+);
+
+check_req(
+ "http://www.example.com/?format=light",
+ undef, {
+ keep_args => 1,
+ },
+ { ssl => 0, host => "www.example.com", uri => "/", },
+ {
+ format => "light",
+ },
+);
+
sub check_req {
my ( $url, $path, $opts, $eopts, $expected ) = @_;
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog