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):

 $app->sendRequest("FooController", "BarMethod");

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! A variable returned by WikiaApp does not have very similar behaviour to a regular global variable. Changing its value does it locally, but does not change the value of global variable. In order to change global variable value, the setGlobal method has to be used:

 $app->setGlobal('wgTitle', $wgTitle);

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. If there are many global variables, wrap them in a new class instead of using global variables or WikiaApp.