WikiaApp is a Helper class used by a lot of Wikia code. It is a wrapper for many common operations. Main use cases are hooks registration, getting access to global variables and registering extensions data (for example messages). After a refactoring, the functions for extension registration were deprecated so now this is mostly used for the $wg global variable helper and register hook function.
Finding WikiaApp instance
WikiaApp instance can always be gotten from WikiaSuperFactory:
$app = F::app();
The WikiaApp instance is a member variable of any Controller class:
The WikiaApp instance is a global variable of any View class (template):
Getting access to global variables
Wikia added a wrapper for global variable access for a couple of reasons. Primarily it made our testing framework easier to write, but in the event of a change in core mediawiki it makes it easier for us to transition from one global variable to another (or to keep an old one around for compatibility reasons). It also makes it more explicit that a global variable is being changed because you have to call setGlobal() in order to change a value. It works with a "chaining" style. wg() is actually a function that looks up the global variable, which allows for an intermediary (such as a unit test) to control the return value. In most cases, it just looks up the global variable and returns it.
Important note! Variable returned by WikiaApp does not behave very same as regular global variable. Changing it's value does it localy, does not change value of global variable. In order to change global variable value setGlobal method has to be used:
Best programming practices
In general using global variables is very bad programming practice. WikiaApp way of accessing global variables should be considered only as low risk, cheap refactoring method. If possible pass data as method arguments and wrap them in new class if there are many of them instead of using global variables or WikiaApp.