Another template speedup: make one less pass through the whole output

this combines the two up to two passes that add hidden fields to HTML
forms into a single one. At the same time it uses a more efficient regex
that never backtracks, and restores the check to only do that for
forms with internals (relative) URLs.