Libertus Upgrades libertus To WordPress 2.0.3
Posted on Wed, 7th June 2006 at 14:30 under General, WordPressApologies 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.phpSane 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.phpI’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?
As a test of image uploading, here’s a lovely picture of my garden this morning.
![]()
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. ![]()
![]()
Libertus said: June 7th, 2006 at 15:31
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.
ReplyLibertus said: June 7th, 2006 at 15:44
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.
Ah fuck it. Just do the lot. What does it matter?
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.phpaction ‘edited_comment’.Ahhh… nice!
ReplyLibertus said: June 7th, 2006 at 16:04
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 , which yields several results. I find ticket #2590 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!
ReplyLibertus said: June 7th, 2006 at 18:23
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 .
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 instead. I would prefer the URL to remain exactly as the person types it. The filter ‘pre_user_url’ serves my purpose.
ReplyLibertus said: June 7th, 2006 at 18:43
<h3 id=’test-comment’>A Test Comment</h3>
You never know <what> you might <find fred="&&&;;’/> in a plain text document.
ReplyLibertus said: June 7th, 2006 at 18:46
<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>.
ReplyLibertus said: June 7th, 2006 at 18:48
A Test Comment
So long as the markup is valid, express yourself withstyle .
ReplyLibertus said: June 8th, 2006 at 10:02
Image Management
Time to deal with , 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 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 inWordPress Trac ticket 2801 .
wp-includes/template_functions_links.php:get_attachment_link(). SeeStep 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?
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 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.phpfunctionwp_handle_upload()lines 1778-1781.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. SeeWordPress 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 hasWordPress Trac ticket 2682 .
No Thumbnail. The thumbnail file is in exactly the right place and named accordingly. What’s going on? SeeI’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 toimagecopyresampled contain the solution. I add that code to my local version, test successfully and submit WordPress Trac ticket 2805 .
Replyimagealphablendingandimagesavealphaseem 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 functionLibertus said: June 8th, 2006 at 15:22
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!
ReplyLibertus said: June 8th, 2006 at 19:36
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.
ReplyLibertus said: June 8th, 2006 at 19:51
An Image Problem
Something always breaks.
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 Thumbnailagain. 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.
ReplyLibertus said: June 8th, 2006 at 21:26
Done
Phew. That was a long day. Time for a beer!
ReplyNobby said: June 16th, 2006 at 12:06
Whadya mean ‘avoid’ you big hairy sheep abusing sassanack.
ReplyLibertus said: June 16th, 2006 at 15:42
OK! OK! I’ll change it to “abuse”.
ReplyLibertus said: July 8th, 2006 at 12:57
Finishing Touches
Re-instate the feature that protected registered users from impersonation.
ReplyDisable the nofollow filter.