Sunday 28 December 2008

Perl Hacking

In my spare time today, I decided to conclusively get to the bottom of why the Blog Cloner plugin, that comes with Movable Type, always fails to load and fills my activity log with hundreds of errors. I never just sat down and tried to figure it out from scratch so I’d just disable or delete it, and clean out the errors from the log. I needed to think about it logically, and this is what I did.

I noticed that it didn’t happen if I had a clean install of MT, so I figured that it must be one of the extra plugins that I use.

So I started adding them one by one to a clean install.

It didn’t take long for the error to appear… and it was caused by AdminLinks.pl. This is a really old plugin I’ve used since 2004 to add links to my entries that point directly to the edit entry page in the admin interface.

Now I’m not a programmer, I just know bits and pieces of a few languages, the absolute basics. So to work out exactly what the heck this plugin was doing took me a while!

The original usage would be something like this:

<MTAdminOnly>
<a href="<$MTAdminLink type="editentry"$>">Edit Entry</a>
</MTAdminOnly>

I noticed in my testing that for some reason it wasn’t even working correctly any more. Instead of putting the AdminEdit tag inside the AdminOnly, it was closing AdminOnly and then putting the edit link. Not particularly helpful!

I only ever used it to add Edit Entry links, so I decided I’d strip out all the additional options, and reduce it to just one tag which I called <$mt:AdminEditEntry$>

After a few hours trying to follow through the existing code, update some of it to the new MT4 techniques and fix what was broken, I managed to get it working!

I also decided to make the plugin use the existing Movable Type admin cookie, instead of having to keep setting an additional one just for this purpose. To do this, I had to add CookiePath / to my mt-config.cgi, as suggested by Jay Allen in 2006.

quack - © 2002-2018