Keeping Computer Books Up-to-Date

Charles Wright in the Sydney Morning Herald:

With the number of blogs increasing at a phenomenal rate, more people than ever will find themselves dealing with the market-leading Movable Type. The Movable Type 3 Bible, from Wiley, gives you a thorough grounding in the complexities of a blogging platform that, on the surface, looks relatively easy to master but repays the effort required to learn about its more powerful features. Increasingly, these books are rendered somewhat out of date with the release of new versions, which this book promises to solve with an update site. Frankly, there's not much there, but there is a link to the author's site.

A truism of computer book writing is that a new software release will be announced the day after your book goes to press on the same subject. I need to write more on Workbench about Movable Type's PHP publishing features in advance of the book's next edition, but otherwise it keeps current with version 3.

I've always thought that computer books should be paired with active web sites, which is why there are more than 5,000 pages on this server supporting my books. I occasionally get a nice email from someone who picks up an eight-year old copy of Teach Yourself Java 1.1 Programming in 24 Hours and is pleasantly surprised to find the support site online.

As I told Wright in email, with the dot-com bust and the abundance of free technical information on the web, the economics of supporting a book after publication have never been uglier.

I should not have been so quick in college to choose journalism and computer science over a career in interpretive dance.

Changing Weblog Software is Drudge Work

I just finished moving the Drudge Retort from Movable Type to Wordzilla, my PHP/MySQL software that runs Workbench, giving all 14,400 weblog entries and 233,000 user comments a new home. The project took 10 days, around eight more than I expected.

The Retort is emulating Daily Kos by giving site visitors the tools to create their own blogs. I'm going to choose interesting user blog entries for the main page and home page to run alongside my own blog entries -- I've always wanted to give the kids a chance to drive the family car.

There are 270 users who've written blog entries. One of the most active is by Niceville, a relentless contributor whose politics lie to the right of Alan Keyes, even though the Retort leans left. User blogs support visitor comments, RSS feeds, page caching, membership, and ping notification. Anyone who wants to try it out can join the site and begin blogging.

From now on, I'll be multiplying all project time estimates by five. My next book, an irreverent beginner's title on Java 2 version 1.4, will be completed in November 2007. Pre-order it today.

Let's Put Everything on the Table

Of all the insults I received for popesquatting, the ones that stung the most were about my web skills, such as this comment on MetaFilter:

Eh, his website needs work. The text overflows the white box and he must've used the nowrap attribute as there is a hideous amount of rightwards scrolling. pls fix ur website b4 u sho it to teh whirled, pls ok tks.

Ouch. F U 2.

I like three-column designs, so I lay out my sites with HTML tables, often putting ads in the rightmost column. This lends itself to a creative trick some cranks like to employ -- putting a really long word in a comment to hose my layout and push ads way off the page, depriving me of money I need to put food on my family.

I'm currently moving the 14,000 weblog entries and 232,000 comments on the Drudge Retort from Movable Type to my Wordzilla PHP/MySQL software, so I wanted to solve this long-word problem.

I can't use PHP's wordwrap() function, which breaks long words that exceed a set maximum, because my weblog comments include hyperlinks. Any URL longer than the maximum would be broken.

I found a nice open source PHP script by Brian Huisman, htmlwrap, that solves this problem:

htmlwrap() is a function which wraps HTML by breaking long words and preventing them from damaging your layout. This function will NOT insert br tags every "width" characters as in the PHP wordwrap() function. HTML wraps automatically, so this function only ensures wrapping at "width" characters is possible. Use in places where a page will accept user input in order to create HTML output like in forums or blog comments.

David Raynes has released Workflow, a plug-in for Movable Type that adds fine-grained editing capabilities to weblog authors. As Anil Dash explains:

Workflow lets you limit control of publshing rights to certain authors in your Movable Type installation, allowing other people on the system to act as editors and review entries before they're published. Administrators can control who has rights to any of these levels of permissions. Plus, authors can transfer ownership of a post to other authors and they'll be notified by email when the transfer happens.

The most remarkable thing about this release, which is supported by a free personal license and $250 commercial license, is that the Workflow plug-in can be extended with plug-ins.

I'm skeptical that third-party developers can be profitable creating add-ons to weblog software, even a product as popular as Movable Type. As the author of books on Radio UserLand and Movable Type, I'm finding it difficult when the pool of potential customers is limited to a single weblog tool, though I greatly enjoyed writing the books.

But I'd love to be proven wrong.

Avoiding Movable Type's Comment Date Bug

I was reminded today of a nettlesome Movable Type template bug with how comment dates are displayed by the MTCommentDate tag.

As noted by Michael Hanscom, if you place an MTCommentDate tag inside an MTCommentEntry container, it displays the date and time the entry was published, not the comment's date and time.

A workaround is to place the tag outside the container, even if you have to use two MTCommentEntry containers for the same comment.

Here's template code to display the 10 most recently posted comments with proper timestamps:

<MTComments lastn="10" sort_order="descend"> <MTCommentEntry> <p><a href="<MTEntryLink>"><MTEntryTitle></a> <MTCommentBody> Posted by <MTCommentAuthorLink spam_protect="1"></MTCommentEntry> <MTCommentAuthorIdentity> at <MTCommentDate><MTCommentEntry> | <a href="<MTEntryLink>#reply">Reply</a><br clear="all"> </MTCommentEntry> </MTComments>

Incidentally, in Six Apart documentation and most books on the subject, template tags like MTCommentDate include dollar signs in their names, as in <$MTCommentDate$>.

In writing Movable Type 3 Bible Desktop Edition, I decided to never put dollar signs around tags. They're unnecessary -- you can refer to all tags without them -- and they don't work with container tags, so it's a confusing aspect of template creation.

Linking Plain URLs in Movable Type Comments

I run an active Movable Type-driven site where visitors include hyperlinks in their comments using HTML markup like this:

Read more on <a href="">Ekzemplo</a>

A lot of people don't know HTML, so they paste URLs:


This is less useful and causes presentation problems when a long URL takes up more space than the site's tables can handle, pushing the right margin off the edge.

I needed to turn plain URLs into hyperlinks without messing up existing links in HTML, so I tried Brad Choate's Regex plug-in, which enables regular expressions to process any Movable Type tag's output.

With a lot of trial-and-error and the help of an online regex tester, I used the plug-in's MTRegexDefine tag to define three find-and-replace regular expressions (in Perl syntax):

A global tag attribute, regex, causes these expressions to be used on its output:

<MTCommentBody regex="1">

Plain URLs are converted to hyperlinks with their domain as the linked text. The order of the regular expressions is important; the plugin invokes hideanchor, longurl, and then showanchor in that order.

Weblog Software Priced to Move

A factoid from a Ben and Mena Trott interview for anyone starting a mom-and-pop business selling commercial weblog software:

Mena Trott: For the two years that we were just Ben and myself, the donations and commercial licenses supported Ben and myself to run the operation, and we never had to use our savings to pay for our rent or anything; this covered our costs. And we've had a lot of downloads and we've had -- numbers have been really large, but the average price, I mean the average --

Ben Trott: The average donation per download --

Mena: -- is 38 cents, lifetime, not per month! So 38 cents is basically what people have paid for Movable Type, and that's because of the generosity of other people that have decided that they wanted to pay.

Ben Hammersley: "The combination of comment spammers, and the database calls made by mt-comments.cgi and MT-Blacklist, is putting so much load on servers that the admins are having to pull sites down to save the others."

I haven't used MT-Blacklist for my Movable Type sites, because I am loathe to trust third parties to provide up-to-date and correct blacklists. I'm having good results so far by simply closing old entries to comments and trackback.

You May Already Be a Winner

I received around 25 entries in the Movable Type Bible Desktop Edition book giveaway.

Chosen at random from received comments and trackback, the five winners are Elise Bauer, Richard MacManus, Harrison Brace, Christian Crumlish, and Judi Sohn.

I'm also sending one to Hanna for the shameless heart-wrenching tale of hard luck in her contest entry:

I could mention that I'm ridiculously poor, being disabled and a ward of the state. But that would be demeaning, wouldn't it?

I'll be fighting the last-minute Christmas crowds at the post office to mail out these books, dodging surly Floridians with holiday cheer deficiency syndrome who have dug hideous sweaters out from storage for our first (and perhaps last) freeze. Wish me luck.

Before you install MT-Workbench to close old Movable Type entries to feedback, take a look at Conversation Killer, the plug-in I wish I knew about before I did all of that coding.

New Movable Type Tool: MT-Workbench

I have released beta version 0.1 of MT-Workbench, a PHP class library that can close all weblog entries to comments and trackback after they become one week old.

The open source library was written for a Movable Type weblog that uses a MySQL database. The library's closefeedback.php script can be run daily as a cronjob, closing old discussions so they can't be abused by comment spammers trying to boost their Google PageRank.

So far, the results have been heartening on the Drudge Retort, which used to receive 5-10 spams for every 100 visitor comments. In several skims this week, I haven't been able to find any spam.

Rebuilding Movable Type Entries by Cronjob

Thanks to a tip from Richard Eriksson, I've completed the Movable Type utility to close comments and trackback on all weblog entries after they become a week old. I will be releasing it tomorrow under the GPL, assuming it runs properly as a cronjob and closes these seven-day-old entries to new feedback.

I couldn't get the script to work until I used Timothy Appnel's mt-rebuild utility to republish individual entries after they have been closed.

I tried to use Ed Dumbill's excellent XML-RPC for PHP library to rebuild entries, calling the mt.publishPost method for each entry, but couldn't get the calls to work.

I run mt-rebuild from PHP with the language's system function:

system("$this->perl_path $this->mt_rebuild_path -mode="entry" -blog_id=$entry_blog_id -entry_id=$entry_id");

The $this->perl_path and $this->mt_rebuild_path references are object variables that hold the locations of Perl and mt-rebuild.

New: Movable Type 3 Bible Desktop Edition

Hot off the presses: Movable Type 3 Bible Desktop Edition, my new 410-page book on the current edition of the weblog publishing software. I wrote the book to encourage Movable Type webloggers to get into the advanced publishing capabilities of the software, such as template design, plug-in programming, and XML syndication with Atom and RSS.

Movable Type 3 Bible Desktop EditionFor the book, I spent six months combing over the Movable Type documentation, support forums, source code, and database. I stalked several coders who use the software avidly -- Richard Eriksson, Brad Choate, and Jay Allen could have gotten restraining orders -- to see how people were taking the software beyond the basic publishing capabilities that users master quickly on their own.

This is my first book for Wiley, which crams 102,000 words into an edition small enough to carry around. I have never singlehandedly written a longer book that sells for less: at a price of $16.49 on Amazon, you're getting 60 words per penny.

To mark the occasion, I'm giving away five of my author's copies this week. If you'd like to be eligible to win, post a comment on this entry or write about it on your weblog, linking to its permalink so I don't overlook it. I'll also pay the postage to anywhere that I can send it for under $10.

Amazon top-1,000 reviewer Jack Harrington covered the book last week:

Anyone who uses Movable Type on a regular basis needed the book. It covers all of the basics around installation, setting up blogs and writing entries. But then it goes into more advanced topics like alternating the template and adding plugins. And even more advanced topics like RSS, Atom, and writing your own plugins. This is thorough book that is well written and will cover everything you need to know to blog with Movable Type.

You can read the first chapter on Wiley's Web site.

Closing Movable Type Comments

I'm winning the war on comment spam on Wordzilla, my homebrew weblog software, thanks to PHP code that rejects link-heavy comments and submissions from banned IP addresses.

I'm losing on Movable Type and Manila. Both programs are being flooded with spam that has to be hand-deleted, a chore that's miserably time consuming in each. Six Apart enhanced Movable Type's comment-management features in version 3.1, but it can take up to five minutes to delete a group of spam comments on the Drudge Retort, which has 107,000 comments and 2,600 entries.

Both programs could use a configuration setting that closes weblog entries to new comments and trackback after a user-designated period, such as a week. Most comment spam that I receive comes from older entries -- I'm guessing that their webcrawling robots rely on search engines, so they're slow to find new entries.

Because Movable Type is backed by a database, you can run queries on that database to edit entries. As an experiment, on Nov. 25 I used the following MySQL query to close comments and trackback on all Drudge Retort entries older than a week:

UPDATE mt_entry SET entry_allow_comments = 2, entry_allow_pings = 0 WHERE entry_created_on < date_add(curdate(), interval -7 day)

I had to rebuild the entire site after running this command so that entry archives reflected the change.

Comment spam has all but disappeared. A propecia shill who hits the site constantly hasn't successfully posted a spam in days.

I'm working on a PHP script that makes this automatic, closing comments and trackback in Movable Type weblog's entries after one week. Manipulating the database is easy, but finding a good way to tell Movable Type to rebuild an entry from PHP has been tough.

I was hoping to execute a simple Perl script using PHP's system command, but attempts to rebuild an entry like this have failed:

/usr/bin/perl -I'/path_to_mt/lib' -I'/path_to_mt/extlib' -mMT -e 'my $mt = MT->new; $mt->rebuild_entry(BlogID => 2, Entry => 3000) or die $mt->errstr'