FANDOM


Recommended coding standards

WikiaSuperFactory (F::) and WikiaApp ($app) map MediaWiki coding practices to a set of helper objects and variables. The original intent was to make our code more unit testable by going through a layer of indirection before accessing any mediawiki global variable or function. Additionally, the unit test framework we were using did not allow us to mock classes that were constructed inside of a method instead of being passed in. After additional work, we switched to using the PHP extension runkit, which is a bit of a hack but allows us to test all the legacy code we have. After that, we removed the F::build() factory. WikiaApp still has some useful helper functions, and controllers still have the $this->wg attribute.

MediaWiki Wikia
// Global variables
global $wgCityId;
$city_id = $wgCityId;
 
global $wgMemc; 
$wgMemc->get('key');
// Global variables  (note there is no explicit global keyword)
$city_id = $wg->CityId;
 
$app->wg->memc->get('key');
// Constructing objects
$api = new PayflowAPI();
// Constructing objects
// @deprecated
 $api = F::build('PayflowAPI');
// Objects with non-default constructors
 $user = User::newFromId(1);
// Objects with non-default constructors
// @deprecated
 $user = F::build('User', array(1), 'newFromId');
// Calling global functions
 wfProfileIn();
// Calling global functions
// @deprecated
 $app->wf->profileIn()

In a controller Object we add the $app and $wg helpers as class vars so the calling convention looks like this:

 $this->wg->memc->get('key');
 
 $text = wfMessage('nirvana-is-awesome')->text();

In a template (View Object) we have added the $app $wg helpers to the template namespace itself, so the calling convention looks like this:

<?= $wg->BlankImgUrl ?>
 
<?= wfMessage('nirvana-is-awesome')->text() ?>

Conversion of legacy code

The nirvana framework has undergone some modification in the last few years and there is some code that is written in a "bad style". Please try to convert code to the newer/shorter syntax if possible. Here is an example of conversion of a Controller class that was using the old style syntax to the new style:

Link to github changeset

One example line from this change set:

// nirvana 1.0
$this->response->setVal('tab', $wgRequest->getVal('tab', 'general'));
// nirvana 2.0
$this->tab = $this->getVal('tab', 'general');

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.