[livejournal] r17085: OPSC-123 Merge oauth branch to trunk
Committer: aurbanowich
OPSC-123 Merge oauth branch to trunk* stage 1 : merge trunk to branches/oauth
U branches/oauth/bin/upgrading/proplists.dat U branches/oauth/bin/upgrading/s2layers/disjointed/layout.s2 U branches/oauth/bin/upgrading/s2layers/haven/layout.s2 U branches/oauth/bin/upgrading/s2layers/refriedpaper/layout.s2 U branches/oauth/bin/upgrading/s2layers/sturdygesture/layout.s2 U branches/oauth/cgi-bin/Apache/LiveJournal.pm U branches/oauth/cgi-bin/LJ/Comment.pm U branches/oauth/cgi-bin/LJ/ESN.pm U branches/oauth/cgi-bin/LJ/Entry.pm U branches/oauth/cgi-bin/LJ/Event/PollVote.pm U branches/oauth/cgi-bin/LJ/JSON.pm U branches/oauth/cgi-bin/LJ/NewWorker/TheSchwartz.pm U branches/oauth/cgi-bin/LJ/NotificationMethod/DebugLog.pm U branches/oauth/cgi-bin/LJ/NotificationMethod/Email.pm U branches/oauth/cgi-bin/LJ/NotificationMethod/IM.pm U branches/oauth/cgi-bin/LJ/NotificationMethod/Inbox.pm U branches/oauth/cgi-bin/LJ/NotificationMethod/SMS.pm U branches/oauth/cgi-bin/LJ/PageStats.pm U branches/oauth/cgi-bin/LJ/Poll.pm U branches/oauth/cgi-bin/LJ/Request/Apache.pm U branches/oauth/cgi-bin/LJ/Request/Apache2.pm U branches/oauth/cgi-bin/LJ/S2/EntryPage.pm U branches/oauth/cgi-bin/LJ/S2/RecentPage.pm U branches/oauth/cgi-bin/LJ/S2.pm U branches/oauth/cgi-bin/LJ/Session.pm U branches/oauth/cgi-bin/LJ/Subscription.pm U branches/oauth/cgi-bin/LJ/User/Email.pm U branches/oauth/cgi-bin/LJ/User.pm U branches/oauth/cgi-bin/LJ/Widget/EntryForm.pm U branches/oauth/cgi-bin/LJ/Widget/SiteMessages.pm U branches/oauth/cgi-bin/cleanhtml.pl U branches/oauth/cgi-bin/ljfeed.pl U branches/oauth/cgi-bin/ljlib.pl U branches/oauth/cgi-bin/ljmail.pl U branches/oauth/cgi-bin/ljprotocol.pl U branches/oauth/cgi-bin/ljviews.pl U branches/oauth/cgi-bin/talklib.pl U branches/oauth/htdocs/accountstatus.bml U branches/oauth/htdocs/accountstatus.bml.text U branches/oauth/htdocs/editpics.bml U branches/oauth/htdocs/editpics.bml.text U branches/oauth/htdocs/js/basic.js U branches/oauth/htdocs/js/contextualhover.js U branches/oauth/htdocs/js/entry.js U branches/oauth/htdocs/js/lj_ippu.js U branches/oauth/htdocs/openid/approve.bml U branches/oauth/htdocs/openid/server.bml U branches/oauth/htdocs/stc/fck/fckconfig.js U branches/oauth/htdocs/support/help.bml U branches/oauth/htdocs/talkpost.bml U branches/oauth/htdocs/talkread.bml U branches/oauth/htdocs/update.bml U branches/oauth/htdocs/userinfo.bml
Modified: branches/oauth/bin/upgrading/proplists.dat
===================================================================
--- branches/oauth/bin/upgrading/proplists.dat 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/bin/upgrading/proplists.dat 2010-08-04 08:56:19 UTC (rev 17085)
@@ -1542,3 +1542,8 @@
des: explicitly prevent the system from purging this user
cldversion: 8
+userproplist.purge_external_content:
+ datatype: char
+ cldversion: 8
+ des: Should external content be deleted when journal is deleted. Two bool flags separated by comma: <delete-comments>:<delete-community-entries>
+
Modified: branches/oauth/bin/upgrading/s2layers/disjointed/layout.s2
===================================================================
--- branches/oauth/bin/upgrading/s2layers/disjointed/layout.s2 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/bin/upgrading/s2layers/disjointed/layout.s2 2010-08-04 08:56:19 UTC (rev 17085)
@@ -1030,7 +1030,7 @@
if(defined $en.mood_icon) {
var Image i = $en.mood_icon;
var string alt = $.metadata{"mood"};
- $icon = """<img src="$i.url" width="$i.width" height="$i.height" alt="$alt" title="$alt" /> """;
+ $icon = $i->as_string_ex($alt, "title='$alt' ");
}
if(size($en.tags) > 0 and $*tags_aware) {
var int count = 0;
Modified: branches/oauth/bin/upgrading/s2layers/haven/layout.s2
===================================================================
--- branches/oauth/bin/upgrading/s2layers/haven/layout.s2 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/bin/upgrading/s2layers/haven/layout.s2 2010-08-04 08:56:19 UTC (rev 17085)
@@ -1163,7 +1163,7 @@
}
if ($k == "mood" and defined $e.mood_icon) {
var Image i = $e.mood_icon;
- $val = "<img src='$i.url' width='$i.width' height='$i.height' align='middle' alt='' /> $val";
+ $val = $i->as_string_ex($i.alttext, "align='middle' ") + " " + $val;
}
println safe """<div class="current$k"><strong>$text:</strong> $val</div>""";
}
Modified: branches/oauth/bin/upgrading/s2layers/refriedpaper/layout.s2
===================================================================
--- branches/oauth/bin/upgrading/s2layers/refriedpaper/layout.s2 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/bin/upgrading/s2layers/refriedpaper/layout.s2 2010-08-04 08:56:19 UTC (rev 17085)
@@ -688,7 +688,7 @@
if(defined $en.mood_icon) {
var Image i = $en.mood_icon;
var string alt = $.metadata{"mood"};
- $icon = """<img src="$i.url" width="$i.width" height="$i.height" alt="$alt" title="$alt" /> """;
+ $icon = $i->as_string_ex($alt, "title='$alt' ");
}
if(size($en.tags) > 0 and $*tags_aware) {
var int count = 0;
Modified: branches/oauth/bin/upgrading/s2layers/sturdygesture/layout.s2
===================================================================
--- branches/oauth/bin/upgrading/s2layers/sturdygesture/layout.s2 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/bin/upgrading/s2layers/sturdygesture/layout.s2 2010-08-04 08:56:19 UTC (rev 17085)
@@ -636,7 +636,7 @@
$caption = $*text_meta_mood;
if (defined $.mood_icon) {
$i = $.mood_icon;
- $val = """<img src="$i.url" width="$i.width" height="$i.height" align="absmiddle"> $val""";
+ $val = $i->as_string_ex($i.alttext, "align='absmiddle' ") + " " + $val;
}
}
println """<div class="metadata-$k"><span style="font-weight: bold;">$caption:</span> $val</div>""";
Modified: branches/oauth/cgi-bin/Apache/LiveJournal.pm
===================================================================
--- branches/oauth/cgi-bin/Apache/LiveJournal.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/Apache/LiveJournal.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -1193,10 +1193,13 @@
};
my $size;
+ my $MAX_AGE = 86400 * 365; # one year
my $send_headers = sub {
+ my $expires_str = LJ::TimeUtil->time_to_http(time + $MAX_AGE);
LJ::Request->content_type($mime);
LJ::Request->header_out("Content-length", $size+0);
- LJ::Request->header_out("Cache-Control", "no-transform");
+ LJ::Request->header_out("Expires", $expires_str);
+ LJ::Request->header_out("Cache-Control", "public, max-age=$MAX_AGE");
LJ::Request->header_out("Last-Modified", LJ::TimeUtil->time_to_http($lastmod));
LJ::Request->send_http_header();
};
Modified: branches/oauth/cgi-bin/LJ/Comment.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/Comment.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/Comment.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -831,22 +831,24 @@
my $state = shift;
my $u = LJ::load_userid($self->{journalid});
-
+ my $nodeid = $self->{'nodeid'};
+ my $jtalkid = $self->{'jtalkid'};
my $hookname = $state eq 'D' ? 'report_cmt_delete' :
'report_cmt_update' ;
- LJ::run_hooks($hookname, $self->{'journalid'}, $self->{jtalkid});
+ LJ::run_hooks($hookname, $self->{'journalid'}, $jtalkid);
my $updated = $u->talk2_do(
nodetype => "L",
- nodeid => $self->{nodeid},
+ nodeid => $nodeid,
sql => "UPDATE talk2 SET state=? ".
"WHERE journalid=? AND jtalkid = ? ".
"AND nodetype='L' AND nodeid=? ",
- bindings => [$state, $self->{journalid}, $self->{jtalkid}, $self->{nodeid}],
+ bindings => [$state, $self->{journalid}, $jtalkid, $nodeid],
);
return undef unless $updated;
- LJ::Talk::invalidate_talk2row_memcache($u->id, $self->{jtalkid});
+ # invalidate memcache for this comment
+ LJ::Talk::invalidate_comment_cache($u->id, $nodeid, $jtalkid);
$self->{state} = $state;
}
Modified: branches/oauth/cgi-bin/LJ/ESN.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/ESN.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/ESN.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -35,19 +35,20 @@
}
sub jobs_of_unique_matching_subs {
- my ($class, $evt, @subs) = @_;
+ my ($class, $evt, $subs, $debug_args) = @_;
my %has_done = ();
+ $debug_args ||= {};
my @subjobs;
my $params = $evt->raw_params;
if ($ENV{DEBUG}) {
- warn "jobs of unique subs (@subs) matching event (@$params)\n";
+ warn "jobs of unique subs (@$subs) matching event (@$params)\n";
}
my @subs_filtered;
- foreach my $sub (@subs) {
+ foreach my $sub (@$subs) {
next unless defined $sub;
next unless $evt->available_for_user($sub->owner);
next unless $evt->matches_filter($sub);
@@ -63,12 +64,40 @@
'userid' => $s->userid + 0,
'subdump' => $s->dump,
'e_params' => $params,
+ %$debug_args,
},
);
}
return @subjobs;
}
+## class method
+## Returns list ('debug_info' => \@info)
+## May append signature of the current job to the @info
+sub _get_debug_args {
+ my $worker_class = shift;
+ my $job = shift;
+ my $append_current_job = shift;
+ my $extra_arg = shift;
+
+ return unless $LJ::DEBUG{esn_email_headers};
+
+ my $arg = $job->arg;
+ my @info = (ref $arg eq 'HASH' && $arg->{'debug_info'}) ? @{ $arg->{'debug_info'} } : ();
+
+ if ($append_current_job) {
+ my $jobid = $job->jobid;
+ my $failures = $job->failures;
+ my $grabbed_until = $job->grabbed_until;
+ my $time = time;
+ my ($short_class_name) = ($worker_class =~ /::(\w+)$/);
+ push @info, "c=$short_class_name j=$jobid f=$failures t=$time g=$grabbed_until p=$$ $extra_arg";
+ }
+
+ return ('debug_info' => \@info);
+}
+
+
# this is phase1 of processing. see doc/server/ljp.int.esn.html
package LJ::Worker::FiredEvent;
use base 'TheSchwartz::Worker';
@@ -119,6 +148,8 @@
warn "split_per_cluster=[$split_per_cluster], params=[@$params]\n";
}
+ my %debug_args = LJ::ESN::_get_debug_args($class, $job, 1, "ep=" . join(":", @$e_params));
+
# this is the slow/safe/on-error/lots-of-subscribers path
if ($ENV{FORCE_P1_P2} || $LJ::_T_ESN_FORCE_P1_P2 || $split_per_cluster) {
my @subjobs;
@@ -128,17 +159,17 @@
arg => {
'cid' => $cid,
'e_params' => $params,
+ %debug_args,
},
);
}
return $job->replace_with(@subjobs);
+ } else {
+ # the fast path, filter those max 5,000 subscriptions down to ones that match,
+ # then split right into processing those notification methods
+ my @subjobs = LJ::ESN->jobs_of_unique_matching_subs($evt, \@subs, \%debug_args);
+ return $job->replace_with(@subjobs);
}
-
- # the fast path, filter those max 5,000 subscriptions down to ones that match,
- # then split right into processing those notification methods
- my @subjobs = LJ::ESN->jobs_of_unique_matching_subs($evt, @subs);
-
- return $job->replace_with(@subjobs);
}
@@ -199,6 +230,7 @@
'evt' => $evt,
'cid' => $cid2,
'minuid' => $minuid,
+ LJ::ESN::_get_debug_args($class, $job, 1, "cid=$cid2"),
},
);
}
@@ -277,6 +309,10 @@
'evt' => $evt,
'cid' => $cid,
'minuid' => $lastuid,
+
+ ## keep exisiting debug args, but don't append signature of the current job,
+ ## because there may be up to 1000+ 'FiredMass' consequent jobs before 'ProcessSub' job
+ LJ::ESN::_get_debug_args($class, $job),
},
);
@@ -294,6 +330,7 @@
'userid' => $sub->userid,
'subdump' => $sub->dump,
'e_params' => $params,
+ LJ::ESN::_get_debug_args($class, $job, 1, "min=$minuid"),
},
);
}
@@ -324,8 +361,9 @@
# fast path: job from phase2 to phase4, skipping filtering.
if (@subs <= $LJ::ESN::MAX_FILTER_SET && ! $LJ::_T_ESN_FORCE_P2_P3 && ! $ENV{FORCE_P2_P3}) {
- my @subjobs = LJ::ESN->jobs_of_unique_matching_subs($evt, @subs);
- warn "fast path: subjobs=@subjobs\n" if $ENV{DEBUG};
+ my %debug_args = LJ::ESN::_get_debug_args($class, $job, 1, "cid=$cid fast=true");
+ my @subjobs = LJ::ESN->jobs_of_unique_matching_subs($evt, \@subs, \%debug_args);
+ warn "fast path: subjobs=@subjobs\n" if $ENV{DEBUG};
return $job->replace_with(@subjobs);
}
@@ -386,7 +424,8 @@
arg => {
'e_params' => $e_params,
'sublist' => $sublist,
- 'cid' => $cid,
+ 'cid' => $cid,
+ LJ::ESN::_get_debug_args($class, $job, 1, "cid=$cid fast=false"),
},
);
}
@@ -471,7 +510,8 @@
push @subs, $subsc;
}
- my @subjobs = LJ::ESN->jobs_of_unique_matching_subs($evt, @subs);
+ my %debug_args = LJ::ESN::_get_debug_args($class, $job, 1, "cid=$cid sl=$#$sublist");
+ my @subjobs = LJ::ESN->jobs_of_unique_matching_subs($evt, \@subs, \%debug_args);
return $job->replace_with(@subjobs) if @subjobs;
$job->completed;
}
@@ -498,24 +538,36 @@
# if the user deleted their account (or otherwise isn't visible), bail
return $job->completed unless $u->is_visible || $evt->is_significant;
+ my %opts;
if ($LJ::DEBUG{esn_email_headers}) {
- # if debugging esn emails, stick the debug headers
- # in the subscription object so the email notifier can access them
- my $debug_headers = {
- 'X-ESN_Debug-sch_jobid' => $job->jobid,
- 'X-ESN_Debug-subid' => $subdump,
- 'X-ESN_Debug-eparams' => join(', ', @$eparams),
- 'X-ESN_Debug-failures' => $job->failures,
- 'X-ESN_Debug-pid' => $$,
- };
+ my $subscription_signature = join(",", (
+ "u=$subsc->{'userid'}",
+ "s=$subsc->{'subid'}",
+ "i=$subsc->{'is_dirty'}",
+ "j=$subsc->{'journalid'}",
+ "e=$subsc->{'etypeid'}",
+ "a1=$subsc->{'arg1'}",
+ "a2=$subsc->{'arg2'}",
+ "n=$subsc->{'ntypeid'}",
+ "c=$subsc->{'createtime'}",
+ "x=$subsc->{'expiretime'}",
+ "f=$subsc->{'flags'}",
+ ));
+ my (undef, $headers_list) = LJ::ESN::_get_debug_args($class, $job, 1, "uid=$userid sub=($subscription_signature)");
+ my %debug_headers;
+ foreach my $i (0..$#$headers_list) {
+ $debug_headers{ sprintf('X-Esn-Debug-%02d', $i) } = $headers_list->[$i];
+ }
+ $opts{'_debug_headers'} = \%debug_headers;
+ }
- $subsc->{_debug_headers} = $debug_headers;
+ if ($evt->isa('LJ::Event::OfficialPost')) {
+ ## "TheSchwartz::Worker::SendEmail" tasks for events
+ ## "OfficialPost" and "SupOfficialPost" should go to their database
+ $opts{'_schwartz_role'} = $LJ::THESCHWARTZ_ROLE_MASS;
}
- # TODO: do inbox notification method here, first.
-
- # NEXT: do sub's ntypeid, unless it's inbox, then we're done.
- $subsc->process($evt)
+ $subsc->process(\%opts, $evt)
or die "Failed to process notification method for userid=$userid/subid=$subdump, evt=[@$eparams]\n";
$job->completed;
}
Modified: branches/oauth/cgi-bin/LJ/Entry.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/Entry.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/Entry.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -96,18 +96,21 @@
}
# do we have a singleton for this entry?
- {
- my $journalid = $self->{u}->{userid};
- my $jitemid = $self->{jitemid};
+ my $journalid = $self->{u}->{userid};
+ my $jitemid = $self->{jitemid};
- $singletons{$journalid} ||= {};
- return $singletons{$journalid}->{$jitemid}
- if $singletons{$journalid}->{$jitemid};
+ $singletons{$journalid} ||= {};
+ return $singletons{$journalid}->{$jitemid}
+ if $singletons{$journalid}->{$jitemid};
- # save the singleton if it doesn't exist
- $singletons{$journalid}->{$jitemid} = $self;
- }
+ # no singleton, will load row
+ my $anum = $self->{anum}; # caller supplied anum
+ __PACKAGE__->preload_rows([ $self ]);
+ return undef if $anum and $anum != $self->{anum}; # incorrect anum -> 'no such entry'
+ # save the singleton if it doesn't exist
+ $singletons{$journalid}->{$jitemid} = $self;
+
return $self;
}
@@ -881,8 +884,21 @@
return 0 if $self->journal->{statusvis} =~ m/[DSX]/;
# can't see anything by suspended users
- return 0 if $self->poster->{statusvis} eq 'S';
+ my $poster = $self->poster;
+ return 0 if $poster->{statusvis} eq 'S';
+ # if poster choosed to delete jouranl and all external content,
+ # then don't show his/her entries, except in some protected journals like 'lj_core'
+ if ($poster->{statusvis} eq 'D') {
+ my ($purge_comments, $purge_community_entries) = split /:/, $poster->prop("purge_external_content");
+ if ($purge_community_entries) {
+ my $journal_name = $self->journal->{user};
+ if (!$LJ::JOURNALS_WITH_PROTECTED_CONTENT{$journal_name}) {
+ return 0;
+ }
+ }
+ }
+
# can't see suspended entries
return 0 if $self->is_suspended_for($remote);
}
Modified: branches/oauth/cgi-bin/LJ/Event/PollVote.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/Event/PollVote.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/Event/PollVote.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -169,7 +169,7 @@
sub available_for_user {
my ($self, $u) = @_;
- return 0 if $self->arg1 && ($self->arg1 != $u->id);
+ return 0 if $self->userid != $u->id;
return $u->get_cap("track_pollvotes") ? 1 : 0;
}
Modified: branches/oauth/cgi-bin/LJ/JSON.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/JSON.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/JSON.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -11,10 +11,8 @@
sub from_json {
my ($class, $dump) = @_;
- my $ret = eval { $wrap->decode($dump) };
-
- return undef if $@;
- return $ret;
+ return unless $dump;
+ return $wrap->decode($dump);
}
sub true { $wrap->true };
@@ -72,6 +70,14 @@
return $class->traverse($what, sub {
my ($scalar) = @_;
+
+ # if the string does indeed contain wide characters (which happens
+ # in case the source string literals contained chars specified as
+ # '\u041c'), encode stuff as utf8
+ if ($scalar =~ /[^\x01-\xff]/) {
+ return Encode::encode("utf8", $scalar);
+ }
+
return Encode::encode("iso-8859-1", $scalar);
});
Modified: branches/oauth/cgi-bin/LJ/NewWorker/TheSchwartz.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/NewWorker/TheSchwartz.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/NewWorker/TheSchwartz.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -7,7 +7,7 @@
my $interval = 10;
my $verbose = 0;
-my $schwartz_role = 'worker';
+my $schwartz_role = $LJ::THESCHWARTZ_ROLE_WORKER;
sub options {
my $self = shift;
Modified: branches/oauth/cgi-bin/LJ/NotificationMethod/DebugLog.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/NotificationMethod/DebugLog.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/NotificationMethod/DebugLog.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -42,6 +42,8 @@
# send emails for events passed in
sub notify {
my $self = shift;
+ my $opts = shift || {};
+
croak "'notify' is an object method"
unless ref $self eq __PACKAGE__;
Modified: branches/oauth/cgi-bin/LJ/NotificationMethod/Email.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/NotificationMethod/Email.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/NotificationMethod/Email.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -55,6 +55,8 @@
# send emails for events passed in
sub notify {
my $self = shift;
+ my $opts = shift || {};
+
croak "'notify' is an object method"
unless ref $self eq __PACKAGE__;
@@ -98,7 +100,7 @@
my %headers = (
"X-LJ-Recipient" => $u->user,
%{$ev->as_email_headers($u) || {}},
- %{$self->{_debug_headers} || {}}
+ %{$opts->{_debug_headers} || {}}
);
my $email_subject =
Modified: branches/oauth/cgi-bin/LJ/NotificationMethod/IM.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/NotificationMethod/IM.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/NotificationMethod/IM.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -56,6 +56,8 @@
# send IMs for events passed in
sub notify {
my $self = shift;
+ my $opts = shift || {};
+
croak "'notify' is an object method"
unless ref $self eq __PACKAGE__;
Modified: branches/oauth/cgi-bin/LJ/NotificationMethod/Inbox.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/NotificationMethod/Inbox.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/NotificationMethod/Inbox.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -57,6 +57,8 @@
# notify a single event
sub notify {
my $self = shift;
+ my $opts = shift || {};
+
croak "'notify' is an object method"
unless ref $self eq __PACKAGE__;
Modified: branches/oauth/cgi-bin/LJ/NotificationMethod/SMS.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/NotificationMethod/SMS.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/NotificationMethod/SMS.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -52,6 +52,8 @@
# notify a single event
sub notify {
my $self = shift;
+ my $opts = shift || {};
+
croak "'notify' is an object method"
unless ref $self eq __PACKAGE__;
Modified: branches/oauth/cgi-bin/LJ/PageStats.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/PageStats.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/PageStats.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -18,8 +18,9 @@
# render JS output for embedding in pages
# ctx can be "journal" or "app". defaults to "app".
sub render {
- my ($self) = @_;
+ my ($self, $params) = @_;
+
my $ctx = $self->get_context;
return '' unless $self->should_do_pagestats;
@@ -31,7 +32,7 @@
die "Error loading PageStats '$plugin': $@" if $@;
my $plugin_obj = $class->new;
next unless $plugin_obj->should_render;
- $output .= $plugin_obj->render(conf => $self->{conf}->{$plugin});
+ $output .= $plugin_obj->render(conf => $self->{conf}->{$plugin}, params => (ref($params) eq 'HASH' ? $params : {}) );
}
# return nothing
@@ -78,7 +79,7 @@
sub get_context {
my ($self) = @_;
- return LJ::get_active_journal() ? 'journal' : 'app';
+ return $self->get_journal() ? 'journal' : 'app';
}
sub get_user {
@@ -162,14 +163,53 @@
sub get_journal {
my $self = shift;
+
my $j = LJ::get_active_journal();
- return $j;
+ return $j if $j;
+
+ # Now try to determine active_journal from base request if it is requests chain.
+ # Cache it in $self->{active_journal}.
+ # This code is necessary for getting active_journal in 'error-page.bml'.
+
+ return $self->{active_journal} if exists $self->{active_journal};
+
+ $self->{active_journal} = undef;
+
+ if (!LJ::Request->is_initial_req())
+ {
+ my $request = LJ::Request->prev();
+ my $host = $request->header_in('Host');
+ my $uri = $request->uri;
+
+ if (($LJ::USER_VHOSTS || $LJ::ONLY_USER_VHOSTS) &&
+ $host =~ /^([\w\-]{1,15})\.\Q$LJ::USER_DOMAIN\E$/ &&
+ $1 ne 'www')
+ {
+ my $user = $1;
+
+ my $func = $LJ::SUBDOMAIN_FUNCTION{$user};
+
+ if ($func eq 'journal' && $uri =~ m!^/(\w{1,15})(/.*)?$!) {
+ $user = $1;
+ }
+ elsif ($func) {
+ $user = '';
+ }
+
+ if ($user) {
+ my $u = LJ::load_user($user);
+ $self->{active_journal} = $u if $u;
+ }
+ }
+ }
+
+ return $self->{active_journal};
}
sub journaltype {
my $self = shift;
- my $j = LJ::get_active_journal();
+ my $j = $self->get_journal;
return $j->journaltype_readable;
}
@@ -177,7 +217,7 @@
sub journalbase {
my $self = shift;
- my $j = LJ::get_active_journal();
+ my $j = $self->get_journal;
return $j->journal_base;
}
Modified: branches/oauth/cgi-bin/LJ/Poll.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/Poll.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/Poll.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -1138,12 +1138,12 @@
$valcount += $aggr_results{$qid}->{$item};
$valmean += $aggr_results{$qid}->{$item} * $item;
}
- $valmean /= $valcount;
+ $valmean /= $valcount if $valcount;
$valstddev = 0;
foreach my $item (keys %{$aggr_results{$qid} || {}}) {
$valstddev += $aggr_results{$qid}->{$item} * ($item - $valmean) * ($item - $valmean);
}
- $valstddev = sqrt($valstddev / $valcount);
+ $valstddev = sqrt($valstddev / $valcount) if $valcount;
} elsif ($self->is_clustered) {
$sth = $self->journal->prepare("SELECT COUNT(*), AVG(value), STDDEV(value) FROM pollresult2 " .
"WHERE pollid=? AND pollqid=? AND journalid=?");
Modified: branches/oauth/cgi-bin/LJ/Request/Apache.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/Request/Apache.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/Request/Apache.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -29,21 +29,39 @@
my $instance = '';
-sub _die_if_no_request {
+sub LJ::Request::_get_instance {
+ my $class = shift;
+
+ return $class if ref $class;
+
Carp::confess("Request is not provided to LJ::Request") unless $instance;
+ return $instance;
}
sub LJ::Request::interface_name { 'Apache' }
-
sub LJ::Request::request { $instance }
+
sub LJ::Request::r {
- _die_if_no_request();
- return $instance->{r};
+ return shift->_get_instance()->{r};
}
+sub LJ::Request::apr {
+ return shift->_get_instance()->{apr};
+}
+sub LJ::Request::_new {
+ my $class = shift;
+ my $r = shift;
+
+ return bless {
+ r => $r,
+ apr => Apache::Request->new($r),
+ }, $class;
+}
+
sub LJ::Request::instance { Carp::confess("use 'request' instead") }
+
sub LJ::Request::init {
my $class = shift;
my $r = shift;
@@ -56,24 +74,19 @@
return $instance;
}
- $instance = bless {}, $class;
- $instance->{r} = $r;
- $instance->{apr} = Apache::Request->new($r);
+ $instance = LJ::Request->_new($r);
# Temporary HACK
if ($r->method eq 'POST'){
#$r->headers_in()->set("Content-Type", "multipart/form-data");
}
-
-
return $instance;
}
sub LJ::Request::prev {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->prev(@_);
+ return LJ::Request->_new($class->r()->prev(@_));
}
sub LJ::Request::is_inited {
@@ -82,110 +95,92 @@
sub LJ::Request::update_mtime {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{apr}->update_mtime(@_);
+ return $class->apr()->update_mtime(@_);
}
sub LJ::Request::set_last_modified {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->set_last_modified(@_);
+ return $class->r()->set_last_modified(@_);
}
sub LJ::Request::request_time {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->request_time();
+ return $class->r()->request_time();
}
sub LJ::Request::meets_conditions {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->meets_conditions();
+ return $class->r()->meets_conditions();
}
sub LJ::Request::read {
my $class = shift;
- _die_if_no_request();
- return $instance->{apr}->read(@_);
+ return $class->apr()->read(@_);
}
sub LJ::Request::is_main {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->is_main(@_);
+ return $class->r()->is_main(@_);
}
sub LJ::Request::main {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->main(@_);
+ return $class->r()->main(@_);
}
sub LJ::Request::dir_config {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->dir_config(@_);
+ return $class->r()->dir_config(@_);
}
sub LJ::Request::header_only {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->header_only;
+ return $class->r()->header_only;
}
sub LJ::Request::content_languages {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->content_languages(@_);
+ return $class->r()->content_languages(@_);
}
sub LJ::Request::register_cleanup {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->register_cleanup(@_);
+ return $class->r()->register_cleanup(@_);
}
sub LJ::Request::path_info {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->path_info(@_);
+ return $class->r()->path_info(@_);
}
sub LJ::Request::args {
my $class = shift;
- _die_if_no_request();
- return $instance->{apr}->args(@_);
+ return $class->apr()->args(@_);
}
sub LJ::Request::method {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->method;
+ $class->r()->method;
}
sub LJ::Request::bytes_sent {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->bytes_sent(@_);
+ $class->r()->bytes_sent(@_);
}
sub LJ::Request::document_root {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->document_root;
+ $class->r()->document_root;
}
sub LJ::Request::finfo {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->finfo;
+ $class->r()->finfo;
}
sub LJ::Request::filename {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->filename(@_);
+ $class->r()->filename(@_);
}
sub LJ::Request::add_httpd_conf {
@@ -195,8 +190,7 @@
sub LJ::Request::is_initial_req {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->is_initial_req(@_);
+ $class->r()->is_initial_req(@_);
}
sub LJ::Request::push_handlers_global {
@@ -206,45 +200,44 @@
sub LJ::Request::push_handlers {
my $class = shift;
- _die_if_no_request();
- #$instance->{r}->push_handlers(@_);
+ my $self = $class->_get_instance();
+
+ # $instance->{r}->push_handlers(@_);
return ($_[0] =~ /PerlHandler/)
- ? LJ::Request->set_handlers(@_)
+ ? $self->set_handlers(@_)
: Apache->request->push_handlers(@_);
}
sub LJ::Request::set_handlers {
my $class = shift;
- _die_if_no_request();
- my @args = shift @_;
- $args[1] = ref $_[0] eq 'ARRAY' ? $_[0] : [@_]; # second arg should be an arrayref.
-
- #return Apache->request->set_handlers(@args);
- $instance->{r}->set_handlers(@args);
+ my $r = $class->r();
+ my $handler_name = shift;
+ my $handlers = (ref $_[0] eq 'ARRAY') ? shift : [@_]; # second arg should be an arrayref.
+ if ($handler_name eq 'PerlCleanupHandler') {
+ $r->push_handlers($handler_name, $_) foreach (@$handlers);
+ } else {
+ $r->set_handlers($handler_name, $handlers);
+ }
}
sub LJ::Request::handler {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->handler(@_);
+ $class->r()->handler(@_);
}
sub LJ::Request::method_number {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->method_number(@_);
+ return $class->r()->method_number(@_);
}
sub LJ::Request::status {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->status(@_);
+ return $class->r()->status(@_);
}
sub LJ::Request::status_line {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->status_line(@_);
+ return $class->r()->status_line(@_);
}
##
@@ -258,117 +251,98 @@
sub LJ::Request::notes {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->notes (@_);
+ $class->apr()->notes (@_);
}
sub LJ::Request::pnotes {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->pnotes (@_);
+ $class->apr()->pnotes (@_);
}
sub LJ::Request::parse {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->parse (@_);
+ $class->apr()->parse (@_);
}
sub LJ::Request::uri {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->uri (@_);
+ $class->apr()->uri (@_);
}
sub LJ::Request::hostname {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->hostname (@_);
+ $class->apr()->hostname (@_);
}
sub LJ::Request::header_out {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->header_out (@_);
+ $class->apr()->header_out (@_);
}
sub LJ::Request::headers_out {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->headers_out (@_);
+ $class->apr()->headers_out (@_);
}
sub LJ::Request::header_in {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->header_in (@_);
+ $class->apr()->header_in (@_);
}
sub LJ::Request::headers_in {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->headers_in (@_);
+ $class->apr()->headers_in (@_);
}
sub LJ::Request::param {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->param (@_);
+ $class->apr()->param (@_);
}
sub LJ::Request::no_cache {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->no_cache (@_);
+ $class->apr()->no_cache (@_);
}
sub LJ::Request::content_type {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->content_type (@_);
+ $class->apr()->content_type (@_);
}
sub LJ::Request::pool {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->pool;
+ $class->apr()->pool;
}
sub LJ::Request::connection {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->connection;
+ $class->apr()->connection;
}
sub LJ::Request::output_filters {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->output_filters;
+ $class->apr()->output_filters;
}
sub LJ::Request::print {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->print (@_);
+ $class->r()->print(@_);
}
sub LJ::Request::content_encoding {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->content_encoding(@_);
+ $class->r()->content_encoding(@_);
}
sub LJ::Request::send_http_header {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->send_http_header (@_)
+ $class->apr()->send_http_header(@_);
}
sub LJ::Request::err_headers_out {
my $class = shift;
- _die_if_no_request();
- $instance->{apr}->err_headers_out (@_)
+ $class->apr()->err_headers_out (@_)
}
@@ -379,14 +353,13 @@
# TODO: do we need this and 'args' methods? they are much the same.
sub LJ::Request::get_params {
my $class = shift;
- _die_if_no_request();
- my @params = $instance->{r}->args;
+ my @params = $class->r()->args;
return @params;
}
sub LJ::Request::post_params {
my $class = shift;
- _die_if_no_request();
+ my $self = $class->_get_instance();
## $r->content
## The $r->content method will return the entity body read from the client,
@@ -395,10 +368,10 @@
## NOTE: you can only ask for this once, as the entire body is read from the client.
#return () if $instance->{r}->headers_in()->get("Content-Type") =~ m!^multipart/form-data!;
- return @{ $instance->{params} } if $instance->{params};
+ return @{ $self->{params} } if $self->{params};
- my @params = _parse_post();
- $instance->{params} = \@params;
+ my @params = $self->_parse_post();
+ $self->{params} = \@params;
return @params;
}
@@ -408,10 +381,9 @@
my $header = shift;
my $value = shift;
- _die_if_no_request();
-
- $instance->{r}->err_headers_out->add($header, $value);
- $instance->{r}->headers_out->add($header, $value);
+ my $r = $class->r();
+ $r->err_headers_out->add($header, $value);
+ $r->headers_out->add($header, $value);
return 1;
}
@@ -422,11 +394,10 @@
my $header = shift;
my $value = shift;
- _die_if_no_request();
+ my $r = $class->r();
+ $r->err_header_out($header, $value);
+ $r->header_out($header, $value);
- $instance->{r}->err_header_out($header, $value);
- $instance->{r}->header_out($header, $value);
-
return 1;
}
@@ -434,39 +405,33 @@
my $class = shift;
my $header = shift;
- _die_if_no_request();
-
- $instance->{r}->headers_in->unset($header);
+ my $r = $class->r();
+ $r->headers_in->unset($header);
}
sub LJ::Request::log_error {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->log_error(@_);
+ return $class->r()->log_error(@_);
}
sub LJ::Request::remote_ip {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->connection()->remote_ip(@_);
+ return $class->r()->connection()->remote_ip(@_);
}
sub LJ::Request::remote_host {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->connection()->remote_host;
+ return $class->r()->connection()->remote_host;
}
sub LJ::Request::user {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->connection()->user;
+ return $class->r()->connection()->user;
}
sub LJ::Request::aborted {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->connection()->aborted;
+ return $class->r()->connection()->aborted;
}
@@ -475,37 +440,35 @@
my $filename = shift;
my $fh = shift;
- _die_if_no_request();
- $instance->{r}->send_fd($fh);
+ $class->r()->send_fd($fh);
$fh->close();
}
sub LJ::Request::upload {
my $class = shift;
- return $instance->{apr}->upload(@_);
+ return $class->apr()->upload(@_);
}
sub LJ::Request::parsed_uri {
my $class = shift;
- _die_if_no_request();
- $instance->{r}->parsed_uri; # Apache::URI
+ $class->r()->parsed_uri; # Apache::URI
}
sub LJ::Request::current_callback {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->current_callback;
+ return $class->r()->current_callback;
}
sub LJ::Request::child_terminate {
my $class = shift;
- _die_if_no_request();
- return $instance->{r}->child_terminate;
+ return $class->r()->child_terminate;
}
-sub _parse_post {
- my $r = $instance->{r};
+sub LJ::Request::_parse_post {
+ my $class = shift;
+ my $r = $class->r();
+ my $apr = $class->apr();
my $method = $r->method;
return unless $method eq 'POST';
@@ -532,7 +495,7 @@
# it allows us to separate GET params and POST params.
# otherwise Apache::Request's "parms" method returns them together.
- my $parse_res = $instance->{apr}->parse;
+ my $parse_res = $apr->parse;
# set original QUERY_STRING back
$r->args($qs);
@@ -542,8 +505,8 @@
}
my @params = ();
- foreach my $name ($instance->{apr}->param){
- foreach my $val ($instance->{apr}->param($name)){
+ foreach my $name ($apr->param){
+ foreach my $val ($apr->param($name)){
push @params => ($name, $val);
}
}
Modified: branches/oauth/cgi-bin/LJ/Request/Apache2.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/Request/Apache2.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/Request/Apache2.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -38,24 +38,44 @@
sub LJ::Request::BAD_REQUEST { return Apache2::Const::HTTP_BAD_REQUEST }
sub LJ::Request::HTTP_GONE { return Apache2::Const::HTTP_GONE }
+my $instance = '';
+sub LJ::Request::_get_instance {
+ my $class = shift;
+
+ return $class if ref $class;
+
+ Carp::confess("Request is not provided to LJ::Request") unless $instance;
+ return $instance;
+}
+
sub LJ::Request::interface_name { 'Apache2' }
+sub LJ::Request::request { $instance }
-my $instance = '';
-sub LJ::Request::request { $instance }
sub LJ::Request::r {
- Carp::confess("Request is not provided to LJ::Request") unless $instance;
- return $instance->{r};
+ return shift->_get_instance()->{r};
}
+sub LJ::Request::apr {
+ return shift->_get_instance()->{apr};
+}
+sub LJ::Request::_new {
+ my $class = shift;
+ my $r = shift;
+
+ return bless {
+ r => $r,
+ apr => Apache2::Request->new($r),
+ }, $class;
+}
+
sub LJ::Request::instance {
my $class = shift;
- die "use 'request' instead";
+ Carp::confess("use 'request' instead");
}
-
sub LJ::Request::init {
my $class = shift;
my $r = shift;
@@ -68,16 +88,14 @@
return $instance;
}
- $instance = bless {}, $class;
- $instance->{apr} = Apache2::Request->new($r);
- $instance->{r} = $r;
+ $instance = LJ::Request->_new($r);
+
return $instance;
}
sub LJ::Request::prev {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->prev(@_);
+ return LJ::Request->_new($class->r()->prev(@_));
}
sub LJ::Request::is_inited {
@@ -86,73 +104,65 @@
sub LJ::Request::update_mtime {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->update_mtime(@_);
+ return $class->r()->update_mtime(@_);
}
sub LJ::Request::set_last_modified {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->set_last_modified(@_);
+ return $class->r()->set_last_modified(@_);
}
sub LJ::Request::request_time {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->request_time();
+ return $class->r()->request_time();
}
sub LJ::Request::read {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->read(@_);
+ return $class->r()->read(@_);
}
sub LJ::Request::is_main {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return !$instance->{r}->main;
+ return !$class->r()->main;
}
sub LJ::Request::main {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->main(@_);
+ return $class->r()->main(@_);
}
sub LJ::Request::dir_config {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->dir_config(@_);
+ return $class->r()->dir_config(@_);
}
sub LJ::Request::header_only {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->header_only;
+ return $class->r()->header_only;
}
sub LJ::Request::content_languages {
my $class = shift;
- die "Request is not provided to LJ::Request" unless $instance;
- return $instance->{r}->content_languages(@_);
+ return $class->r()->content_languages(@_);
}
sub LJ::Request::register_cleanup {
my $class = shift;
- return $instance->{r}->pool->cleanup_register(@_);
+ return $class->r()->pool->cleanup_register(@_);
}
sub LJ::Request::path_info {
my $class = shift;
- return $instance->{r}->path_info(@_);
+ return $class->r()->path_info(@_);
}
# $r->args in 2.0 returns the query string without parsing and splitting it into an array.
sub LJ::Request::args {
my $class = shift;
- if (wantarray()){
- my $qs = $instance->{r}->args(@_);
+ my $r = $class->r();
+ if (wantarray()) {
+ my $qs = $r->args(@_);
my @args =
map { URI::Escape::uri_unescape ($_) }
map { s/\+/ /g; $_ } # in query_string 'break' is encoded as '+' simbol
@@ -160,33 +170,33 @@
split /[\&\;]/ => $qs;
return @args;
} else {
- return $instance->{r}->args(@_);
+ return $r->args(@_);
}
}
sub LJ::Request::method {
my $class = shift;
- $instance->{r}->method;
+ $class->r()->method;
}
sub LJ::Request::bytes_sent {
my $class = shift;
- $instance->{r}->bytes_sent(@_);
+ $class->r()->bytes_sent(@_);
}
sub LJ::Request::document_root {
my $class = shift;
- $instance->{r}->document_root;
+ $class->r()->document_root;
}
sub LJ::Request::finfo {
my $class = shift;
- $instance->{apr}->finfo;
+ $class->apr()->finfo;
}
sub LJ::Request::filename {
my $class = shift;
- $instance->{r}->filename(@_);
+ $class->r()->filename(@_);
}
sub LJ::Request::add_httpd_conf {
@@ -197,7 +207,7 @@
sub LJ::Request::is_initial_req {
my $class = shift;
- $instance->{r}->is_initial_req(@_);
+ $class->r()->is_initial_req(@_);
}
sub LJ::Request::push_handlers_global {
@@ -217,7 +227,7 @@
$el =~ s/PerlHandler/PerlResponseHandler/g;
$el;
} @_;
- return $instance->{r}->push_handlers(@handlers);
+ return $class->r()->push_handlers(@handlers);
}
sub LJ::Request::set_handlers {
@@ -227,27 +237,27 @@
$el =~ s/PerlHandler/PerlResponseHandler/g;
$el;
} @_;
- $instance->{r}->set_handlers(@handlers);
+ $class->r()->set_handlers(@handlers);
}
sub LJ::Request::handler {
my $class = shift;
- $instance->{r}->handler(@_);
+ $class->r()->handler(@_);
}
sub LJ::Request::method_number {
my $class = shift;
- return $instance->{r}->method_number(@_);
+ return $class->r()->method_number(@_);
}
sub LJ::Request::status {
my $class = shift;
- return $instance->{r}->status(@_);
+ return $class->r()->status(@_);
}
sub LJ::Request::status_line {
my $class = shift;
- return $instance->{r}->status_line(@_);
+ return $class->r()->status_line(@_);
}
##
@@ -261,97 +271,97 @@
sub LJ::Request::notes {
my $class = shift;
- return $instance->{r}->pnotes(@_);
+ return $class->r()->pnotes(@_);
}
sub LJ::Request::pnotes {
my $class = shift;
- $instance->{r}->pnotes (@_);
+ $class->r()->pnotes (@_);
}
sub LJ::Request::parse {
my $class = shift;
- $instance->{r}->parse (@_);
+ $class->r()->parse (@_);
}
sub LJ::Request::uri {
my $class = shift;
- $instance->{r}->uri (@_);
+ $class->r()->uri (@_);
}
sub LJ::Request::hostname {
my $class = shift;
- $instance->{r}->hostname (@_);
+ $class->r()->hostname (@_);
}
sub LJ::Request::header_out {
my $class = shift;
my $header = shift;
if (@_ > 0){
- return $instance->{r}->err_headers_out->{$header} = shift;
+ return $class->r()->err_headers_out->{$header} = shift;
} else {
- return $instance->{r}->err_headers_out->{$header};
+ return $class->r()->err_headers_out->{$header};
}
}
sub LJ::Request::headers_out {
my $class = shift;
- $instance->{r}->headers_out (@_);
+ $class->r()->headers_out (@_);
}
sub LJ::Request::header_in {
my $class = shift;
my $header = shift;
if (@_ > 0){
- return $instance->{r}->headers_in->{$header} = shift;
+ return $class->r()->headers_in->{$header} = shift;
} else {
- return $instance->{r}->headers_in->{$header};
+ return $class->r()->headers_in->{$header};
}
}
sub LJ::Request::headers_in {
my $class = shift;
- $instance->{r}->headers_in();
+ $class->r()->headers_in();
}
sub LJ::Request::param {
my $class = shift;
- $instance->{r}->param (@_);
+ $class->r()->param (@_);
}
sub LJ::Request::no_cache {
my $class = shift;
- $instance->{r}->no_cache (@_);
+ $class->r()->no_cache (@_);
}
sub LJ::Request::content_type {
my $class = shift;
- $instance->{r}->content_type (@_);
+ $class->r()->content_type (@_);
}
sub LJ::Request::pool {
my $class = shift;
- $instance->{r}->pool;
+ $class->r()->pool;
}
sub LJ::Request::connection {
my $class = shift;
- $instance->{r}->connection;
+ $class->r()->connection;
}
sub LJ::Request::output_filters {
my $class = shift;
- $instance->{r}->output_filters(@_);
+ $class->r()->output_filters(@_);
}
sub LJ::Request::print {
my $class = shift;
- $instance->{r}->print (@_);
+ $class->r()->print (@_);
}
sub LJ::Request::content_encoding {
my $class = shift;
- $instance->{r}->content_encoding(@_);
+ $class->r()->content_encoding(@_);
}
sub LJ::Request::send_http_header {
@@ -364,7 +374,7 @@
sub LJ::Request::err_headers_out {
my $class = shift;
- $instance->{r}->err_headers_out (@_)
+ $class->r()->err_headers_out (@_)
}
@@ -375,8 +385,9 @@
# TODO: do we need this and 'args' methods? they are much the same.
sub LJ::Request::get_params {
my $class = shift;
+ my $r = $class->r();
if (wantarray()){
- my $qs = $instance->{r}->args(@_);
+ my $qs = $r->args(@_);
my @args =
map { URI::Escape::uri_unescape ($_) }
map { s/\+/ /g; $_ } # in query_string 'break' is encoded as '+' simbol
@@ -384,33 +395,35 @@
split /[\&\;]/ => $qs;
return @args;
} else {
- return $instance->{r}->args(@_);
+ return $r->args(@_);
}
}
+
sub LJ::Request::post_params {
my $class = shift;
+ my $self = $class->_get_instance();
+ my $apr = $self->apr();
- return @{ $instance->{params} } if $instance->{params};
+ return @{ $self->{params} } if $self->{params};
my (@params, %already_seen);
- foreach my $name ($instance->{apr}->body) {
+ foreach my $name ($apr->body) {
next if $already_seen{$name}++;
- foreach my $val ($instance->{apr}->body($name)) {
+ foreach my $val ($apr->body($name)) {
push @params, ($name, $val);
}
}
- $instance->{params} = \@params;
+ $self->{params} = \@params;
return @params;
-
}
-
sub LJ::Request::add_header_out {
my $class = shift;
my $header = shift;
my $value = shift;
- $instance->{r}->err_headers_out->add($header, $value);
- $instance->{r}->headers_out->add($header, $value);
+ my $r = $class->r();
+ $r->err_headers_out->add($header, $value);
+ $r->headers_out->add($header, $value);
return 1;
}
@@ -421,8 +434,9 @@
my $header = shift;
my $value = shift;
- $instance->{r}->err_headers_out->set($header, $value);
- $instance->{r}->headers_out->set($header, $value);
+ my $r = $class->r();
+ $r->err_headers_out->set($header, $value);
+ $r->headers_out->set($header, $value);
return 1;
}
@@ -430,49 +444,50 @@
sub LJ::Request::unset_headers_in {
my $class = shift;
my $header = shift;
- $instance->{r}->headers_in->unset($header);
+ $class->r()->headers_in->unset($header);
}
sub LJ::Request::log_error {
my $class = shift;
- return $instance->{r}->log_error(@_);
+ return $class->r()->log_error(@_);
}
sub LJ::Request::remote_ip {
my $class = shift;
- return $instance->{r}->connection()->remote_ip(@_);
+ return $class->r()->connection()->remote_ip(@_);
}
sub LJ::Request::remote_host {
my $class = shift;
- return $instance->{r}->connection()->remote_host;
+ return $class->r()->connection()->remote_host;
}
sub LJ::Request::user {
my $class = shift;
- return $instance->{r}->auth_name();
+ return $class->r()->auth_name();
}
sub LJ::Request::aborted {
my $class = shift;
- return $instance->{r}->connection()->aborted;
+ return $class->r()->connection()->aborted;
}
sub LJ::Request::upload {
my $class = shift;
- return $instance->{apr}->upload(@_);
+ return $class->apr()->upload(@_);
}
+
sub LJ::Request::sendfile {
my $class = shift;
my $filename = shift;
my $fh = shift; # used in Apache v.1
- return $instance->{r}->sendfile($filename);
+ return $class->r()->sendfile($filename);
}
sub LJ::Request::parsed_uri {
my $class = shift;
- $instance->{r}->parsed_uri; # Apache2::URI
+ $class->r()->parsed_uri; # Apache2::URI
}
sub LJ::Request::current_callback {
@@ -482,12 +497,12 @@
sub LJ::Request::child_terminate {
my $class = shift;
- return $instance->{r}->child_terminate;
+ return $class->r()->child_terminate;
}
sub LJ::Request::meets_conditions {
my $class = shift;
- return $instance->{r}->meets_conditions;
+ return $class->r()->meets_conditions;
}
1;
Modified: branches/oauth/cgi-bin/LJ/S2/EntryPage.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/S2/EntryPage.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/S2/EntryPage.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -9,7 +9,6 @@
sub EntryPage
{
my ($u, $remote, $opts) = @_;
-
my $get = $opts->{'getargs'};
my $p = Page($u, $opts);
@@ -94,6 +93,11 @@
'viewall' => $viewall,
'expand_all' => $opts->{expand_all},
};
+
+ ## Expand all comments on page
+ unless ($LJ::DISABLED{allow_expand_all_comments}){
+ $copts->{expand_all} = 1 if $get->{expand} eq 'all';
+ }
my $userlite_journal = UserLite($u);
@@ -172,18 +176,9 @@
}
my $poster;
- if ($com->{'posterid'}) {
- if ($pu) {
- $poster = UserLite($pu);
- $poster->{'_opt_side_alias'} = 1;
- } else {
- $poster = {
- '_type' => 'UserLite',
- 'username' => $com->{'userpost'},
- 'name' => $com->{'userpost'}, # we don't have this, so fake it
- 'journal_type' => 'P', # fake too, but only people can post, so correct
- };
- }
+ if ($com->{'posterid'} && $pu) {
+ $poster = UserLite($pu);
+ $poster->{'_opt_side_alias'} = 1;
}
# Comment Posted Notice
@@ -230,15 +225,26 @@
'edit_url' => $edit_url,
};
- # don't show info from suspended users
- # FIXME: ideally the load_comments should only return these
- # items if there are children, otherwise they should be hidden entirely
- if ($pu && $pu->{'statusvis'} eq "S" && !$viewsome) {
- $s2com->{'text'} = "";
- $s2com->{'subject'} = "";
- $s2com->{'full'} = 0;
- $s2com->{'subject_icon'} = undef;
- $s2com->{'userpic'} = undef;
+ # don't show info from suspended users, and from users who deleted their journals
+ # and choosed to delete their comments in other journals
+ if (!$viewsome && $pu) {
+ my $hide_comment;
+ if ($pu->is_suspended) {
+ $hide_comment = 1;
+ } elsif ($pu->is_deleted) {
+ my ($purge_comments, $purge_community_entries) = split /:/, $pu->prop("purge_external_content");
+ if ($purge_comments && !$LJ::JOURNALS_WITH_PROTECTED_CONTENT{ $u->{user} }) {
+ $hide_comment = 1;
+ }
+ }
+
+ if ($hide_comment) {
+ $s2com->{'text'} = "";
+ $s2com->{'subject'} = "";
+ $s2com->{'full'} = 0;
+ $s2com->{'subject_icon'} = undef;
+ $s2com->{'userpic'} = undef;
+ }
}
# Conditionally add more links to the keyseq
Modified: branches/oauth/cgi-bin/LJ/S2/RecentPage.pm
===================================================================
--- branches/oauth/cgi-bin/LJ/S2/RecentPage.pm 2010-08-04 05:56:16 UTC (rev 17084)
+++ branches/oauth/cgi-bin/LJ/S2/RecentPage.pm 2010-08-04 08:56:19 UTC (rev 17085)
@@ -142,8 +142,10 @@
my $ditemid = $itemid * 256 + $item->{'anum'};
my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
- $entry_obj->handle_prefetched_props($logprops{$itemid});
+
+ next ENTRY unless $entry_obj->visible_to($remote);
+ $entry_obj->handle_prefetched_props($logprops{$itemid});
...
(truncated) 