I might have to explain this one

Posted by David on Jun 15th, 2006

One of the issues I’ve run into with writing Firefox extensions is that now, since I hold the keys to their arcana, I want to fix the problems in other people’s extensions. Adblock leaks memory and sullies my javascript console with its strange warnings and errors, and I doubt that the guy who writes Toolbar Enhancements is ever going to make a new release for new firefoxes. I can create my forked version of extensions easily enough, but what do I do about the updateURL?

Firefox extensions contain a link to a source of update information. Extensions can be upgraded automatically, but even if automatic upgrades are turned off, the information associated with an extension concerning what versions of Firefox it supports create another reason to check the update information: the compatibility upgrade. Your profile and installed extensions outlive any particular installation of Firefox, so when you upgrade the browser, manually or automatically, it can create a version incompatibility. Since developers aren’t expected to know the future, it’s possible to change the minVersion and maxVersion properties in the update source without making a new release, so any users looking for a compatibility upgrade may learn that their copy already works and they can continue to happily plug along.

The problem this creates for me is whether to provide information only on my forked versions or whether to also inform upgrade-seekers about new upstream releases. Though there might be times when I don’t want my changes undone by a careless upgrade, it seems easier for me to just leave everything in the hands of the user, and for other cases, such as simple compatibility changes, I would want any newer upstream release to supersede my changes. That leaves me to try to figure out how to make two sources of information into one.

Like many lazy people out there, when faced with a task needing dynamic content on the Web, I turn to PHP. It’s a terrible language, but it’s easy to use and does ok at Web things, so half-assed is good enough. Firefox update sources are in RDF, a data-description model that’s been around since, I think, Netscape 4. RSS was born of attempts to summarize a site’s content in terms of RDF, and RDF had another brief surge of interest with Tim Berners-Lee’s Semantic Web idea before people figured out that Web 2.0 was a better name to use to trick investors, but none of that really matters. What’s important to me and my stupid problems is that the XML syntax for RDF allows too many ways to say the same thing for me to just drop in my augmentations to an update file through string processing or even an XML parser, so I’m going to need to actually parse the RDF.

RDF is one of those standards that’s really simple at its base—describe data using a set of triples: subject, predicate and object—but still manages to fill 227 pages of W3C recommendation and countless related drafts and member submissions. After briefly flirting with the idea of reinventing the wheel, I decided that this would be really dumb and started to look for other people’s code to misappropriate. rdfapi is the first google hit for “rdf php,” but it blows. I neither want to try to fix its code nor to fill up my hard drive with its logged warnings and errors. The first hit for “rdf library” is the Redland suite, a much more mature library written by a guy who works at Yahoo! and also happens to be the editor for the RDF/XML syntax recommendation. Redland seems like a better idea, and it comes with PHP bindings.

As I’ve mentioned before, PHP is a crappy language. I do not blame Mr. Beckett one bit for not wanting to code any PHP, instead taking the route of the rest of the PHP library by providing direct bindings to the C functions, but, since Redland has a pretty nice API to begin with, written in that bizarre style of halway object-oriented programming that only C can pull off, it becomes rather obvious on the PHP side that I’m using bindings into a language that expects me to manage my own memory. To alleviate this, I created a PEAR package (are they called packages? modules? extensions?) to provide things like garbage collection, exceptions and all that fancy stuff. As long as you have both the Redland PHP bindings and SPL (comes with PHP), you can use pear install http://gophernet.org/projects/librdf-php/LibRDF-1.0.0.tgz and it’ll dump it wherever PHP extmodackages are stored. On this journey through the fancier aspects of a bad language, I found an attempt to do what javadoc does, so I wrote big, redundant comments for everything and created some files. I also have a demonstration (source) of adding a fictional new version, 1.1.1.0ds1, of rmannoy to the existing update.rdf. You may notice that I replaced all of the list items in the main sequence with “li” predicates; librdf serializes sequences back out using the actual value of the predicate, _1, _2 and so forth, and the firefox RDF parser doesn’t dig this. The Netscape RDF parser has been around longer than the standard, so I don’t care enough to try to point fingers and find out who’s more right. Anyhow, if you ever need to manipulate RDF in PHP, I hope this helps.

One Response

  1. Dead Simple RDF and SPARQL using PHP : literarymachine blog Says:

    [...] be plain awesome. I started writing a simple object oriented wrapper but eventually stumbled across this, so I didn’t even have to do that. I have contacted the author, he hasn’t been working [...]

Leave a Comment




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>