« Bolivia Falling into Ruin | Main | Mosul »

June 12, 2005

Delete and Ban

I have been wanting for some time to be able to delete a trackback ping, and at the same time ban the IP (same with category pings and comments). Since SixApart hasn't done the work for me, I figured I'd do it myself. In the extended entry are the diffs to enable this functionality.

Of course, there are the caveats. This has only been tested on one installation with two blogs, and only on MT 3.16. Even then the testing has been limited so far, though I suspect it will get a more thorough workout over time. This only works with trackback pings, category pings and comments. (Hopefully, it works correctly with all of those all of the time, but no guarantees on that.) This is not a plug-in, but alteration to the basic MT code. As such, it carries more risk than installing most plug-ins. Please don't muck up your app, then whine to me about it. In other words, use at your own risk; no warranty; that word does not mean what you think it means; you can't handle the truth. Oh, and the template change allows for translations, but I didn't do any localization at all.

If you use this, please let me know. If you use this and have problems, definitely let me know so that I can fix them. If you are from SixApart, and want to incorporate this, please feel free, especially if you can improve it.

UPDATE: One thing I should note: there are no checks to make sure that you haven't deleted this IP before, so if you are deleting several items from the same place, your banlist will likely include the same IP several times, which is a little inefficient. I'll probably fix that at some point.

UPDATE: OK, I've fixed the code so that it only puts the IP in the ban list once. If you've already updated your CMS.pm with the original code, I suggest going back to the original and then proceeding from the diff in the extended section. I also fixed the display of the code. All of the -> operators weren't showing up correctly.

Here is the change to <MT_BIN>/lib/MT/App/CMS.pm

1832a1833,1846
>             if (($type eq 'ping' || $type eq 'ping_cat' || $type eq 'comment')
>                 && $q->param('deleteAndBan'))
>             {
>                 use MT::IPBanList;
>                 my $existing = MT::IPBanList->load({ 'ip' => $obj->ip, 'blog_id' => $q->param('blog_id') });
>                 unless ($existing) {
>                     my $ban = MT::IPBanList->new;
>                     $ban->blog_id($q->param('blog_id'));
>                     $ban->ip($obj->ip);
>                     $ban->save
>                         or die $ban->errstr;
>                 {
>             }

And here is the change to <MT_BIN>/tmpl/cms/delete_confirm.tmpl

56,64d55
> <TMPL_IF NAME=TYPE_COMMENT>
> <input type="submit" name="deleteAndBan" value="<MT_TRANS phrase="Delete and Ban">" />
> </TMPL_IF>
> <TMPL_IF NAME=TYPE_PING>
> <input type="submit" name="deleteAndBan" value="<MT_TRANS phrase="Delete and Ban">" />
> </TMPL_IF>
> <TMPL_IF NAME=TYPE_PING_CAT>
> <input type="submit" name="deleteAndBan" value="<MT_TRANS phrase="Delete and Ban">" />
> </TMPL_IF>
Posted by jeff at June 12, 2005 3:18 PM

Trackback Pings

TrackBack URL for this entry:
http://www.caerdroia.org/MT/mt-tb.cgi/140