A friend of mine used to search (and share!) some really strange things on Wikipedia like stuff about Rome and Julius Caesar in middle of programming session. I think it just a way to avoid boredom when you've been doing something for some time.
As for the cure I think there is nothing wrong with small breaks. It's the big distractions which cause problems. For that a lot of things can help you keep track like an accountability partner, list of tasks broken down into small tasks, a simple spreadsheet where you mark your work times and break times, etc.