List Pending Comments

So MT-Moderate automatically moderates most comments that you’ll want moderated. This is a huge step in blocking comment spam. If it doesn’t show up on the site, then that’s most of the battle. In fact, for some people, it is all of the battle. All you have to do is occasionally approve some comments that come in, because you’d like to see them on your blog. Those pending comments that contain nothing but spam? Ignore them. Done, problem solved.

But if you’re a bit anal-retentive like myself, you might prefer to remove those pending comments from your installation. You could go through and delete each one, page by page, but that’s really a bit of a pain. I’m always afraid that I’m going to remove a valid comment by mistake.

Or you could load up a database utility of some sort and delete them that way. But many people don’t have that level of knowledge, and it still takes some work to get done. Unfortunately, Movable Type doesn’t allow you to list pending comments. Not by default, anyway. Luckily, it only takes a few small changes and you’ll be listing pending comments that can be easily removed.

Before you do anything, make a backup of any files involved. That way, if you change something and it breaks, you’ll have a copy that you can use to get going again. To make this change, you’ll need to modify list_comment.tmpl and CMS.pm. These files are found in directories underneath your Movable Type installation. If you can’t find the files, you might want to think twice – or perhaps more than twice – about making this change.

First, list_comment.tmpl. This is a template file. It’s processed by the Movable Type code to produce output. It’s very much like a simple (HTML) web page, but with a few added tags in there to handle displaying things correctly. You can load it in your favorite HTML editor, but because of these extra tags, it might not work that well. I use Wordpad for this reason. Actually, I use Wordpad for HTML too, so that’s not really a very good example.

Once loaded, look for this section:

  <select name="filter">
  <option value="email"><MT_TRANS phrase="Email"></option>
  <option value="author"><MT_TRANS phrase="Name"></option>
  <option value="ip"><MT_TRANS phrase="IP Address"></option>
  </select>&nbsp;

Wherever you would like it to show in your template, add this line:

  <option value="pending"><MT_TRANS phrase="Pending"></option>

The end result should look something like this (the order of the elements may differ, and that’s okay):

  <select name="filter">
  <option value="email"><MT_TRANS phrase="Email"></option>
  <option value="author"><MT_TRANS phrase="Name"></option>
  <option value="ip"><MT_TRANS phrase="IP Address"></option>
  <option value="pending"><MT_TRANS phrase="Pending"></option>
  </select>&nbsp;

This allows you to select Pending from the drop-down list and filter your comments. You can change the “phrase” portion to read something else if you like, but don’t change the “value” portion of that line unless you change the corresponding place(s) in the rest of the example.

Now that you can select pending entries on the screen, you need to be able to have Movable Type provide those entries to you. So load CMS.pm now, and search for this line:

  sub list_comments {

18 lines below this line, you’ll find this line:

  my $limit = $q->param('limit') || 20;

This line appears several times in CMS.pm, so make sure that you are working with the correct one (that is, the one found in list_comments). Just below this line, add this block of code:

  if ($q->param('filter') eq 'pending') {
  $terms{visible} = 0;
  }

This simply allows the processor to select only items that are not visible – that is, items waiting for approval. That’s it. You’re done. Now all you have to do is click the “select all” button, which will put a check on each line, and then click delete (and confirm). They’re gone. One word of warning: You should approve any valid comments prior to performing this action, otherwise the valid ones will be gone too.

Update: I do offer Movable Type consulting services. If this seems like too much for you, but you’d like to have such a feature, contact me and let’s see if we can work something out.

Leave a Reply

Your email address will not be published. Required fields are marked *