Applications

RightFields 1.21

Spam Prevention

TinyTuring 1.02

Template Tags

CheckLinks 1.2

Collect 1.2

Columnize 1.11

Compare 1.1

DateTags 2.3

DaylightOrStandard 1.1

DropCap 1.1

FilterCategories 1.1

FirstNWords 1.3

GetXML 1.1

Glue 1.1

IfModified 1.4

Loop 1.1

TextWrap 1.1



Support staggernation.com's plugin development

CheckLinks Plugin for Movable Type

Current version: 1.2 (7/12/04)

About the CheckLinks Plugin

This Movable Type plugin implements a set of template tags for identifying invalid link URLs within entries.

If your site has been around for a while, a few or many of the pages you've linked to in the past may have ceased to exist or moved to new locations. Also, if you tend to link to a large number of pages, you might not be in the habit of clicking on each and every link to check it, so some URLs might not have been valid in the first place. The CheckLinks plugin tries to access all the URLs linked to in your entries (or a subset of your entries), and lets you display a list of the ones it can't successfully access.

These tags are intended to be used on an index template, most likely one you don't display to readers, but one you periodically rebuild so you can look over the results. Since trying to access all the links is a time-consuming operation, you'll probably want to turn the "Rebuild this template automatically when rebuilding index templates" option off for the template on which you place the CheckLinks tags.

If a URL has already been accessed successfully within a given instance of MTCheckLinks, the plugin will not attempt to re-check it if it encounters another link to the same URL. This should speed up execution if you tend to link to the same URLs repeatedly.

Please note that simply because the plugin identifies a link as bad doesn't necessarily mean it's bad; it's possible a site was just momentarily inaccessible. You'll have to investigate the "bad" links yourself and determine how to handle each on a case-by-case basis.

The CheckLinks plugin keeps track of the HTTP status line returned by each unsuccessful request it sends. The status includes a three-digit code (for example, 404 means the page was not found on the server) and a textual description of the error. With the MTIfBadLinks, MTIfNoBadLinks, and MTBadLinks tags, you can restrict the listing of bad links to those with particular status codes. An explanation of the codes can be found here.

Installation

To install the CheckLinks plugin, upload the file CheckLinks.pl to the plugins directory within your Movable Type directory. If you do not already have a plugins directory, create one before uploading the file. For more information about Movable Type plugins, see the documentation.

The CheckLinks plugin requires the LWP::UserAgent Perl module. This module is used by Movable Type for some optional functionality, and MT's documentation has instructions on how to install it if it's not already installed on your system. (To find out whether it's installed, you can run MT's mt-check.cgi script.)

Support

Please use the support forums for all support requests, bug reports, feature requests, questions, and comments regarding this plugin.

MTCheckLinks

This container tag is the master tag that tells the plugin you're going to be checking links and collecting bad links. All other tags in the CheckLinks plugin must go within MTCheckLinks.

Within MTCheckLinks, first use MTCheckLinksHere to indicate the entry text containing the links to check, and then use the "BadLink(s)" tags to display the results of the checking.

If you want to create a single listing of bad links for multiple entries, MTEntries should go within MTCheckLinks. If you want to display each entry's bad links separately, MTCheckLinks should go within MTEntries, as in the following example:

<MTEntries>
 <p><b>Entry:</b> <$MTEntryTitle$><br>
 <MTCheckLinks>
  <MTCheckLinksHere>
   <$MTEntryBody$>
   <$MTEntryExtended$>
  </MTCheckLinksHere>
  <MTIfBadLinks>
   <b>Bad links:</b>
   <MTBadLinks>
    <br><$MTBadLinkURL$> (<$MTBadLinkStatus$>)
   </MTBadLinks>
  </MTIfBadLinks>
  <MTIfNoBadLinks>
   <b>No bad links found</b>
  </MTIfNoBadLinks>
 </MTCheckLinks>
 </p>
</MTEntries>

The tag takes the following attributes:

  • proxy="http://proxy.url" (optional)
    If your MT installation is behind a firewall and you need to use a proxy server to reach external sites, you can tell CheckLinks to use the proxy by passing this attribute.
  • no_proxy="domain1, domain2..." (optional)
    If you're using the proxy attribute, CheckLinks may not be able to reach links to sites behind your firewall that should not be accessed through the proxy. To specify that CheckLinks should not use the proxy for links to certain domains, pass one or more domain names in the no_proxy attribute.

MTCheckLinksHere

This container tag should surround the text within which you want to check links. When MTCheckLinksHere is called multiple times within a single MTCheckLinks container, it accumulates all the bad links it encounters into a single listing.

The tag takes the following attributes:

  • show="1" (optional)
    By default, MTCheckLinksHere does not display its contents. If you want to display the contents of the tag, pass show="1".
  • include_local="1" (optional)
    By default, the plugin will not attempt to check relative links to pages on your own site—that is, HREFs for which the site is not specified, such as href="/mysite/archives/foo.html". Pass include_local="1" if you want the plugin to check relative links, which it will do by getting the site name from the Site URL specified in your weblog configuration and adding it to the beginning of the HREF.

MTIfBadLinks

This container tag displays its contents if and only if some bad links were found by MTCheckLinksHere.

The tag takes the following attributes:

  • status="code,code2.." (optional)
    If one or more three-digit HTTP status codes are passed in this attribute, the tag will display its contents if and only if one or more bad links were found with any of the specified codes. Multiple codes should be delimited by commas.
  • omit_status="code,code2.." (optional)
    If one or more three-digit HTTP status codes are passed in this attribute, the tag will display its contents if and only if one or more bad links were found with any code other than the specified codes. Multiple codes should be delimited by commas.

MTIfNoBadLinks

This container tag displays its contents if and only if no bad links were found by MTCheckLinksHere.

The tag takes the following attributes:

  • status="code,code2.." (optional)
    If one or more three-digit HTTP status codes are passed in this attribute, the tag will display its contents if and only if no bad links were found with any of the specified codes. Multiple codes should be delimited by commas.
  • omit_status="code,code2.." (optional)
    If one or more three-digit HTTP status codes are passed in this attribute, the tag will display its contents if and only if no bad links were found with any code other than the specified codes. Multiple codes should be delimited by commas.

MTBadLinks

This container tag loops through the bad links that were found by MTCheckLinksHere, displaying its contents once for each bad link. Within MTBadLinks, use MTBadLinkURL, MTBadLinkStatus, and MTBadLinkText to display information about each link.

The tag takes the following attributes:

  • status="code,code2.." (optional)
    If one or more three-digit HTTP status codes are passed in this attribute, the tag will loop through only those bad links that have any of the specified codes. Multiple codes should be delimited by commas.
  • omit_status="code,code2.." (optional)
    If one or more three-digit HTTP status codes are passed in this attribute, the tag will loop through only those bad links that have any code other than the specified codes. Multiple codes should be delimited by commas.
  • sort_by="url|status|text" (optional)
    By default, MTBadLinks will list the bad links in the order in which they were found by MTCheckLinksHere. To display them sorted by URL, HTTP status, or link text, use the sort_order attribute.
  • sort_order="ascend|descend" (optional)
    The order in which the listing should be sorted, if a sort_order was specified. The default is an ascending sort.
  • skip_dupes="1" (optional)
    Pass this attribute if you don't want to show multiple instances of the same bad link URL.
  • load_entries="1" (optional)
    If you're checking links in multiple entries at one time (MTEntries within MTCheckLinks), you'll probably want to indicate which entry each bad link appears in. Passing load_entries="1" causes MTBadLinks to load the entry associated with each bad link. You can then use any of the MTEntry tags within MTBadLinks, as in the following example:
    <MTCheckLinks>
    <MTEntries>
      <MTCheckLinksHere>
       <$MTEntryBody$>
      </MTCheckLinksHere>
     </MTEntries>
     <MTBadLinks load_entries="1">
      <p><$MTBadLinkStatus trim_to="3"$>: <$MTBadLinkURL$><br>
      Found in entry: "<$MTEntryTitle$>"</p>
     </MTBadLinks>
    </MTCheckLinks>

MTBadLinkURL

Within MTBadLinks, this tag displays the URL of the current bad link.

MTBadLinkStatus

Within MTBadLinks, this tag displays the HTTP status that was returned for the current bad link. The status is a line of text that begins with a three-digit code; if you only want to show the code, use trim_to="3" (a Movable Type global attribute).

MTBadLinkText

Within MTBadLinks, this tag displays the link text (whatever's between the opening <a> and closing </a>) of the current bad link.

Version History

7/27/05 - version 1.3

  • Added proxy and no_proxy attributes to MTCheckLinks (Bobb Menk).

7/12/04 - version 1.2

  • Plugin now registers itself with MT 3 interface.
  • Added $VERSION variable.
  • Conditional container tags are now declared as conditional tags, so they should work with MTElse.
  • All container tags now pass conditions along when building contents, so they'll work outside conditional tags within MTEntries, etc.

6/5/03 - version 1.1

  • MTCheckLinksHere now does not re-check URLs it's already fetched successfully
  • Removed some superfluous error checking

6/3/03 - version 1.0 released


The End As I Know It: A Novel of Millennial Anxiety, by staggernation.com proprietor Kevin Shay, is now available in paperback.

Please visit kshay.com for more information.