[dw-free] refactor sysban
[commit: http://hg.dwscoalition.org/dw-free/rev/e03794ee5a42]
http://bugs.dwscoalition.org/show_bug.cgi?id=2261
Refactor comment info code to reduce duplication of logic.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2261
Refactor comment info code to reduce duplication of logic.
Patch by
Files modified:
- cgi-bin/LJ/Comment.pm
- cgi-bin/LJ/S2/EntryPage.pm
- htdocs/talkread.bml
- htdocs/tools/recent_comments.bml
--------------------------------------------------------------------------------
diff -r 0ec6e01c4fd9 -r e03794ee5a42 cgi-bin/LJ/Comment.pm
--- a/cgi-bin/LJ/Comment.pm Mon Jan 24 10:14:41 2011 -0600
+++ b/cgi-bin/LJ/Comment.pm Mon Jan 24 10:17:18 2011 -0600
@@ -1071,18 +1071,19 @@ sub manage_buttons {
return $managebtns;
}
-# returns info for javscript comment management
+# returns info for javascript comment management
+# can be used as a class method if $journal is passed explicitly
sub info {
- my $self = $_[0];
- my $remote = LJ::get_remote() or return;
+ my ( $self, $journal ) = @_;
+ my $remote = LJ::get_remote();
+ $journal ||= $self->journal or return {};
- my %LJ_cmtinfo;
- $LJ_cmtinfo{canAdmin} = $remote->can_manage( $self->journal );
- $LJ_cmtinfo{canSpam} = ! LJ::sysban_check( 'spamreport', $self->journal->user );
- $LJ_cmtinfo{journal} = $self->journal->user;
- $LJ_cmtinfo{remote} = $remote->user;
-
- return \%LJ_cmtinfo;
+ return {
+ canAdmin => $remote && $remote->can_manage( $journal ),
+ canSpam => ! LJ::sysban_check( 'spamreport', $journal->user ),
+ journal => $journal->user,
+ remote => $remote ? $remote->user : '',
+ };
}
sub indent {
diff -r 0ec6e01c4fd9 -r e03794ee5a42 cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm Mon Jan 24 10:14:41 2011 -0600
+++ b/cgi-bin/LJ/S2/EntryPage.pm Mon Jan 24 10:17:18 2011 -0600
@@ -1,4 +1,3 @@
-#!/usr/bin/perl
#!/usr/bin/perl
#
# This code was forked from the LiveJournal project owned and operated
@@ -342,17 +341,8 @@ sub EntryPage
# print comment info
{
- my $canAdmin = $remote && $remote->can_manage( $u ) ? 1 : 0;
- my $canSpam = LJ::sysban_check( 'spamreport', $u->user ) ? 0 : 1;
- my $formauth = LJ::ejs(LJ::eurl(LJ::form_auth(1)));
-
- my $cmtinfo = {
- form_auth => $formauth,
- journal => $u->user,
- canAdmin => $canAdmin,
- canSpam => $canSpam,
- remote => $remote ? $remote->user : undef,
- };
+ my $cmtinfo = LJ::Comment->info( $u );
+ $cmtinfo->{form_auth} = LJ::ejs( LJ::eurl( LJ::form_auth( 1 ) ) );
my $recurse = sub {
my ($self, $array) = @_;
diff -r 0ec6e01c4fd9 -r e03794ee5a42 htdocs/talkread.bml
--- a/htdocs/talkread.bml Mon Jan 24 10:14:41 2011 -0600
+++ b/htdocs/talkread.bml Mon Jan 24 10:17:18 2011 -0600
@@ -340,12 +340,11 @@ body<=
# Quick reply variables. Not always set.
my ($last_talkid, $last_jid) = LJ::get_lastcomment();
- my %LJ_cmtinfo; # data structure to give to javascript for commentmanage
- $LJ_cmtinfo{form_auth} = LJ::form_auth(1);
- $LJ_cmtinfo{journal} = $u->user;
- $LJ_cmtinfo{canAdmin} = $remote && $remote->can_manage( $u ) ? 1 : 0;
- $LJ_cmtinfo{canSpam} = LJ::sysban_check( 'spamreport', $u->user ) ? 0 : 1;
- $LJ_cmtinfo{remote} = $remote ? $remote->user : "";
+
+ # data structure to give to javascript for commentmanage
+ my %LJ_cmtinfo = %{ LJ::Comment->info( $u ) };
+ $LJ_cmtinfo{form_auth} = LJ::form_auth( 1 );
+
my $show_thread_expander = $u->show_thread_expander( $remote );
#
diff -r 0ec6e01c4fd9 -r e03794ee5a42 htdocs/tools/recent_comments.bml
--- a/htdocs/tools/recent_comments.bml Mon Jan 24 10:14:41 2011 -0600
+++ b/htdocs/tools/recent_comments.bml Mon Jan 24 10:17:18 2011 -0600
@@ -20,7 +20,6 @@ body<=
use strict;
use vars qw(%GET %POST);
my $ret;
- my %LJ_cmtinfo;
LJ::need_res('js/commentmanage.js');
LJ::set_active_crumb('managecomments');
@@ -28,19 +27,13 @@ body<=
my $remote = LJ::get_remote();
return "<?needlogin?>" unless $remote;
- $LJ_cmtinfo{'form_auth'} = LJ::form_auth(1);
- $LJ_cmtinfo{'canAdmin'} = 1;
- $LJ_cmtinfo{'remote'} = $remote->{user};
- $LJ_cmtinfo{'journal'} = $remote->{user};
-
my $authas = $GET{'authas'} || $remote->{'user'};
my $u = LJ::get_authas_user($authas);
return LJ::bad_input($ML{'error.invalidauth'})
unless $u;
- my $user = $u->{'user'};
-
- $LJ_cmtinfo{canSpam} = LJ::sysban_check( 'spamreport', $user ) ? 0 : 1;
+ my %LJ_cmtinfo = %{ LJ::Comment->info( $u ) };
+ $LJ_cmtinfo{form_auth} = LJ::form_auth( 1 );
my $dbcr = LJ::get_cluster_reader($u);
return "Error: can't get DB for user" unless $dbcr;
--------------------------------------------------------------------------------
