Fix the "addHeader($tag, $attributes, $text)" methods to not ignore the $text parameter

Rebased version of https://github.com/owncloud/core/pull/7316 - I also deduplicated the logic into template.php

Fixes https://github.com/owncloud/core/issues/11046

@PVince81 @KenBW2 @icewind1991  Please review - thanks.
Put that in the param description of $text?