alf (red_alf) wrote in changelog,
alf
red_alf
changelog

[livejournal] r22984: LJSUP-13431: Antispam for edited entries...

Committer: afedorov
LJSUP-13431: Antispam for edited entries in the communities

U   trunk/cgi-bin/ljprotocol.pl
U   trunk/htdocs/editjournal.bml
Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2012-09-26 15:06:22 UTC (rev 22983)
+++ trunk/cgi-bin/ljprotocol.pl	2012-09-26 15:47:19 UTC (rev 22984)
@@ -3161,117 +3161,124 @@
             LJ::run_hook('spam_community_detector', $uowner, $req, \$need_moderated, $suspicious_list);
         }
 
-        if ($uowner->{'journaltype'} eq 'C' && $need_moderated && !$flags->{'nomod'}) {
+        if ($uowner->{'journaltype'} eq 'C' && !$flags->{'nomod'}) {
 
             my $entry = LJ::Entry->new($ownerid, jitemid => $itemid);
             my $modid_old = $entry->prop("mod_queue_id");
+            
+            if ($need_moderated) {
 
-            $req->{'_moderate'}->{'authcode'} = LJ::make_auth_code(15);
+                $req->{'_moderate'}->{'authcode'} = LJ::make_auth_code(15);
 
-            # create tag <lj-embed> from HTML-tag <embed>
-            LJ::EmbedModule->parse_module_embed($uowner, \$req->{event});
+                # create tag <lj-embed> from HTML-tag <embed>
+                LJ::EmbedModule->parse_module_embed($uowner, \$req->{event});
 
-            my $fr = $dbcm->quote(Storable::nfreeze($req));
-            return fail($err, 409) if length($fr) > 200_000;
+                my $fr = $dbcm->quote(Storable::nfreeze($req));
+                return fail($err, 409) if length($fr) > 200_000;
 
-            # store
-            my $modid = LJ::alloc_user_counter($uowner, "M");
-            return fail($err, 501) unless $modid;
+                # store
+                my $modid = LJ::alloc_user_counter($uowner, "M");
+                return fail($err, 501) unless $modid;
 
-            $uowner->do("INSERT INTO modlog (journalid, modid, posterid, subject, logtime) ".
-                        "VALUES ($ownerid, $modid, $posterid, ?, NOW())", undef,
-                        LJ::text_trim($req->{'subject'}, 30, 0));
-            return fail($err, 501) if $uowner->err;
+                $uowner->do("INSERT INTO modlog (journalid, modid, posterid, subject, logtime) ".
+                            "VALUES ($ownerid, $modid, $posterid, ?, NOW())", undef,
+                            LJ::text_trim($req->{'subject'}, 30, 0));
+                return fail($err, 501) if $uowner->err;
 
-            $uowner->do("INSERT INTO modblob (journalid, modid, request_stor) ".
-                        "VALUES ($ownerid, $modid, $fr)");
-            if ($uowner->err) {
-                $uowner->do("DELETE FROM modlog WHERE journalid=$ownerid AND modid=$modid");
-                return fail($err, 501);
-            }
+                $uowner->do("INSERT INTO modblob (journalid, modid, request_stor) ".
+                            "VALUES ($ownerid, $modid, $fr)");
+                if ($uowner->err) {
+                    $uowner->do("DELETE FROM modlog WHERE journalid=$ownerid AND modid=$modid");
+                    return fail($err, 501);
+                }
                 
-            if ($modid_old) {
-                $uowner->do("DELETE FROM modlog WHERE journalid=$ownerid AND modid=$modid_old");
-                return fail($err, 501) if $uowner->err;
-                $uowner->do("DELETE FROM modblob WHERE journalid=$ownerid AND modid=$modid_old");
-                return fail($err, 501) if $uowner->err;
-            }
+                if ($modid_old) {
+                    $uowner->do("DELETE FROM modlog WHERE journalid=$ownerid AND modid=$modid_old");
+                    return fail($err, 501) if $uowner->err;
+                    $uowner->do("DELETE FROM modblob WHERE journalid=$ownerid AND modid=$modid_old");
+                    return fail($err, 501) if $uowner->err;
+                }
 
-            $entry->set_prop("mod_queue_id", $modid);
+                $entry->set_prop("mod_queue_id", $modid);
             
-            my $suspicious_text = "";
-            foreach (@$suspicious_list) {
-                $suspicious_text .= "   - $_->{type} - $_->{url}\n";
-            }
+                my $suspicious_text = "";
+                foreach (@$suspicious_list) {
+                    $suspicious_text .= "   - $_->{type} - $_->{url}\n";
+                }
 
-            # alert moderator(s)
-            my $mods = LJ::load_rel_user($dbh, $ownerid, 'M') || [];
-            if (@$mods) {
-                # load up all these mods and figure out if they want email or not
-                my $modlist = LJ::load_userids(@$mods);
+                # alert moderator(s)
+                my $mods = LJ::load_rel_user($dbh, $ownerid, 'M') || [];
+                if (@$mods) {
+                    # load up all these mods and figure out if they want email or not
+                    my $modlist = LJ::load_userids(@$mods);
 
-                my @emails;
-                my $ct;
-                foreach my $mod (values %$modlist) {
-                    last if $ct > 20;  # don't send more than 20 emails.
+                    my @emails;
+                    my $ct;
+                    foreach my $mod (values %$modlist) {
+                        last if $ct > 20;  # don't send more than 20 emails.
 
-                    next unless $mod->is_visible;
+                        next unless $mod->is_visible;
 
-                    LJ::load_user_props($mod, 'opt_nomodemail');
-                    next if $mod->{opt_nomodemail};
-                    next if $mod->{status} ne "A";
+                        LJ::load_user_props($mod, 'opt_nomodemail');
+                        next if $mod->{opt_nomodemail};
+                        next if $mod->{status} ne "A";
 
-                    push @emails,
-                        {
-                            to          => $mod->email_raw,
-                            browselang  => $mod->prop('browselang'),
-                            charset     => $mod->mailencoding || 'utf-8',
-                        };
+                        push @emails,
+                            {
+                                to          => $mod->email_raw,
+                                browselang  => $mod->prop('browselang'),
+                                charset     => $mod->mailencoding || 'utf-8',
+                            };
 
-                    ++$ct;
-                }
+                        ++$ct;
+                    }
 
-                foreach my $to (@emails) {
-                    # TODO: html/plain text.
-                    my $body = LJ::Lang::get_text(
-                        $to->{'browselang'},
-                        'esn.moderated_edited_submission.body', undef,
-                        {
-                            user        => $u->{'user'},
-                            subject     => $req->{'subject'},
-                            community   => $uowner->{'user'},
-                            modid       => $modid,
-                            siteroot    => $LJ::SITEROOT,
-                            sitename    => $LJ::SITENAME,
-                            moderateurl => "$LJ::SITEROOT/community/moderate.bml?authas=$uowner->{'user'}&modid=$modid",
-                            viewurl     => "$LJ::SITEROOT/community/moderate.bml?authas=$uowner->{'user'}",
-                            susp_list   => $suspicious_text,
-                        });
+                    foreach my $to (@emails) {
+                        # TODO: html/plain text.
+                        my $body = LJ::Lang::get_text(
+                            $to->{'browselang'},
+                            'esn.moderated_edited_submission.body', undef,
+                            {
+                                user        => $u->{'user'},
+                                subject     => $req->{'subject'},
+                                community   => $uowner->{'user'},
+                                modid       => $modid,
+                                siteroot    => $LJ::SITEROOT,
+                                sitename    => $LJ::SITENAME,
+                                moderateurl => "$LJ::SITEROOT/community/moderate.bml?authas=$uowner->{'user'}&modid=$modid",
+                                viewurl     => "$LJ::SITEROOT/community/moderate.bml?authas=$uowner->{'user'}",
+                                susp_list   => $suspicious_text,
+                            });
 
-                    my $subject = LJ::Lang::get_text($to->{'browselang'},'esn.moderated_edited_submission.subject');
+                        my $subject = LJ::Lang::get_text($to->{'browselang'},'esn.moderated_edited_submission.subject');
 
-                    LJ::send_mail({
-                        'to'        => $to->{to},
-                        'from'      => $LJ::DONOTREPLY_EMAIL,
-                        'charset'   => $to->{charset},
-                        'subject'   => $subject,
-                        'body'      => $body,
-                    });
+                        LJ::send_mail({
+                            'to'        => $to->{to},
+                            'from'      => $LJ::DONOTREPLY_EMAIL,
+                            'charset'   => $to->{charset},
+                            'subject'   => $subject,
+                            'body'      => $body,
+                        });
+                    }
                 }
-            }
 
-            my $msg = translate($u, "modpost", undef);
-            return {
-                'message' => $msg,
-                xc3 => {
-                    u => $u,
-                    post => {
-                        coords      => $req->{props}->{current_coords},
-                        has_images  => ($req->{event} =~ /pics\.livejournal\.com/ ? 1 : 0),
-                        from_mobile => ($req->{event} =~ /m\.livejournal\.com/ ? 1 : 0)
+                my $msg = translate($u, "modpost", undef);
+                return {
+                    'message' => $msg,
+                    xc3 => {
+                        u => $u,
+                        post => {
+                            coords      => $req->{props}->{current_coords},
+                            has_images  => ($req->{event} =~ /pics\.livejournal\.com/ ? 1 : 0),
+                            from_mobile => ($req->{event} =~ /m\.livejournal\.com/ ? 1 : 0)
+                        }
                     }
-                }
-            };
+                };
+            } elsif ($modid_old) {
+                $uowner->do("DELETE FROM modlog  WHERE journalid=? and  modid=?", undef, $ownerid, $modid_old);
+                $uowner->do("DELETE FROM modblob WHERE journalid=? and  modid=?", undef, $ownerid, $modid_old);
+                $entry->set_prop("mod_queue_id", undef);
+            }
         }
     }
 

Modified: trunk/htdocs/editjournal.bml
===================================================================
--- trunk/htdocs/editjournal.bml	2012-09-26 15:06:22 UTC (rev 22983)
+++ trunk/htdocs/editjournal.bml	2012-09-26 15:47:19 UTC (rev 22984)
@@ -568,15 +568,37 @@
             # LJSUP-13431: Antispam for edited entries in the communities
             my $modid = $entry_obj->prop("mod_queue_id");
             if ( $modid && LJ::isu($journalu) ) {
-                my $dbcr = LJ::get_cluster_def_reader($journalu); 
-                my $frozen = $dbcr->selectrow_array("
-                    SELECT request_stor 
-                    FROM modblob 
-                    WHERE journalid=? AND modid=?
-                ", undef, $journalu->{'userid'}, $modid);
+                my $dbcm = LJ::get_cluster_master($journalu);
+                my $edit_url = "$LJ::SITEROOT/editjournal.bml?journal=$usejournalu->{user}&itemid=$ditemid";
 
-                my $req = $frozen ? Storable::thaw($frozen) : {};
-                ($subject, $event) = ($req->{subject}, $req->{event});
+                if ($GET{restore} eq 'yes') {
+                    $entry_obj->set_prop("mod_queue_id", undef);
+        
+                    $dbcm->do("
+                        DELETE 
+                        FROM modlog
+                        WHERE journalid=? AND modid=?
+                    ", undef, $journalu->{'userid'}, $modid);
+
+                    $dbcm->do("
+                        DELETE 
+                        FROM modblob 
+                        WHERE journalid=? AND modid=?
+                    ", undef, $journalu->{'userid'}, $modid);
+            
+                    return BML::redirect($edit_url);
+                } else {
+                    my $frozen = $dbcm->selectrow_array("
+                        SELECT request_stor 
+                        FROM modblob 
+                        WHERE journalid=? AND modid=?
+                    ", undef, $journalu->{'userid'}, $modid);
+
+                    my $req = $frozen ? Storable::thaw($frozen) : {};
+                    ($subject, $event) = ($req->{subject}, $req->{event});
+        
+                    LJ::need_var( entry_restore => "$edit_url&restore=yes" );
+                }
             }
 
             my $suspend_msg = $entry_obj->should_show_suspend_msg_to($remote) ? 1 : 0;

Tags: afedorov, bml, livejournal, pl, red_alf
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments