Fandom

Wikia Developers Wiki

Nirvana/WikiaApp

< Nirvana

859pages on
this wiki
Add New Page
Talk0 Share

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:

 $this->app->isController($this);

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.

$app->wg->WikiId;
$app->wg->Title->isSpecial("SomeSpecialPage");

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:

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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.