Archive for July, 2005

Making monthly archive dropdown lists in WordPress

Saturday, July 30th, 2005

I was asked by Armand how to do the month-by-month blog archive drop-down in the right hand column of the blog, which, if you have archives going back some time, saves having an enormous list of months (which, IMHO, looks ugly). WordPress’s get_archives() function does provide drop-down capability, but only by using JavaScript to handle the form submission, which is just dumb, and breaks badly if you don’t have JavaScript enabled.

So, I wrote a hack that does the drop-down, but handles it using standard HTTP form submission (which is nice). There is a bit of JavaScript, an event handler to submit the form straight away when a selection is made, but this is a convenience thing, and it still works the old-fashioned way if you have JavaScript disabled.

Here goes… first of all it’s just a hack, not a plugin, so you’ll need to have a my-hacks.php file set up and running - see here for more details.

Once you have my-hacks.php open, add the following inside the PHP code:

function make_month_dropdown() {
	global $wpdb, $tableposts, $month;
	$now = current_time('mysql');
	// Get the entries grouped by month and year
	$archiveEntries =
		$wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`,
		MONTH(post_date) AS `month`
		FROM $tableposts WHERE post_date < '$now' AND post_status = 'publish'
		GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC");
	// Start form
	echo '<form action="'.get_settings('home').'/" method="get">';
	echo '<div><select name="m" class="small" onchange="this.form.submit();">';
	// Produce each line of the dropdown
	foreach($archiveEntries as $archiveEntry) {
		// Add leading zero
		$thisMonth = zeroise($archiveEntry->month,2);
		// value to be passed into query string
		$thisM = $archiveEntry->year.$thisMonth;
		echo "<option value=\"$thisM\"";
		// Preselect currently-viewed month
		if ($thisM == $_GET['m']) echo ' selected="selected" ';
		echo '>';
		echo $month[$thisMonth].' '.$archiveEntry->year;
		echo '</option>';
	}
	echo '</select>&nbsp;';
	echo '<input type="submit" value="&raquo;" />';
	echo '</div></form>';
}

Save that (and upload). Then in your template file (sidebar.php), replace the line beneath the archive header, that says <?php get_archives(); ?> (or something similar) with:

<?php make_month_dropdown(); ?>

And you should be done. Hopefully. Feedback in the comments below.

Serious but not organised

Friday, July 29th, 2005

A few weeks ago Mayor of London blog spotted a loophole in the 2005 Serious Organised Crime and Police Act that, although it created a big chunk in Westminster which made it illegal to commence protests without permission, Brian Haw’s ongoing protest was exempt.

At the time I thought it was an amusing story which I would relate down the pub and then promptly forget (which I did), and that it had no chance as a successful legal defence. Until today that is, it turns out Brian Haw has succeded in getting exempted for that very reason. Which is a good thing. But only a very small good thing. The legality of the Act is not in question, so the rest of us can’t join in, and Parliament could happily amend the Act to cover past protests if it wanted to, so there’s no guarantee that Mr Haw will be safe forever.

More scarily, though this error works out in the favour of those of us who cherish democracy, we must remember that it slipped through in the rush to get the Bill passed before the election, which meant it didn’t come under the scrutiny it might otherwise have had. Which leads to the question - what about all the other parts of the bill? Did the muppet who drafted the clauses about the protest part get his hands on the rest of it, the bits that actually had to do with serious organised crime? And what about all the other bills passed at the same time? I shudder to think…

Free as in beer, not as in software

Thursday, July 28th, 2005

Must be a slow news day or something - the story about Open Source beer banging around various weblogs and linklogs I read. Okay, so the idea is great, make a beer recipe with a Creative Commons share-alike licence which people can download, use for free, make derivative works, etc.

But, it’s nothing more than a crappy gimmick. For starters, the recipe they have isn’t that much more informative about making beer than what’s currently available in the public domain, or on other websites (this brewing site, which I found while Googling, looks quite interesting, and is far more informative). More importantly, the knowledge required to brew beer successfully is not the kind that benefits from an open-content licence; it’s highly complex and often quite tacit - what the different strains of yeasts, varieties of grain and their carbohydrate content, the time of year and ambient temperature, the complicated business of sterilising containets - all these factors are quite hard to get a handle on and to make things worse, the complexity increases once you start combining them.*

These things are hard to spell out exactly. To publish a beer recipe is an amusing diversion, but on its own, it’s about as informative as posting source code without comments, if not worse - all the information of any use is outside the grasp of the written word.

* I am not a brewing expert; however my father used to be quite into making wine, sherry and later on, mead, and I suspect many of the problems he encountered similarly apply to the beer industry.

Greasepostmonkeycoding

Wednesday, July 27th, 2005

Oh no, I broke the golden rule and started mucking around with Greasemonkey, which was a mistake, as I have now wasted this entire evening. Anyway, it is fun to play with custom code in webpages, and after basically looking at other people’s code I’ve come up with a simple little widget - it turns any UK postcode in a page (which is not already inside a hyperlink) into a hyperlink to the relevant Google Maps map for the area - e.g. SW1A 2AA becomes SW1A 2AA. Want to try? Install it from here (you must have Greasemonkey installed first, obviously - download it here). Enjoy. Lots of it is derived from others’ work - credits are in the source code. Any bugs, report in the comments below.

Fair use of ripped CDs, and charity shops

Wednesday, July 27th, 2005

While dropping by my local Oxfam bookshop today, I noticed a wee notice in the door that said along the lines of: “Upgraded to an MP3 player? Then why not donate your old unwanted CDs to us?” While this is perhaps an eminently nice sentiment and innocuous to boot, to me this looks like it might break copyright law. For while ripping personal copies of your own CDs onto MP3 for use on the move or as backup falls under “fair use“, if the original then moves into someone else’s hands, as the MP3 is no longer a duplicate of something you own, it’s no longer fair use and so your copy is illegal. I think. (I am not a lawyer, after all) Of course, while selling on the old CD is probably a definite no-no, I don’t know whether donating it to charity is the same, but I think it might be - and you know how horrible intellectual property lawyers can get. Anyone care to advise?

We Are Afraid!

Wednesday, July 27th, 2005

While We’re Not Afraid! was a bit, in my opinion, tacky, and bordering on a sort of online equivalent of grief tourism, at least the sentiment was eminently agreeable; we should not be afraid of stepping out in public, nor should we suspect anyone whose skin isn’t white of being about to kill us.

Bolstered by this, I thought that the people of London would be broadly in agreement. But then I read this BBC article on how non-white Londoners are getting funny looks, or even outright hostility, when they travel now; the fact that they now feel compelled to ‘blend in’ to a city that is characterised by its diversity is quite perverse (although the guy who now wears a white wristband and carries a copy of the Economist brought a smile to my face - he’s savvy enough to be covering all bases, at least).

I didn’t see many travellers actually treating others with outright suspicion whilst bounding round on the tube and buses this weekend, which might mean this all may be a figment of the receiving party’s imagination; they could be worried enough that they’re actively looking for hostility from fellow travellers and are merely projecting fear onto others, but if anything this is worse. Either way, it means that a significant number of people are now getting properly fucking scared of one thing or another, which means that the terrorists are winning - sorry, I hate that phrase, I’ll go again - which is a horrible state of affairs that becomes very hard to remedy. What can we do about it?

Update: Whatever we do about it, it won’t be thanks to any ideas from the letters page of Metro (which makes the BBC’s “Have Your Say” look like The Moral Maze). Going Underground carries a selection for today, including one person who suggests fostering community spirit by having luminously-jacketed volunteers who would demand to inspect the contents other passengers’ bags. Nurse!

(Further) OpenTech thoughts

Monday, July 25th, 2005

There was an O’Reilly stand (well, table) at OpenTech, which had a dazzling array of O’Reilly books. O’Reilly books nearly all have a distinctive, but as of yet has not become boring, style of animal engravings on the front (sometimes with puns - Python books have pythons, shell scripting books have tortoises, etc.). Which got me thinking… what if O’Reilly runs out of animals? Alright, there are a lot of species out there, but there’s also a lot of O’Reilly books. I envisaged a nightmarish future where O’Reilly goes evil, enters the genetic engineering industry and starts churning out transgenic species - half-dolphin, half-cougar, something like that, just for the purposes of making new cover art. Anyway, I took advantage of the local discount and bought Mind Hacks - the title is a slight misnomer IMHO but it’s still a really interesting book.

Alright, some seriousness. In the midst of my last post I omitted some other interesting people; Rufus Pollock and Tom Chance of Free Culture UK and Remix Reading, both of whom talked of the importance of grassroots open culture, getting actual artists and creatives to jump in and start producing and using CC-licensed stuff (which is good, and a damn sight better than last year’s music remix speakers, who didn’t really care for Creative Commons). I agree with them, and think very much the “get people to take part first, and then introduce all the intricacies, legal issues and differences between users as part of the practical learning curve” approach advocated works best - getting people working with them hands-on is the way forward.

I also missed out some stuff we saw from the Backstage BBC developers - social tagging of BBC News stories is just the beginning in this area, I think. There was also Social Documents, a collaborative text-annotation project which could be really cool for schools and universities to work on

Some good blog posts on the day’s events: Ewan Spence, the guy behind the iPod shuffle shuffle tells all, Vagueware provides a good summary of the day’s events too, as does Chris Green and Neil Turner. Tom Reynolds recounts his moment on stage, while there is the odd dissenting voice about the whole thing.

Davblog also talks about it, before entertaining the scary notion of a Greasemonkey arms race did slightly worry me - although the author corrects himself slightly in saying pages won’t be entirely unreadable if websites obfuscate their code, Greasemonkey’s job of parsing the tree is certainly easier in well-marked up HTML (e.g. using <h2> rather than <b><font size=”+2″>), and although it won’t stop scripts being made, it might set back the semantic web cause somewhat. But the entire point is that this kind of thing should be embraced by the mainstream, and so we should attempt to co-opt the content producers and start telling them that this is a good thing (the customer is always right, right?) until (eventually) they start to listen (hopefully).

One talk I missed - promise.tv looks really exciting, and I wish I’d gone to the talk about it - more info about in on BoingBoing (Max and Armand, you’ll probably both be interested in this).

Big thing I really missed, as I didn’t attend the relevant seminar, was Danny O’Brien’s discussion of whether we need a British version of the EFF. And the result? A nice shiny pledge to donate £5 a month to a British EFF. Go on, sign it. Danny talks more about it in detail here.

And finally - Technorati’s list of posts about Opentech and an enormous set of Flickr photos tagged accordingly. And most fun of all, the audio streams of the day are also up, so if you couldn’t make it all, or regret missing some bits (like I did), you can catch up.

Bombs don’t kill people, coppers do

Sunday, July 24th, 2005

What to make of the tragic death of an innocent man? Should we now treat the Metropolitan Police, who stand out with their funny dress, different customs and method of speech, with suspicion every time we see one out on the street, or in a train station? Should we suspect all white young men of being potential killers with guns under their jackets, the mysterious “plain clothes officers” who have gone incognito, the better to blend amongst us?

Of course not. Not just because unwarranted suspicion and fear of our police is highly demoralising and counter-productive, but because it is ridiculous. It’s ridiculous not just because it’s obvious that only a minority of policemen wield hidden arms and there only stands a tiny chance that it is you they are going to shoot, if anyone; it’s ridiculous by sheer social convention. We all know the average copper is not going to kill you (even after the cases of Harry Stanley and James Ashley).

The same social convention does not, however, apply if you look or act even remotely like a terrorist. The BBC’s Have Your Say has a telling selection of comments, with many people rationalising that a mere possibility (not high or near-certain probability, just a possibility) of innocent people being blown up is just cause for an innocent person to be shot in the head five times. There’s not even much hand-wringing over the difficulty of it all - it’s straight-off “sod it, shoot them”:

“There should be no witch hunt or scapegoating of the police. I hope they will robustly defend their actions and not be demoralised.”

“As unfortunate as this man’s death has been, I fully believe the police were only acting in the best interests of the public.”

“If anyone carrying a bag on the Tube is running from the police and ignores their orders to stop then they ought to be shot. The lives of hundreds of innocent civilians must be paramount.”

“It is a war we’re fighting and the enemy is not playing by any rules of engagement. Support your police, they are doing it for you.”

Maybe they held these opinions before July 7, maybe they have developed them as a reaction since; either way, the fact that being in possession of a non-white skin and running when men in plain clothes chase after you with guns is now seen by many as just cause to end your life. Of course, it would be interesting to see if the same people would support themselves, or a relative, being sacrificed on this dubious altar of “maybe”.

Scary as this mentality is, it has no bearing on the facts of the case. Was this a cold blooded murder or an honest mistake with fatal consquences? I don’t know, and I am not trying to pronounce guilt upon the man who shot Mr de Menezes - there may well have been sufficient misleading but compelling signs to draw a near-certain conclusion that he was a terrorist about to blow up a train. It’s not up to me to decide. It’s up to the criminal justice system to decide. Jean Charles de Menezes deserves justice every bit as much as the 52 people who were murdered on July 7th, and that means removing the false and dangerous idea that just because a decision is difficult, one should be absolved of responsibility for its outcome.