Patch Mephisto to add a comments list filter
posted: April 4th, 2007 · by: Sven
Mephisto is backed by Akismet when it comes to comment-spam-protection and this duo works pretty well. But like any such system it’s not 100% foolproof and therefor Rick has build it that way that comments are put aside, not completely deleted when Akismet thinks that it’s spam. You’re supposed to log into the admin interface, go to “Moderate comments” and then review them. You can approve or delete the comments separately or delete them all at once.
That’s all pretty reasonable and handy. But when I scrolled through my 900 spam comments yesterday I found myself really wanting to filter the list by keywords like “cialis” or “toyota” (what the heck is so cool about Toyota newly?). This way I could reduce the list by the largest portions in some steps and then only have to review the rest of it.
I looked at the source code and found that it’s pretty super simple to patch in support for this kind of feature. So, here you go.
The controller part
The filter keyword can be put into the URL parameters like in admin/comments?filter=toyota so nothing needs to be changed in the routes. We can access the parameter right away in the controller action with params[:filter].
Thus all that’s needed here is to change the index action of Admin::CommentsController to constrain the selected comments by the keyword if one is present.
That’s easy. We’ll just replace this line:
@comments = site.unapproved_comments.find(:all, :include => :article)
… by this slightly longer piece of code:
condition = [:body, :author, :author_url].collect do |column|
"contents.#{column} LIKE '%#{params[:filter]}%'"
end.join(' OR ') unless params[:filter].blank?
@comments = site.unapproved_comments.find(:all, :include => :article,
:conditions => condition)
That’s all. You now can try and add a filter=something parameter to your URL and the comments list should be filtered accordingly.
Later on we might want to refactor this and move the condition building and querying stuff into the Site or Comment model.
The view part
Everything that remains to do now is to add some kind of HTML form to the admin interface that allows to enter a keyword and sends it to the appropriate action.
I’ve added the following to the admin/comments/index.rhtml template:
<!-- begin action nav -->
<div id="page-nav">
...
</div>
<div id="filter" class="manual">
<form action="">
<label>Filter
<input type="text" name="filter" value="<%= params[:filter] %>">
</form>
</div>
<!-- /end action nav -->
And adjusted the design with the following addition to the mephisto.css stylesheet (located in the public/stylesheets/mephisto directory):
#filter {
...
height: 35px;
}
#filter form {
float: right;
margin: 6px;
font-weight: bold;
text-shadow: #FFFFFF 2px 2px;
}
Here’s a patch
I’ve filed away a patch for my personal backup purposes: admin_filter_comments_list.diff. I believe it should work with any default Mephisto installation as well.
moein said January 8th, 2011 at 01:36 PM ¶
??????? ?????? ???????? ????? ? ??? فارکس ایران
http://www.nikgraphic.com
jack said January 23rd, 2011 at 11:39 AM ¶
thanks for that headsup. That’s a useful tip! I’ve never ran into that, but for sure that’s something quite some people will need a solution for. cheap vps
chat said March 31st, 2011 at 07:34 PM ¶
This fix worked better:
Dependencies.loadoncepaths -= Dependencies.loadoncepaths.select{|path| \ path =~ %r(^#{File.dirname(FILE)}) }
Okey oyunu said May 12th, 2011 at 04:06 PM ¶
Thanks for this article. Tüm dünya artik okey oyunu oynuyor. Yillardir bir çok oyun programi olmasina ragmen, içlerinden en güzeli olarak nitelendirebilecegimiz tek bir site göze çarpmaktadir. Diger tüm okey oyunu programlarinin aksine ücretsiz olmasi ve 3 boyutlu olarak hizmet vermesi mükemmel bir gelismedir. Sizlerde www.okey-oyunu.com adresinden bu essiz okey oyununu indirebilirsiniz. Kullanimi çok basit ve Türkçe dil seçenegi ile kolaylikla oyuna baslayabilirsiniz. Ister kendi ülkenizden, isterseniz dünyanin tüm farkli bölgelerinden dilediginiz oyun odalarini seçerek, oyuna hemen baslayabilirsiniz. Okey oyunu oynamak için artik arkadas bile aramaniza gerek kalmadan, bilgisayarinizdan 100 binlerce üye ile online olarak okey oyununu oynamanin zevkine varabilirsiniz.