Background
To guard against too many API requests to Google, and to prevent colossal misuse of Phonos in general, it can be registered as an expensive parser function. What this does is prevent too many uses on a single page, as specified by $wgExpensiveParserFunctionLimit. When this is exceeded, we're supposed to skip over whatever is the "expensive" part, in our case doing any sort of API call. Pages that have too many expensive parser function calls are categorized into Category:Pages with too many expensive parser function calls. The "expensive parser function count" may also be influenced by other functions, such as {{#ifexist:}}, related to Phonos. Regardless, this doesn't happen too often in the wild and when it does communities generally know how to debug and handle it.
Note that this doesn't matter very much at the time of writing since the Google API call only happens on-click, but we're slated to make all the calls to the engine from the parser hook (T315481).
Acceptance criteria
- If the limit is exceeded after we increment the count, Phonos shouldn't render the Phonos button, unless the file already exists.
Other notes
- Unfortunately we can't determine if there's a cache hit without making a trip to Shellbox, so we may have to increment the counter even if we aren't actually making external API calls. However at least if the file= parameter is set, we should bypass calling Parser::incrementExpensiveFunctionCount() since we know that's cheap.
- A better design would probably be to show an informative error. This could be shown instead of the play button.