Apologies for the down-time over the last couple of days. This blog has been undergoing a major metamorphosis under the covers so I thought it best to hit the big red switch.

This blog now runs stock WordPress 2.0.3 instead of my previous, heavily-customised version Liberated WordPress 1.5.2. The experience of upgrading has been one less of education than simply doing what I know, properly. I now have a lovely Subversion repository containing all the changes I have made since the blog went down – a track of the entire upgrade procedure.

At the point I’m writing this (on my local, now-master copy of the blog), I still have a lot of work to do. The blog is running beautifully on the stock version new engine and I have taken the opportunity to clean up some of the content that was suffering from charset identity dysphoria*. There are missing features that I had previously hard-coded into the engine that I now have to replace or decide to do without.

Missing features

Alt-C close tag button in editing interface
Really, really handy. Make into a plugin. Sorted.
Users editing their own comments
Can do without for the time being. Re-implement as plugin with preview and tidy mechanism, like wp-validator.
wp-comments-post.php Sane redirection on comment posting
Needed because the default is annoying. Investigate. Sorted.
wp-mail.php
Can be removed. I don’t blog-by-email.
Disallow use of registered user’s name by unregistered user posting comment
Plugin.
Miscellaneous
wp-includes/comment-functions.php I’ve “improved” the retrieval of comments in moderation.
Changed the priority of the ‘balanceTags’ filter on comment content.
Shortcut substitutions for < > and <code/>.
Better, more relaxed e-mail check
Flood protection against God? 8)

As a test of image uploading, here’s a lovely picture of my garden this morning.
My Back Garden

As a test of my thumbnail directory filter, here’s a close-up of one of those beautiful poppies in my back garden. I could be out there looking at the poppies, but instead I’m indoors upgrading my blog and fixing WordPress bugs. :)
The Heart Of A Beautiful Red Poppy In My Back Garden

And finally, because I love this drawing by Emma Whyatt.
Emma's Flower Drawing (transparent)

15 Comments

  1. Libertus says:

    I’ve decided to offer plain text as a comment input format. Now I definately need a plugin!

    Not being redirected to the comment I just submitted is really annoying! Time to see if 2.0.3 offers better plugin hooking goodness than I previously enjoyed. If not, more customisations are necessary but I think I’ll feed them upstream, if they’re worthy.

  2. Libertus says:

    First Things First – Comment Redirection

    All I need to do is add a fragment identifier to the redirection that already takes place after a comment is submitted, which is done at the end of wp-comments-post.php.

    There’s not much I can plug into here. The comment ID is known but not used. I’ll need to patch the vendor code, adding the comment fragment if the redirection is to the post permalink, leaving explicit redirection alone for the time being.

    $location = ( empty( $_POST['redirect_to'] ) )
    ? get_permalink( $comment_post_ID ) . '#comment-' . $comment_id
    : $_POST['redirect_to'];

    Ah fuck it. Just do the lot. What does it matter?

    $location = ( empty( $_POST['redirect_to'] )
    ? get_permalink( $comment_post_ID )
    : $_POST['redirect_to']
    ) . '#comment-' . $comment_id;

    Now it works for editing a comment too. Phew! I was gonna go nuts there, for a while.

    Actually no, I spoke too soon, it didn’t work. There is a separate redirect for editing a comment in wp-admin/post.php action ‘edited_comment’.

    header('Location: ' . $referredby . '#comment-' . $comment_ID);

    Ahhh… nice!

  3. Libertus says:

    Verify Changes And Send Upstream

    To send a change upstream to a vendor, I need a patch and a description.

    WordPress Patch to add fragment identifier of comment to all post-comment-editing redirections

    Index: wp-comments-post.php
    ===================================================================
    --- wp-comments-post.php        (revision 17)
    +++ wp-comments-post.php        (working copy)
    @@ -57,7 +57,7 @@
            setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
     endif;
    
    -$location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'];
    +$location = ( empty( $_POST['redirect_to'] ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'] ) . '#comment-' . $comment_id;
    
     wp_redirect( $location );
    
    Index: wp-admin/post.php
    ===================================================================
    --- wp-admin/post.php   (revision 17)
    +++ wp-admin/post.php   (working copy)
    @@ -331,7 +331,7 @@
    
            $referredby = $_POST['referredby'];
            if (!empty($referredby)) {
    -               header('Location: ' . $referredby);
    +               header('Location: ' . $referredby . '#comment-' . $comment_ID);        } else {
                    header ("Location: edit.php?p=$comment_post_ID&c=1#comments");
            }
    

    Check Vendor Doesn’t Already Have The Change

    WordPress development is done in public using a source-code repository management system called Trac, which the developers host at http://trac.wordpress.org. I begin my quest for a pre-existing patch by searching on comment redirect, which yields several results. I find ticket #2590 New Filter: comment_post_redirect to which I give my support.

    A Better Patch In Light Of #2590

    Index: wp-comments-post.php
    ===================================================================
    --- wp-comments-post.php	(revision 3850)
    +++ wp-comments-post.php	(working copy)
    @@ -57,8 +57,8 @@
     	setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
     endif;
    
    -$location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'];
    -
    +$location = ( empty( $_POST['redirect_to'] ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'] ) . '#comment-' . $comment_id;
    +$location = apply_filters('comment_post_redirect', $location, $comment);
     wp_redirect( $location );
    
     ?<
    Index: wp-admin/comment.php
    ===================================================================
    --- wp-admin/comment.php	(revision 3850)
    +++ wp-admin/comment.php	(working copy)
    @@ -192,12 +192,9 @@
    
     	edit_comment();
    
    -	$referredby = $_POST['referredby'];
    -	if (!empty($referredby)) {
    -		header('Location: ' . $referredby);
    -	} else {
    -		header ("Location: edit.php?p=$comment_post_ID&c=1#comments");
    -	}
    +	$location = ( empty( $_POST['referredby'] ) ? "edit.php?p=$comment_post_ID&c=1" : $_POST['referredby'] ) . '#comment-' . $comment_ID;
    +	$location = apply_filters( 'comment_edit_redirect', $location, $comment_ID );
    +	wp_redirect( $location );
    
     	break;
     default:
    

    Whatever upstream does, I’m adopting this patch into my own codebase. Thanks for the filter, MarkJaquith!

  4. Libertus says:

    Editing Enhancements Plugin

    A plugin to make miscellaneous enhancements to the overall experience of editing content on my blog.

    Alt+z Closes Previous Open Tag

    Perhaps my favourite customisation from Liberated WordPress is now a plugin. The “Close Tags” quicktag is now on access key ‘z’ (Alt+z) and instead of closing all the tags in the file, closes the last open tag before the cursor.

    So, like, you type <q>It’s a <strong>prettyAlt+z <em>coolAlt+z featureAlt+z.

    Plain-text Comment Posting Option

    Very simple. If the XHTML checkbox isn’t checked, pre-process the comment content through htmlspecialchars().

    Fix User-profile URL Messiness

    A huge annoyance in WordPress is its refusal to accept a blank URL in both user profiles and comments, inserting http:// instead. I would prefer the URL to remain exactly as the person types it. The filter ‘pre_user_url’ serves my purpose.

  5. Libertus says:

    <h3 id=’test-comment’>A Test Comment</h3>

    You never know <what> you might <find fred="&&&amp;;;’/> in a plain text document.

  6. Libertus says:

    <h3 id=’test-comment’>A Test Comment</h3>

    So long as the <strong>markup</strong> is <em>valid</em>, express yourself with <is:product cite="W3C Style CSS">style</is:product>.

  7. Libertus says:

    A Test Comment

    So long as the markup is valid, express yourself with style.

  8. Libertus says:

    Image Management

    Time to deal with The Image Problem, if I have one.

    A useful feature I gain with the WordPress 2.0.3 upgrade is inline image uploading, a way to put pics on the blog server along with the post I am writing about them.

    I want all my images to be uploaded to /libertus/images and all thumbnails placed in /libertus/images/.thumbs/. I shall manually control the permissions on these directories during uploads or, better still, have special scripts which can do it for me safely. The images directory will, eventually, be managed by a single script that responds to all requests. I’m particularly concerned about maintaining stable URLs while I move images around. I like the idea of each image being identifiable by its md5 hash as well as its filename. Pity md5s look like crap, so maybe I’ll map to capital letters and numbers.

    Step 1. Upload An Image For This Post

    I have a lovely picture of the sunny, flowery back garden I could be enjoying instead of doing this! That’ll do. It’s a 640×480 50% JPEG that I prepared for a friend this morning, taken on my trusty, crusty Canon Powershot S1 IS.

    Hmm… the uploaded file could not be moved to .. The file may have uploaded by couldn’t go into the images directory. I must have my option set wrong. No, I just needed to make my images directory writable. There’s the garden! Link to page, send to editor.

    Oops! The hrefs aren’t written correctly when the image links are sent to the editor. I’m getting href=”libertus/images…” which will drive the browser insane and give 404s. I’ll have to seek an automatic fix because that could get nasty. Turns out to be a bug in wp-includes/template_functions_links.php:get_attachment_link(). See WordPress Trac ticket 2801.

    Step 2. How Did My Garden Grow?

    I have uploaded and published the image. I assume it is now in /ibertus/images and has a thumbnail file. How did my garden grow?

    paul@kubuntu ~/s/t/b/w/www> ls -l images/back*

    -rw-r–rw- 1 www-data www-data 58630 2006-06-08 10:09 images/back-garden.jpeg
    -rw-r–r– 1 www-data www-data 4461 2006-06-08 10:09 images/back-garden.thumbnail.jpeg

    Not good. Not good at all. I don’t mind the new files being owned by the web server user, that’s OK and I can change that if I want to using the sticky bit. What I mind the the image file being left world-writable. That has to be a bug.

    Step 3. Correct WordPress Uploaded Image Permissions

    Found it! And with one of those wonderfully enigmatic and ironic comments, emphasis mine. From wp-admin/admin-functions.php function wp_handle_upload() lines 1778-1781.

    	// Set correct file permissions
    $stat = stat(dirname($new_file));
    $perms = $stat['mode'] & 0000666; ← should be 0664
    @ chmod($new_file, $perms);

    The read/write permissions of the parent directory are not the correct file permissions for any new file. The correct permissions for new files are 0644, rw-r?-r–, owner read/write, group read/maybe write, world read. My images directory has to be set world-writable for the duration of an upload. That does not mean I want my image files to be world-writable!

    I test my change by re-uploading my back garden image, then submit to trac. See WordPress Trac ticket 2802.

    Step 4. Poppycock! Getting Thumbnails In The Right Place

    I like /libertus/images/.thumbs, which isn’t the default, so I need to use filter ‘thumbnail_filename’. My first attempt just appends ‘.thumbs/thumb-’ to the supplied filename.

    Which didn’t work. After inline uploading, the image appears but the options menu has No Thumbnail. The thumbnail file is in exactly the right place and named accordingly. What’s going on? See WordPress Trac ticket 2682.

    I’ve got it working with minimal patching. Sweet. One final test. Someone, somewhere, said something about being able to drag-and-drop images.

    Step 5. Preserve Transparency In Thumbnails

    It’s only polite. The main image retains the transparency I spent a lot of time adding in, so why should my thumbnail have a black background? I suspect it’s another bug, probably related to a missing call to the image processing library. Back to wp_create_thumbnail().

    Hmm… no combination of calls to imagealphablending and imagesavealpha seem to have any effect. The background is black. I’d better check to see if this is a known bug. The user-notes to the PHP manual entry on function imagecopyresampled contain the solution. I add that code to my local version, test successfully and submit WordPress Trac ticket 2805.

  9. Libertus says:

    Style Matters

    The last major item before switching back on is to adjust the stylesheet. I removed a font-scaling rule from the default and so all the text is massive, which I like. What I don’t like is that the rest of the page doesn’t scale with the chosen text size, which it should, to a certain extent.

    Font Scaling Sucks!

    Don’t do it! Don’t change the font size selected by the reader, if at all avoidable.

    The reason all my text is massive is because the default WordPress theme scales down from the default and then up to it’s preferred sizes. I’m going to start by removing all font sizes that scale up.

    Font Scaling Rocks!

    With all the font-scaling nastiness removed from the stylesheet, the blog looks sane with my default font size. Now for the neat trick, to make the width of the page scale, within reason, along with the font-size selected by the reader. When I press Ctrl+Plus everything should get bigger, and vice versa for Ctrl+Minus.

    To do that, the page itself must be sized relative to the default font. It is currently fixed at 760 pixels and I need to use ems. How wide should it be? How many characters across is readable? 40 ems translates, roughly, to 80 normal letters, so I’ll start with that.

    Umm… a bit slim, and an obvious problem arises. The header and footer images really depend on that 760 pixel width. Next step is to set the width to 60ems and the min-width, grudgingly, to 760 pixels for now.

    Decent Style Takes Ages

    A few hours working on website style makes me appreciate why women take so long to get ready to go out. After a lot of work, I have a basic style with which I’m satisfied. It doesn’t select any fonts or enforce much in the way of font sizing. There are no images. The page scales with whatever font size you choose. And it still has rounded corners, thanks to Stu Nicholls at http://cssplay.co.uk.

    Cleaning Up and Checking In

    I could go on all night but I have to go back on-line too!

  10. Libertus says:

    It Lives!

    WordPress 1.5.2 to WordPress 2.0.3 in 40 easy steps! What a buzz.

    I hope you all enjoy. Feel free to tell me what you think below. 8)

  11. Libertus says:

    An Image Problem

    Something always breaks. :D

    For some reason, the image attachments to this post don’t work so all you get is a blank page. When I’m editing, the inline gallery shows No Thumbnail again. Sheesh. Could be a PHP difference, I suppose.

    Images Need Absolute Pathnames

    Switching servers caused the problem. I had “uploaded” the images locally so WordPress recorded the absolute path of the images locally, which is not right for the public server. I wrote a quick plug-in page to correct any image attachments that had incorrect pathnames.

  12. Libertus says:

    Done

    Phew. That was a long day. Time for a beer!

  13. Nobby says:

    Whadya mean ‘avoid’ you big hairy sheep abusing sassanack.

  14. Libertus says:

    OK! OK! I’ll change it to “abuse”.

  15. Libertus says:

    Finishing Touches

    Re-instate the feature that protected registered users from impersonation.
    Disable the nofollow filter.

Leave a Reply

You must be logged in to post a comment.