[dw-free] Define and implement new user defaults
[commit: http://hg.dwscoalition.org/dw-free/rev/3bd415c4b16c]
http://bugs.dwscoalition.org/show_bug.cgi?id=372
Update defaults for new accounts, and lots of work to update the code to
call proper LJ::User functions instead of intuiting defaults directly.
Patch by
janinedog.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=372
Update defaults for new accounts, and lots of work to update the code to
call proper LJ::User functions instead of intuiting defaults directly.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/fingerd.pl
- cgi-bin/DW/Hooks/NavStrip.pm
- cgi-bin/LJ/CProd/ControlStrip.pm
- cgi-bin/LJ/M/ProfilePage.pm
- cgi-bin/LJ/Setting/CommentIP.pm
- cgi-bin/LJ/User.pm
- cgi-bin/LJ/Widget/NavStripChooser.pm
- cgi-bin/talklib.pl
- cgi-bin/weblib.pl
- etc/config.pl
- htdocs/manage/profile/index.bml
- htdocs/manage/settings/index.bml
- htdocs/multisearch.bml
- htdocs/talkpost.bml
-------------------------------------------------------------------------------- diff -r 2620ad1e9a33 -r 3bd415c4b16c bin/fingerd.pl --- a/bin/fingerd.pl Wed Mar 04 07:56:12 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -#!/usr/bin/perl -# -# finger server. -# -# accepts two optional arguments, host and port. -# doesn't daemonize. -# -# -# <LJDEP> -# lib: Socket::, Text::Wrap, cgi-bin/ljlib.pl -# </LJDEP> - -my $bindhost = shift @ARGV; -my $port = shift @ARGV; - -unless ($bindhost) { - $bindhost = "0.0.0.0"; -} - -require "$ENV{'LJHOME'}/cgi-bin/ljlib.pl"; - -use Socket; -use Text::Wrap; - -$SIG{'INT'} = sub { - print "Interrupt caught!\n"; - close FH; - close CL; - exit; -}; - -my $proto = getprotobyname('tcp'); -socket(FH, PF_INET, SOCK_STREAM, $proto) || die $!; - -$port ||= 79; -my $localaddr = inet_aton($bindhost); -my $sin = sockaddr_in($port, $localaddr); -setsockopt (FH,SOL_SOCKET,SO_REUSEADDR,1) or - die "setsockopt() failed: $!\n"; -bind (FH, $sin) || die $!; - -listen(FH, 10); - -while (LJ::start_request()) -{ - accept(CL, FH) || die $!; - - my $line = <CL>; - chomp $line; - $line =~ s/\0//g; - $line =~ s/\s//g; - - if ($line eq "") { - print CL "Welcome to the $LJ::SITENAME finger server! - -You can make queries in the following form: - - \@$LJ::DOMAIN - this help message - user\@$LJ::DOMAIN - their userinfo -"; - close CL; - next; - } - - my $dbr = LJ::get_dbh("slave", "master"); - - if ($line =~ /^(\w{1,15})$/) { - # userinfo! - my $user = $1; - my $quser = $dbr->quote($user); - my $sth = $dbr->prepare("SELECT user, has_bio, caps, userid, name, email, bdate, allow_infoshow FROM user WHERE user=$quser"); - $sth->execute; - my $u = $sth->fetchrow_hashref; - unless ($u) { - print CL "\nUnknown user ($user)\n"; - close CL; - next; - } - - my $bio; - if ($u->{'has_bio'} eq "Y") { - $sth = $dbr->prepare("SELECT bio FROM userbio WHERE userid=$u->{'userid'}"); - $sth->execute; - ($bio) = $sth->fetchrow_array; - } - delete $u->{'has_bio'}; - - $u->{'accttype'} = LJ::name_caps($u->{'caps'}); - - if ($u->{'allow_infoshow'} eq "Y") { - LJ::load_user_props($dbr, $u, "opt_whatemailshow", - "country", "state", "city", "zip", - "aolim", "icq", "url", "urlname", - "yahoo", "msn"); - } else { - $u->{'opt_whatemailshow'} = "N"; - } - delete $u->{'allow_infoshow'}; - - if ($u->{'opt_whatemailshow'} eq "L") { - delete $u->{'email'}; - } - if ($LJ::USER_EMAIL && LJ::get_cap($u, "useremail")) { - if ($u->{'email'}) { $u->{'email'} .= ", "; } - $u->{'email'} .= "$user\@$LJ::USER_DOMAIN"; - } - - if ($u->{'opt_whatemailshow'} eq "N") { - delete $u->{'email'}; - } - delete $u->{'opt_whatemailshow'}; - - my $max = 1; - foreach (keys %$u) { - if (length($_) > $max) { $max = length($_); } - } - $max++; - - delete $u->{'caps'}; - - print CL "\nUserinfo for $user...\n\n"; - foreach my $k (sort keys %$u) { - printf CL "%${max}s : %s\n", $k, $u->{$k}; - } - - if ($bio) { - $bio =~ s/^\s+//; - $bio =~ s/\s+$//; - print CL "\nBio:\n\n"; - $Text::Wrap::columns = 77; - print CL Text::Wrap::wrap(" ", " ", $bio); - } - print CL "\n\n"; - - close CL; - next; - - } - - print CL "Unsupported/unimplemented query type: $line\n"; - print CL "length: ", length($line), "\n"; - close CL; - next; -} diff -r 2620ad1e9a33 -r 3bd415c4b16c cgi-bin/DW/Hooks/NavStrip.pm --- a/cgi-bin/DW/Hooks/NavStrip.pm Wed Mar 04 07:56:12 2009 +0000 +++ b/cgi-bin/DW/Hooks/NavStrip.pm Wed Mar 04 08:04:40 2009 +0000 @@ -51,12 +51,7 @@ LJ::register_hook( 'show_control_strip', if ( $remote ) { - # TODO: make this default admin-settable from the UI? - # Logged-in defaults: on for journals they aren't watching, - # comms they aren't members of. Off everywhere else - my $display = defined $remote->prop( 'control_strip_display' ) - ? $remote->prop( 'control_strip_display' ) - : $pagemask{'community.notbelongto'} | $pagemask{'journal.notwatching'}; + my $display = $remote->control_strip_display; return undef unless $display; # customized comment pages (both entry and reply) @@ -84,8 +79,7 @@ LJ::register_hook( 'show_control_strip', : $display & $pagemask{'journal.notwatching'}; } else { - # Logged-out defaults: off everywhere (empty == off) - my $display = $journal->prop( 'control_strip_display' ); + my $display = $journal->control_strip_display; return undef unless $display; return $r->note( 'view' ) eq 'read' diff -r 2620ad1e9a33 -r 3bd415c4b16c cgi-bin/LJ/CProd/ControlStrip.pm --- a/cgi-bin/LJ/CProd/ControlStrip.pm Wed Mar 04 07:56:12 2009 +0000 +++ b/cgi-bin/LJ/CProd/ControlStrip.pm Wed Mar 04 08:04:40 2009 +0000 @@ -3,7 +3,7 @@ use base 'LJ::CProd'; sub applicable { my ($class, $u) = @_; - return 0 if defined $u->prop("control_strip_display"); + return 0 if defined $u->control_strip_display; return 1; } diff -r 2620ad1e9a33 -r 3bd415c4b16c cgi-bin/LJ/M/ProfilePage.pm --- a/cgi-bin/LJ/M/ProfilePage.pm Wed Mar 04 07:56:12 2009 +0000 +++ b/cgi-bin/LJ/M/ProfilePage.pm Wed Mar 04 08:04:40 2009 +0000 @@ -32,7 +32,7 @@ sub _init { ### load user props. some don't apply to communities { - my @props = qw(opt_whatemailshow country state city zip renamedto + my @props = qw(country state city zip renamedto journaltitle journalsubtitle public_key url urlname opt_hidefriendofs dont_load_members opt_blockrobots adult_content admin_content_flag diff -r 2620ad1e9a33 -r 3bd415c4b16c cgi-bin/LJ/Setting/CommentIP.pm --- a/cgi-bin/LJ/Setting/CommentIP.pm Wed Mar 04 07:56:12 2009 +0000 +++ b/cgi-bin/LJ/Setting/CommentIP.pm Wed Mar 04 08:04:40 2009 +0000 @@ -25,7 +25,7 @@ sub option { my ($class, $u, $errs, $args) = @_; my $key = $class->pkgkey; - my $commentip = $class->get_arg($args, "commentip") || $u->prop("opt_logcommentips"); + my $commentip = $class->get_arg($args, "commentip") || $u->opt_logcommentips; my @options = ( N => $class->ml('setting.commentip.option.select.none'), @@ -47,7 +47,7 @@ sub save { my ($class, $u, $args) = @_; my $val = $class->get_arg($args, "commentip"); - $val = "N" unless $val =~ /^[NSA]$/; + $val = '' unless $val =~ /^[NSA]$/; $u->set_prop( opt_logcommentips => $val ); diff -r 2620ad1e9a33 -r 3bd415c4b16c cgi-bin/LJ/User.pm --- a/cgi-bin/LJ/User.pm Wed Mar 04 07:56:12 2009 +0000 +++ b/cgi-bin/LJ/User.pm Wed Mar 04 08:04:40 2009 +0000 @@ -258,15 +258,21 @@ sub create_personal { # now flag as underage (and set O to mean was old or Y to mean was young) $u->underage(1, $opts{ofage} ? 'O' : 'Y', 'account creation') if $opts{underage}; - # For settings that are to be set explicitly - # on create, with more private settings for non-adults - if ($u->underage || $u->is_child) { - $u->set_prop("opt_findbyemail", 'N'); - } elsif ($u->is_minor) { - $u->set_prop("opt_findbyemail", 'H'); - } else { - $u->set_prop("opt_findbyemail", 'Y'); - } + # subscribe to default events + $u->subscribe( event => 'OfficialPost', method => 'Inbox' ); + $u->subscribe( event => 'OfficialPost', method => 'Email' ) if $opts{news}; + $u->subscribe( event => 'JournalNewComment', journal => $u, method => 'Inbox' ); + $u->subscribe( event => 'JournalNewComment', journal => $u, method => 'Email' ); + $u->subscribe( event => 'AddedToCircle', journal => $u, method => 'Inbox' ); + $u->subscribe( event => 'AddedToCircle', journal => $u, method => 'Email' ); + # inbox notifications for PMs are on for everyone automatically + $u->subscribe( event => 'UserMessageRecvd', journal => $u, method => 'Email' ); + $u->subscribe( event => 'InvitedFriendJoins', journal => $u, method => 'Inbox' ); + $u->subscribe( event => 'InvitedFriendJoins', journal => $u, method => 'Email' ); + $u->subscribe( event => 'CommunityInvite', journal => $u, method => 'Inbox' ); + $u->subscribe( event => 'CommunityInvite', journal => $u, method => 'Email' ); + $u->subscribe( event => 'CommunityJoinRequest', journal => $u, method => 'Inbox' ); + $u->subscribe( event => 'CommunityJoinRequest', journal => $u, method => 'Email' ); return $u; } @@ -2088,6 +2094,55 @@ sub _lazy_migrate_infoshow { } +sub control_strip_display { + my $u = shift; + + # return prop value if it exists and is valid + my $prop_val = $u->prop( 'control_strip_display' ); + return 0 if $prop_val eq 'none'; + return $prop_val if $prop_val =~ /^\d+$/; + + # otherwise, return the default: all options checked + my $ret; + my @pageoptions = LJ::run_hook( 'page_control_strip_options' ); + for ( my $i = 0; $i < scalar @pageoptions; $i++ ) { + $ret |= 1 << $i; + } + + return $ret ? $ret : 0; +} + + +sub opt_logcommentips { + my $u = shift; + + # return prop value if it exists and is valid + my $prop_val = $u->prop( 'opt_logcommentips' ); + return $prop_val if $prop_val =~ /^[NSA]$/; + + # otherwise, return the default: log for all comments + return 'A'; +} + + +sub opt_whatemailshow { + my $u = shift; + + my $user_email = $LJ::USER_EMAIL && $u->get_cap( 'useremail' ) ? 1 : 0; + + # return prop value if it exists and is valid + my $prop_val = $u->prop( 'opt_whatemailshow' ); + if ( $user_email ) { + return $prop_val if $prop_val =~ /^[ALBN]$/; + } else { + return $prop_val if $prop_val =~ /^[AN]$/; + } + + # otherwise, return the default: no email shown + return 'N'; +} + + ######################################################################## ### 8. Formatting Content Shown to Users @@ -3217,7 +3272,7 @@ sub emails_visible { # security controls return () unless $u->share_contactinfo($remote); - my $whatemail = $u->prop("opt_whatemailshow"); + my $whatemail = $u->opt_whatemailshow; my $useremail_cap = LJ::get_cap($u, 'useremail'); # some classes of users we want to have their contact info hidden @@ -3230,16 +3285,16 @@ sub emails_visible { return $active && (time() - $active) > $hide_after * 86400; }; - return () if $u->{'opt_whatemailshow'} eq "N" || - $u->{'opt_whatemailshow'} eq "L" && ($u->prop("no_mail_alias") || ! $useremail_cap || ! $LJ::USER_EMAIL) || + return () if $whatemail eq "N" || + $whatemail eq "L" && ($u->prop("no_mail_alias") || ! $useremail_cap || ! $LJ::USER_EMAIL) || $hide_contactinfo->(); my @emails = ($u->email_raw); - if ($u->{'opt_whatemailshow'} eq "L") { + if ($whatemail eq "L") { @emails = (); } if ($LJ::USER_EMAIL && $useremail_cap) { - unless ($u->{'opt_whatemailshow'} eq "A" || $u->prop('no_mail_alias')) { + unless ($whatemail eq "A" || $u->prop('no_mail_alias')) { push @emails, "$u->{'user'}\@$LJ::USER_DOMAIN"; } } @@ -8201,10 +8256,6 @@ sub make_journal push @needed_props, @{$LJ::viewinfo{$eff_view}->{'owner_props'}}; } - if ($eff_view eq "reply") { - push @needed_props, "opt_logcommentips"; - } - $u->preload_props(@needed_props); # if the remote is the user to be viewed, make sure the $remote diff -r 2620ad1e9a33 -r 3bd415c4b16c cgi-bin/LJ/Widget/NavStripChooser.pm --- a/cgi-bin/LJ/Widget/NavStripChooser.pm Wed Mar 04 07:56:12 2009 +0000 +++ b/cgi-bin/LJ/Widget/NavStripChooser.pm Wed Mar 04 08:04:40 2009 +0000 @@ -27,12 +27,9 @@ sub render_body { my %pagemask = map { $pageoptions[$_] => 1 << $_ } 0..$#pageoptions; - # TODO: make this default admin-settable from the UI? # choose where to display/see it - my $display = defined $u->prop( 'control_strip_display' ) - ? $u->prop( 'control_strip_display' ) - : $pagemask{'community.notbelongto'} | $pagemask{'journal.notwatching'}; - + my $display = $u->control_strip_display; + foreach my $pageoption ( @pageoptions ) { my $for_html = $pageoption; $for_html =~ tr/\./_/; @@ -183,10 +180,10 @@ sub handle_post { my %override; my $post_fields_of_parent = LJ::Widget->post_fields_of_widget("CustomizeTheme"); - my ($given_control_strip_color, $given_control_strip_display); + my ( $given_control_strip_color, $given_control_strip_display, $props ); if ($post_fields_of_parent->{reset}) { $given_control_strip_color = ""; - $given_control_strip_display = ""; + $props->{control_strip_display} = ""; $override{control_strip_bgcolor} = ""; $override{control_strip_fgcolor} = ""; $override{control_strip_bordercolor} = ""; @@ -195,16 +192,14 @@ sub handle_post { $given_control_strip_color = $post->{control_strip_color}; $given_control_strip_display |= $_+0 foreach split( /\0/, $post->{control_strip_display} ); + $props->{control_strip_display} = $given_control_strip_display ? $given_control_strip_display : 'none'; } my $color = $given_control_strip_color; - my $props; # we only want to store dark or light in the user props $props->{control_strip_color} = $color if $color eq 'light' || $color eq 'dark'; - # Stringify 0, so it will be stored. Hacky, but it works. - $props->{control_strip_display} = $given_control_strip_display ? $given_control_strip_display : "0 "; - + foreach my $uprop ( qw/control_strip_color control_strip_display/ ) { $u->set_prop($uprop, $props->{$uprop}); } diff -r 2620ad1e9a33 -r 3bd415c4b16c cgi-bin/talklib.pl --- a/cgi-bin/talklib.pl Wed Mar 04 07:56:12 2009 +0000 +++ b/cgi-bin/talklib.pl Wed Mar 04 08:04:40 2009 +0000 @@ -1837,11 +1837,11 @@ LOGIN $ret .= "<input type='checkbox' name='do_spellcheck' value='1' id='spellcheck' /> <label for='spellcheck'>$BML::ML{'talk.spellcheck'}</label>"; } - if ($journalu->{'opt_logcommentips'} eq "A") { + if ($journalu->opt_logcommentips eq "A") { $ret .= "<br />$BML::ML{'.logyourip'}"; $ret .= LJ::help_icon_html("iplogging", " "); } - if ($journalu->{'opt_logcommentips'} eq "S") { + if ($journalu->opt_logcommentips eq "S") { $ret .= "<br />$BML::ML{'.loganonip'}"; $ret .= LJ::help_icon_html("iplogging", " "); } @@ -2595,8 +2595,8 @@ sub enter_comment { $talkprop{'picture_keyword'} = $comment->{picture_keyword}; $talkprop{'opt_preformatted'} = $comment->{preformat} ? 1 : 0; - if ($journalu->{'opt_logcommentips'} eq "A" || - ($journalu->{'opt_logcommentips'} eq "S" && $comment->{usertype} ne "user")) + if ($journalu->opt_logcommentips eq "A" || + ($journalu->opt_logcommentips eq "S" && $comment->{usertype} ne "user")) { if (LJ::is_web_context()) { my $ip = BML::get_remote_ip(); @@ -2875,7 +2875,6 @@ sub init { LJ::load_userids_multiple([ $item->{'posterid'} => \$init->{entryu}, ], [ $journalu ]); - LJ::load_user_props($journalu, "opt_logcommentips"); if ($form->{'userpost'} && $form->{'usertype'} ne "user") { unless ($form->{'usertype'} eq "cookieuser" && @@ -3455,7 +3454,7 @@ sub edit_comment { $comment_obj->set_prop_raw( edit_time => "UNIX_TIMESTAMP()" ); # set poster IP separately since it has special conditions - my $opt_logcommentips = $comment_obj->journal->prop('opt_logcommentips'); + my $opt_logcommentips = $comment_obj->journal->opt_logcommentips; if ($opt_logcommentips eq "A" || ($opt_logcommentips eq "S" && $comment->{usertype} ne "user")) { $comment_obj->set_poster_ip; } diff -r 2620ad1e9a33 -r 3bd415c4b16c cgi-bin/weblib.pl --- a/cgi-bin/weblib.pl Wed Mar 04 07:56:12 2009 +0000 +++ b/cgi-bin/weblib.pl Wed Mar 04 08:04:40 2009 +0000 @@ -756,8 +756,7 @@ sub create_qr_div { $qrhtml .= "</label>"; } - LJ::load_user_props($u, 'opt_logcommentips'); - if ($u->{'opt_logcommentips'} eq 'A') { + if ($u->opt_logcommentips eq 'A') { $qrhtml .= '<br />'; $qrhtml .= LJ::deemp(BML::ml('/talkpost.bml.logyourip')); $qrhtml .= LJ::help_icon_html("iplogging", " "); diff -r 2620ad1e9a33 -r 3bd415c4b16c etc/config.pl --- a/etc/config.pl Wed Mar 04 07:56:12 2009 +0000 +++ b/etc/config.pl Wed Mar 04 08:04:40 2009 +0000 @@ -210,6 +210,7 @@ free_create => 1, 'interests-findsim' => 0, memories => 0, + opt_findbyemail => 1, 'show-talkleft' => 0, 'stats-recentupdates' => 0, 'stats-newjournals' => 0, @@ -826,6 +827,13 @@ # Pagination for allpics.bml page. -1 means unlimited. # $ALLPICS_PAGESIZE = 20; + + # initial settings for new users + %USER_INIT = ( + opt_whocanreply => 'reg', + opt_mangleemail => 'Y', + moodthemeid => 7, + ); } 1; diff -r 2620ad1e9a33 -r 3bd415c4b16c htdocs/manage/profile/index.bml --- a/htdocs/manage/profile/index.bml Wed Mar 04 07:56:12 2009 +0000 +++ b/htdocs/manage/profile/index.bml Wed Mar 04 08:04:40 2009 +0000 @@ -55,8 +55,7 @@ body<= # load user props LJ::load_user_props( $u, { use_master => 1 }, - qw/ opt_whatemailshow - country state city zip timezone + qw/ country state city zip timezone icq aolim yahoo msn url jabber google_talk skype gizmo urlname gender last_fm_user opt_hidefriendofs @@ -336,7 +335,7 @@ body<= # opt_whatemailshow $ret .= "<br />\n$ML{'.fn.emaildisplay'}: "; - my $cur = $u->{'opt_whatemailshow'}; + my $cur = $u->opt_whatemailshow; my @vals = ( ($LJ::USER_EMAIL && LJ::get_cap($u, "useremail")) ? ("A" => BML::ml(".email.opt.prime"), "L" => BML::ml(".email.opt.lj"), diff -r 2620ad1e9a33 -r 3bd415c4b16c htdocs/manage/settings/index.bml --- a/htdocs/manage/settings/index.bml Wed Mar 04 07:56:12 2009 +0000 +++ b/htdocs/manage/settings/index.bml Wed Mar 04 08:04:40 2009 +0000 @@ -108,7 +108,6 @@ body<= LJ::Setting::CommentCaptcha LJ::Setting::CommentIP LJ::Setting::Display::BanUsers - LJ::Setting::FindByEmail )], }, history => { diff -r 2620ad1e9a33 -r 3bd415c4b16c htdocs/multisearch.bml --- a/htdocs/multisearch.bml Wed Mar 04 07:56:12 2009 +0000 +++ b/htdocs/multisearch.bml Wed Mar 04 08:04:40 2009 +0000 @@ -153,8 +153,7 @@ }, undef, $email); } if (my $u = LJ::load_userid($uid)) { - LJ::load_user_props($u, "opt_whatemailshow"); - if ($u->{'opt_whatemailshow'} eq "A" || $u->{'opt_whatemailshow'} eq "B") { + if ($u->opt_whatemailshow eq "A" || $u->opt_whatemailshow eq "B") { if ($output eq "foaf") { return BML::redirect(LJ::journal_base($u) . '/data/foaf'); } else { diff -r 2620ad1e9a33 -r 3bd415c4b16c htdocs/talkpost.bml --- a/htdocs/talkpost.bml Wed Mar 04 07:56:12 2009 +0000 +++ b/htdocs/talkpost.bml Wed Mar 04 08:04:40 2009 +0000 @@ -144,7 +144,7 @@ body<= return if LJ::bad_password_redirect(); - my @user_props = ("opt_logcommentips", "opt_whoscreened"); + my @user_props = ("opt_whoscreened"); push @user_props, qw( opt_blockrobots adult_content admin_content_flag ) if $u->is_visible; $u->preload_props(@user_props); if (!$u->is_visible || $u->should_block_robots || ($entry && $entry->should_block_robots)) { --------------------------------------------------------------------------------