Here's a first cut at this. It includes the changes from your standby_wal_archiving_v1.patch, so you get that behaviour if you set archive_mode='always', and the new behaviour I wanted with archive_mode='shared'. I wrote it on top of the other patch I posted recently to not archive bogus recycled WAL segments after promotion (http://www.postgresql.org/message-id/549489FA.4010304@vmware.com), but it seems to apply without it too.
I suggest reading the documentation changes first, it hopefully explains pretty well how to use this. The code should work too, and comments on that are welcome too, but I haven't tested it much. I'll do more testing next week.
Patch did get applied successfully to the latest master. Can you please rebase.