The Doctor becomes sheriff in a Western town being attacked by a cyborg on Doctor Who. "A Town Called Mercy" is the third episode of the show's seventh season.
Added:

Doctor Who Season 7 Episode 3 Quotes

Yes, I wear a Stetson now.

The Doctor

Tea, but the strong stuff. Leave the bag in.

The Doctor