Allowing git:// urls in the Drupal Link module

Updated: Sun, Jul 27, 2008 - 6:33pm
Type
Status

I wanted to give you all anonymous access to my public git repositories, and I wanted to add a special field in my Drupal "Blog Post" content type to allow it.  (Results can be seen in my post about dbgp).  It was all pretty standard.  I added a field to my content type.  The field was of type "Link", as provided by the Drupal Link module.

I ran into a small stumbling block, however:  When I attempted to post my git:// url, the Link module told me that it was an "invalid url".  It's not.  It just has an unusual protocol name.

It turns out that the Link module  checks a variable called "filter_allowed_protocols", which was defined by the core "Filter" module.  Apparently, nobody provides a UI to edit this variable.  So I had to insert it into the database by hand.

First, I selected for that variable:

  1. SELECT * FROM variable WHERE name='filter_allowed_protocols';

As it happened, my results were blank -- it was using the defaults. So I pulled the defaults out of the source code, and I wrote a little php, added 'git' as one of the allowed protocols, and then wrote a php script to print out the serialized version of this array.  (The reason for this step is that the 'values' in the Drupal variable table are supposed to be stored as serialized php variables).

My script looked a lot like this:

  1. echo mysql_escape_string(serialize(array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal', 'git')))."\n";

Finally, I stuck the results of that back in the database:

  1. UPDATE variable SET value='a:12:{i:0;s:4:\"http\";i:1;s:5:\"https\";i:2;s:3:\"ftp\";i:3;s:4:\"news\";i:4;s:4:\"nntp\";i:5;s:6:\"telnet\";i:6;s:6:\"mailto\";i:7;s:3:\"irc\";i:8;s:3:\"ssh\";i:9;s:4:\"sftp\";i:10;s:6:\"webcal\";i:11;s:3:\"git\";}'
  2. WHERE name='filter_allowed_protocols';

And now, I can post my git repositories and you can clone them.  Horray!

Your rating: None Average: 4.5 (2 votes)