Treat phonos parser function as expensive

If the limit is exceeded, we show nothing and the page is automatically
put in a tracking category for editorial review.

The 'expensive parser function' count is only incremented if the file=
parameter isn't given, which doesn't do anything expensive.
Unfortunately we can't determine if the file is cached without making an
otherwise unnecessary trip to Shellbox, but this will change once we
start calling the Engine from the parser hook (T315481).

Bug: T315483
Change-Id: Ib227c580ccd81c8d2b6266c72df993f9cb652e6e
diff --git a/includes/Phonos.php b/includes/Phonos.php
index 782abd5..7188ff0 100644
--- a/includes/Phonos.php
+++ b/includes/Phonos.php
@@ -62,6 +62,8 @@
 			return '';
 		}
 
+		$parser->addTrackingCategory( 'phonos-tracking-category' );
+
 		$spanAttrs = [
 			'class' => 'ext-phonos',
 			'data-phonos-ipa' => $options['ipa'],
@@ -79,10 +81,12 @@
 				$spanAttrs['data-phonos-file'] = $options['file'];
 				$spanAttrs['data-phonos-error'] = 'phonos-file-not-found';
 			}
+		} elseif ( !$parser->incrementExpensiveFunctionCount() ) {
+			// Return nothing. See T315483
+			// TODO: Once T315481 is resolved, check to see if there is a cached file.
+			return '';
 		}
 
-		$parser->addTrackingCategory( 'phonos-tracking-category' );
-
 		return Html::element( 'span', $spanAttrs, $options['ipa'] );
 	}