Add an "Edit" Tab to Every Block

This snippet builds on another snippet about "Add an Edit this Block link". Instead of a link this goes further to have the edit link look like the tabs for View, Edit, etc. Here is the code to include in your theme's block.tpl.php file:

I suggest some changes so that this validates when more than one block is shown on a page and also an addition to bring the user back to the originating page after editing the block. This is based on the block.tpl.php for the Garland theme: