Limit template expansion depth similar to the PHP parser

The PHP parser limits the nesting depth of templated template parameters with

 $wgMaxTemplateDepth = 40;

This patch tries to emulate that behavior in Parsoid.

Co-authored-by: Gabriel Wicke <gwicke@wikimedia.org>
Co-authored-by: Arlo Breault <abreault@wikimedia.org>

Bug: 57670
Change-Id: I628f9074366f0fb33437924821444512b245aa21