Use hooks instead of $wgOut when $wgCategoryTreeForceHeaders is set

Previously, $wgOut was used when $wgCategoryTreeForceHeaders was set and
a hook was used when it was not.
This change makes sure there is always a hook used with an OutputPage
instance. It fixes bug 57651.

Using $wgOut the rebuildFileCache.php maintenance script would generate
pages without JavaScript and CSS for CategoryTree when
$wgCategoryTreeForceHeaders was set (for example, when the sidebar was
in use).

Other uses of $wgOut in the CategoryTree extension seem to be less of an
issue because when there is a CategoryTree on a page, those pages seem
to be excluded from caching. (But fixing those would be nice
nonetheless: it may prevent other bugs in the future).

Bug: 57651
Change-Id: I0ee66d38755e255c5597db7a237a176039025fae
Merge "Use hooks instead of $wgOut when $wgCategoryTreeForceHeaders is set"