Personal tools
shadowfax.org.uk logo
Views

Wordpress as comment engine for Mediawiki

From Shadowfax

Jump to: navigation, search

MediaWiki is great as a lightweight CMS, but there are some things that it doesn't do so well. Discussion tabs may be great in a wiki - but for discrete comments by non-logged in users they don't fare so well. fortunately adding a comment engine to MediaWiki is pretty straightforward.

I was going to make my own lightweight comment engine until I stumbled across Greg Perry's extension which allows Wordpress to be used as a comment engine for MediaWiki. Given that I was planning to use Wordpress as a blogging engine it seemed the ideal comment engine to use on this site (thanks Greg!). Greg's page which used to hold the code no longer exists and I have been unable to contact Greg, so I have taken the liberty of duplicating the MediaWiki Wordpress Comment Extension Code on this site.

I have also managed to obtain a copy of Greg's original code, which is presented on an as is basis. At some stage soon I hope to have a bit of time to clarify all this and add some decent usage notes to it.

In its initial form, however, there were a few minor issues with the approach - some of which I have fixed.

  1. You need to create a separate blog entry for each mediawiki page being commented on, otherwise the comments are shared with all pages being commented on
  2. It redirects the user to the wordpress page on comment completion
  3. It needs to be entered into each wiki page article.
  4. Error messages appear on a non-branded and rather empty page
  5. It assumed that the Wordpress was installed in the same database as MediaWiki

The following sections detail possible fixes to some of these items. I'm relatively new to both wordpress and mediawiki so I can't guarantee that these are the most efficient ways to apply the fixes, but they do work.

Get the code

Contents

One blog entry for all comments

To fix the first issue requires modifying the Wordpress database to add a field to a table and editing the Wordpress core. It is worth backing up the appropriate files before you make any changes - and I disclaim any responsibility if you break your wordpress installation. You have been warned!

With this mod in place only one blog entry is needed, but each wiki page has its own unique comment stream. Note that this only works if page names in the wiki are unique and less than 255 characters. Also note that moving/renaming a page will break the link to any existing comments.

From MySQL prompt

USE wordpress-database-name-here;
ALTER TABLE wp_comments ADD wikipage varchar(255);

In wp_insert_comment (found in wordpress/include/comment.php

//add the following line
if (!isset($comment_wikipage)) $comment_wikipage = '';
 
//And change the insert SQL to 
$result = $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->comments
(comment_post_ID, comment_author, comment_author_email, comment_author_url,
comment_author_IP, comment_date, comment_date_gmt, comment_content,
comment_approved, comment_agent, comment_type, comment_parent, user_id,wikipage)
VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %s)",
$comment_post_ID, $comment_author, $comment_author_email, $comment_author_url,
$comment_author_IP, $comment_date, $comment_date_gmt, $comment_content, $comment_approved,
$comment_agent, $comment_type, $comment_parent, $user_id,$comment_wikipage) );

In wordpress/wp-comments-post.php

//Add the following line
$comment_wikipage     = ( isset($_POST['wikipage']) ) ? trim($_POST['wikipage']) : null;
 
//And modify the $commentdata  line to
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email',
'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID',
'comment_wikipage');

Return the user to wiki page not wordpress

This is a very easy fix since wordpress already looks for a redirect parameter in the posted form. With this tweak in place the user is returned to the wiki page that they posted the comment from not redirected to the wordpress blog. I have already applied this fix in the code presented on this site

Add Comments form to all wiki pages by default

Again relatively straightforward. All you need to do is call get_wordpress_comments() from the mediawiki template file where you want the comments to appear. eg

<?php get_wordpress_comments(); ?>

Applying Styles to the comments

If you are using my version of this extension, you can apply styles to the comments using CSS - either in the main.css for the appropriate skin, or the wiki page MediaWiki:Common.css

The following example code show the elements that can be used. If you want the comment author name to occur on its own line, you can add display: block; to the comment-author section.

#comment-outer {
  text-align: center;
}
 
#comment-list {
  text-align: left;
  margin-left: auto;
  margin-right: auto;
  width: 85%;
}
 
.comment-item {
  margin-top: 4px;
  padding: 10px;
  border: 1pt solid #dedeee;
  background-color: #eef3f5;
}
 
.comment-inp {
  padding: 3px;
  border: 1pt solid #84b0c7;
}
 
.comment-author {
  border: 1pt solid #84b0c7;
  background-color: #d5e1e8;
  padding: 3px;
}


Leave your comment

Comments

Ian @Mishi. I've sent you an email with a suggested solution. Wordpress has changed a bit since this entry was written. I hope to get some time to look at this later in the week, and will post an update here when I get it working.
mishi Hi, thank you very much for your work! I'm trying to implement your code, but I can't find wp_insert_comment in wordpress/include/comment.php
I'm using Wordpress ver 3.2.1 Could you help me? Thanks!
Ian Hi Lucy

Apologies for late reply. I'm not sure I do know. It may be an issue with the style sheet of your wiki. Which version of the script are you using? Greg's 0.9.0 or my 0.10.0?
Lucy I've tried installing wordpresscomments but when I put in the comment section loads before the page and comes up in the top left hand corner. Any ideas why?
Claude Good initiative!
Ian Thanks for the comments, Sandy. Not had much feedback on this hack - so I have no idea if anyone other than me is using it. And I've not used Wordpress MU either. Sorry.
sandy3269 Has anyone tried this with Wordpress MU? I'm in the beginning stages of looking at what you've added to this extension and modifying for multi-user. Oh, by the way, Yambe is a good extension, thanks.
KonstantinMiller Hello. I think the article is really interesting. I am even interested in reading more. How soon will you update your blog?
Ian Coleman Just a comment to prove to myself that this is working correctly!
Menu