MTValidate Plugin

Current Version: 0.5 (1/10/2007) [download]

Introduction

This plugin is a wrapper around the code that powers the W3C Validator. You can use it to ensure that anything that might appear on your blog (entries, comments) is valid (X)HTML. Originally authored by Alexei Kosut, I seem to be maintaining it now.

The plugin provides 3 MT tags

<MTValidate>

This is a container tag, the contents of which will be passed to the Validator. For example,

<MTValidate>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>Validating Your Comment</title>
 </head>
 <body>
  <h3>Your Comment</h3>
   <$MTCommentPreviewBody$>
   <p class="comments-post">Submitted by <$MTCommentPreviewAuthorLink$> at <$MTCommentPreviewDate$></p>
 </body>
</html>
</MTValidate>

in the Comment Preview Template will validate the user's comment, and return a message saying either that the comment was valid or listing the errors it contained. Note that the content of this tag must expand to a fully-formed (X)HTML document, including a DTD.

<MTValidateIfValid>

A conditional tag, which will display its content if the preceeding <MTValidate> processed a valid document.

<MTValidateIfInvalid>

A conditional tag, which will display its content if the preceeding <MTValidate> processed an invalid document.

Examples of the usage of this plugin for validating comments can be found here and here.

Installation

This may be the trickiest part. There are a number of prerequisites. If you are on a good webhost, everything you need will be already there. If not...

  1. First, you need the onsgmls SGML parser (part of the OpenSP distribution). This is standard on Linux, where it's located at /usr/bin/onsgmls. On MacOSX, the easiest way to install it is using fink:
     fink install opensp
  2. Next, you'll need a bunch of Perl modules. Most of these are standard. Some, marked with an asterisk, are required for MovableType (and so you almost certainly have them already)

    • Config::General (≥2.06)
    • File::Spec*
    • File::Temp*
    • HTML::Entities*
    • HTML::Parser (≥3.25)
    • HTML::Template (≥2.6)*
    • Set::IntSpan
    • Text::Iconv
    • Text::Wrap
    • XML::LibXML (optional: needed if you set XHTML_Check = 1)

    The whole shebang (and a few superfluous modules) can be installed via CPAN, using

    install Bundle::W3C::Validator

    More detail about installing via CPAN (especially, if you don't have root access) can be found in this old blog entry.

  3. Download, uncompress and untar the plugin. You will find a validator folder that you should place inside the plugins folder of your MovableType installation.
  4. Download, uncompress and untar the sgml-lib folder and place it inside the validator folder.

  5. Open up the file validator/config/validator.conf and make sure the location of onsgmls is set correctly. Also, decide whether you want to enable additional checking of XHTML files. If so, set

    XHTML_Check  = 1
  6. Now copy the validator folder to your MovableType plugins directory and enjoy ...