MT-W3CValidator: A Movable Type Plugin

Current version is 1.5.0.0 released on 2007-04-17

Contents

What This Plugin Does

This plugin will validate your web pages on the fly when published from Movable Type. The validation is done live against the W3C’s Markup Validation Service by sending your newly published page. A compliant page will then include a badge from the W3C. A non-compliant page will not display a badge.

This plugin was built to address the issue of many web pages claiming to be compliant but are not. They probably were at one time, but as you post things to your blog, you may post non-compliant code now and then and become uncompliant. This plugin makes sure your pages are compliant, before you claim it! Now, if you notice the badge missing from your page, you know something is wrong.

This plugin is not intended to be a tool for debugging and diagnosing why you are not compliant. That is what the W3C’s Markup Validation Service is for. Go there and enter your page name if that is your goal. The goal of this plugin is to just quickly check if you are compliant or not and show the badge when you are compliant.

Requirements

  • This plugin works with Movable Type version 3.3 and higher.
  • Perl version 5.8.5 or higher. This is what I use. It may work on lower versions. Let me know if it does and I will lower this.
  • This plugin will only work in static (not dynamic) templates.

Installation Instructions

  1. Download the latest version of the plugin.
  2. Unzip the contents of the file.
  3. Copy the file W3CValidator.pl to your Movable Type “plugins” directory. (If you don’t have a plugins directory, create a plugins directory in the same directory where your mt.cgi file is located. Then upload W3CValidator.pl into the newly created plugins directory.)
  4. Give me some credit. You have many choices. Do one or all! 1) Add a trackback link to this page on your page. 2) Donate so that I continue to enhance this plugin.

How To Use The Tags

This plugin will only work in static (not dynamic) templates.

  • MTW3CValidate
    A container tag that should surround the entire contents of your page. Ideally, this should be the first and last tag in your template file. All output between these tags is used in the validator.

  • MTW3CValidBadge
    This tag returns the standard image HTML as recommended by the W3C for valid pages. Place this tag within the MTW3CValidate tags where you want the image to appear. If the page is not valid, this tag returns nothing. This tag must be placed within the container MTW3CValidate.

  • MTW3CValidBadgeCustom
    A container tag that allows you to specify your own HTML for the valid badge instead of using the default HTML recommended by the W3C. Some people like to use other smaller images or save the image to their own server. Place these tags within the MTW3CValidate tags where you want the image to appear. If the page is not valid, these tags returns nothing. This tag must be placed within the container MTW3CValidate.

  • MTW3CInvalidBadgeCustom
    A container tag that allows you to specify your own HTML for the invalid badge. If the page is valid, these tags returns nothing. This tag must be placed within the container MTW3CValidate.

  • MTW3CValidatorOutput
    A tag that prints out the HTML returned from the validator. If your page is not validating, this should give you information on why its not working. This tag should only be used to debug your installation if you are having problems. This tag is not meant to be an every day debugging tool for invalid pages. You will want to just use the validator for this. A word of caution, this tag will blindly insert the contents of the validator response into your web page — that combination is guaranteed to be invalid because its a page within a page. Again, this is only a debugging technique. This tag must be placed within the container MTW3CValidate.

Frequently Asked Questions

  • Q: Are there any other plugins that can help me format my entries to be XHTML-compliant?
    A: Yes, I use and recommend SafeHref to help encode URLs that I put on my pages. URLs are normally the number one thing that breaks compliance. Its a great help. You can also use Amputator to fix those pesky ampersands.

  • Q: This plugin (and others) don’t seem to be working on my server. Why?
    A: Internally, Movable Type requires some Perl modules to be installed for plugins to work. Some servers do not have these modules installed by default. Please run mt-check.cgi on your server to find out what you are missing.

Examples

1. In this simple example, we create a page that is validated and has the badge displayed.

<MTW3CValidate>
<!DOCTYPE html PUBLIC 
      "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
         <title>Virtual Library</title>
      </head>
      <body>
         <p>Moved to <a href="http://example.org/">example.org</a>.</p>
         <MTW3CValidBadge>
      </body>
   </html>
</MTW3CValidate>

2. In this simple example, we create a page that is validated and has a custom badge displayed.

<MTW3CValidate>
<!DOCTYPE html PUBLIC 
      "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
         <title>Virtual Library</title>
      </head>
      <body>
         <p>Moved to <a href="http://example.org/">example.org</a>.</p>
         <MTW3CValidBadgeCustom>
         [My page is XHTML-valid, dude!]
         </MTW3CValidBadgeCustom>
         <MTW3CInvalidBadgeCustom>
         [My page is NOT XHTML-valid, dude!]
         </MTW3CInvalidBadgeCustom>
      </body>
   </html>
</MTW3CValidate>

Donate

If you enjoy using this plugin and/or would like to see it enhanced, please donate a buck or two…or fifty. I will use the money to buy my wife dinner so she lets me keep working on this stuff for free and does not complain.

License

This software is licensed under the CC-GNU LGPL.

CC-GNU LGPL

Download

Download the current version from the link below. Past versions are not archived.

Version History

1.5.0.0 — 2007-04-17
  • Updated to use W3C header parsing instead of page for results.
1.0.1.0 — 2005-09-04
  • Updated plugin info to take advantage of MT 3.2 enhancements.
1.0.0.2 — 2004-12-10
  • Fixed bug where plugin reported error in MT-Medic.
1.0.0.1 — 2004-11-11
  • Fixed defect where errors generated by other tags within MTW3CValidate tag did not show errors correctly.
1.0.0.0 — 2004-01-02
  • Made compatible with Movable Type 3.0.
0.37 — 2004-01-02
  • Change URL link for plugin.
0.36 — 2003-11-20
  • Added an “Unable to connect” message in the place of all the tags when your server cannot connect to the validator service.
0.35 — 2003-11-19
  • Added the MTW3CValidatorOutput tag to help people debug their site.
0.31 — 2003-11-03
  • Removed the border attribute from the built-in validation badge because its not valid XHTML-Strict. I use XHTML-Transitional on my pages so I didn’t notice.
  • Added copyright notice for tracking usage.
0.30 — 2003-10-19
  • Added ability to specify custom HTML for invalid badge.
0.20 - 2003-10-14
  • Added ability to specify custom HTML for valid badge.
0.10 — 2003-09-24
  • Works for me.

Contact

For questions, suggestions, bug reports, and anything else related to this plugin, please e-mail brandon@fuller.name or leave a comment.

Related Posts with Thumbnails
Updated: 2009-11-25 at 10:50 MST in Hacks
Tags: movabletype

26 Comments

Lisa

I love this plugin, thanks for making it available. Is it possible you'd add a formatting option to let us use our own images? I hate cross-referencing, plus I'd like to use a smaller image for the succesful pages.

Thanks tho, great job. =)

Brandon Fuller

Done. Version 0.20.

Lisa

Worked brilliantly, thanks for fixing that so fast =) Great work again, thanks Brandon!

Martin Bokman

Now you opened up a can of worms :)

What do you think of the following:

<MTW3CInvalidBadgeCustom>
[Uh-oh, the page is invalid, click <a href="http://validator.w3.org/check/referer/">HERE</a> to see why]
</MTW3CInvalidBadgeCustom>

Anyhow, kudos for the plugin as it is already.

Brad

Y'all -

I love Martin's idea, but I think the more sensible/complete format would be:

<MTW3CIfValid>
[my celebration of validity]
<MTElse>
[not valid! go to http://validator.w3c.org/check.cgi?blahblahblah]
</MTElse>
</MTW3CIfValid>

That way both possibilities are contained in a single syntax, and you can just omit the MTElse clause if you want to hide or ignore your regrettably invalid state.

Anyone else like that?

Just my $.02,
- Brad

Brandon Fuller

Ok, the invalid tag was added. Thanks for the suggestions.

Michael Urspringer

Thanks for this Plugin. Works great. Also use and like the invalid tag.

scrooks!

Ironically, your validator is generating invalid code. :-) I'm making all my page XHTML 1.0 Strict, but your tag uses the "border" attribute in the IMG element, which is not allowed in XHTML strict. For an example, try to validate http://www.scrooks.net. You can see on that page that your plugin marks it as valid, but then if you click on the "Valid" icon the WC3 validator runs and flags the border attribute as invalid.

Other than that, I really like this tool! :-)

Brandon Fuller

I have the border="0" attribute all over the place and the pages still validate. The issue is that I use XHTML-Transitional and you are using XHTML-Strict. Strict is pretty brutal because it gets rid of lots of things people like to use. But in an effort to please the strict folks, I will remove my border="0" attribute from the built-in badge HTML. If you are a Transitional guy or gal, just use a custom badge and add it back in. No biggie.

Neely

This tool is just what I've been looking for, but for some reason MTW3CValidator claims that my XHTML is *not* valid, even though manually running the same page through http://validator.w3.org/ tells me that the XHTML *is* valid. I've thoroughly read the instructions on this page, but I can only assume I'm missing something forehead-slappingly obvious.

P.S. My log is pretty profane, so be aware if you decide to visit it. :-)

Brandon Fuller

I added in a tag, MTW3CValidatorOutput, today that allows you to print out the response that is sent back from the validator. This should help you figure out why the validator thinks your page is not valid.

Neely

Thanks for that. I'm not getting any output at all from MTW3CValidatorOutput, so it looks like the W3 validator site isn't even being contacted. It's obviously something wrong with my server or MT setup. I'll have to look into it.

Brandon Fuller

I changed all the tags so they print a message when your server cannot connect. Give that a try.

Neely

Again, thanks for your help. MTW3CValidator is indeed printing the 'Unable to connect to validator service' message so, as this plug-in works for everyone else, I can only assume something on my server (running OS X 10.3.1, MT 2.64, perl 5.8) is askew. I have all the modules called by MTW3CValidator, MT is seeing and running the plug-in, but the connection to the W3C server simply isn't making it. Other installed MT plug-ins (including one I wrote myself) work, however none of them need to connect to an external site. I won't be able to do any serious tinkering until after the weekend, but if I find a solution I'll post it here.

Neely

Hooray! I finally got MTW3CValidator to work. In an unrelated housekeeping thing, I updated some Perl modules last week, and that seems to have made the plug-in work. I have absolutely no idea why that should be, but it works nonetheless. Thanks for all your help and plug-in updates, Mr Fuller. I have tracked back (trackbacked?) to this page from my site.

Neely

Just installed version 1.0.0.0 and it's working fine - and I notice that the credit lines that MTW3CValidator used to place in the HTML of validated pages have been removed. That's really important for someone like me on a slow server, where shaving every byte off my code makes a difference, so thanks for doing that and thanks for the plug-in.

Jim

Hi Just tried your plugin with MT3.01D. It worked in principal but it made my comment section to be "Need to Sign-In" when I didn't specify that. My Comments are Non-Sign-in and with TypeKey sign-in and not moderated.

Brandon Fuller

Sorry, but that makes no sense to me. I use the plugin and have no comments issues. Further, I can't draw a connection between the two.

Jim

Hi Brandon, neither do i. :)

Its just that when I added the tags at the top and bottom of the script, my comments will display as if it requires Sign In and doesn't accept non-registered comments.

Its no biggie anyway. :)

Murk

I'm having some problems getting things to run. (MT3.11)

I've put the .pl file into plugings, and have CHModded to 755 (is this right?)

In the template I have this:

Testing:
<MTW3CValidBadgeCustom>
valid
[My page is XHTML-valid, dude!]
</MTW3CValidBadgeCustom>
<MTW3CInvalidBadgeCustom>
invalid
[My page is NOT XHTML-valid, dude!]
</MTW3CInvalidBadgeCustom></ br>

(thinking I'll test the thing out and then worry about getting the badge displaying later)

... all I see in the page source is this:

Testing:

<!-- VALIDBADGECUSTOMVALIDBADGECUSTOM -->
<!-- INVALIDBADGECUSTOMINVALIDBADGECUSTOM --></ br>


I have to be missing something here.... but I can't see what. Any ideas?

Brandon Fuller

Simple -- you are missing the main tags. Notice in all the samples that the page is surrounded by <MTW3CValidate> tags? Add those in.

Murk

Doh!

Cheers. Rather subtle those things, though :)

Murk

Smashing - now works a treat, it's now a matter of pure presentation. Of course, I'll link here with the eventual code.

I wonder now... can I do the same thing with the CSS validator?

Monolith aka Mikey

Here's a silly question. I'm running Perl 5.8.0. The W3C site is working fine. I'm getting the ‘Unable to connect to validator service’ message. Would having a version of Perl older than 5.8.5 cause this error?

Monolith aka Mikey

Never mind that, I just upgraded to Perl 5.8.7 and I get the same, ‘Unable to connect to validator service’ message.

Justin Clarke

This did not appear to be working for me, even though I did not get the "Unable to connect to validator service" error message. From reviewing the output from the MTW3CValidatorOutput I found the culprit.

The plugin is looking in the returned page for <h2 id=result class="valid"> whereas the page returns <h2 class="valid"> when the page is valid

Leave a comment

(Required)
(Required, Hidden, Gravatar - Click to upload your own photo!)
(Optional)