VE-1497: Created MediaWiki API method that delivers list of templates based on passed query

This method is meant to be used within newly developed template tool in VisualEditor.
Its behavior is specifically described in JIRA ticket.

https://wikia-inc.atlassian.net/browse/VE-1433
https://wikia-inc.atlassian.net/browse/VE-1497
I think it's bad practice to have the count() inside the loop instead of set to a variable before the loop. However, in this particular case, the array is so small that the cost is probably close to nothing.