Manual:$wgMaxPPNodeCount

Details
A complexity limit on template expansion: the maximum number of nodes visited by  