/**
  * @brief This function gets messages from given list of packages
  */
 public function getMessages()
 {
     // get list of requested packages
     $packages = explode(',', $this->request->getVal('packages'));
     // get messages from given packages
     $messages = JSMessages::getPackages($packages);
     $this->setVal('messages', $messages);
     // this should be handled as JS script
     $this->response->setHeader('Content-type', 'application/javascript; charset=utf-8');
     // cache it well :)
     if (!$this->request->isInternal()) {
         $this->response->setCacheValidity(self::CACHE_TIME);
         $this->response->setContentType('text/javascript; charset=utf-8');
     }
 }
 /**
  * @brief this is a function that return rendered article
  *
  * @requestParam String title of a page
  */
 public function renderPage()
 {
     wfProfileIn(__METHOD__);
     $titleName = $this->request->getVal('page');
     $html = ApiService::call(array('action' => 'parse', 'page' => $titleName, 'prop' => 'text', 'redirects' => 1, 'useskin' => 'wikiamobile'));
     $this->response->setVal('globals', Skin::newFromKey('wikiamobile')->getTopScripts());
     $this->response->setVal('messages', JSMessages::getPackages(array('GameGuides')));
     $this->response->setVal('title', Title::newFromText($titleName)->getText());
     $this->response->setVal('html', $html['parse']['text']['*']);
     wfProfileOut(__METHOD__);
 }
 /**
  * Return different type of assets in a single request
  *
  * @requestParam string templates - JSON encoded array of controller / method and optional params used to render a template
  * @requestParam string styles - comma-separated list of SASS files
  * @requestParam string scripts - comma-separated list of AssetsManager groups
  * @requestParam string messages - comma-separated list of JSMessages packages
  * @requestParam integer ttl - cache period for varnish and browser (in seconds),
  *
  * @responseParam array templates - rendered templates (either HTML or JSON encoded string)
  * @responseParam array styles - minified styles
  * @responseParam array scripts - minified AssetsManager packages
  * @responseParam array messages - JS messages
  */
 public function getMultiTypePackage()
 {
     wfProfileIn(__METHOD__);
     $this->response->setFormat('json');
     $key = null;
     $data = null;
     $templates = $this->request->getVal('templates', null);
     $styles = $this->request->getVal('styles', null);
     $scripts = $this->request->getVal('scripts', null);
     $messages = $this->request->getVal('messages', null);
     $mustache = $this->request->getVal('mustache', null);
     $handlebars = $this->request->getVal('handlebars', null);
     $sassParams = $this->request->getVal('sassParams', null);
     // handle templates via sendRequest
     if (!is_null($templates)) {
         $profileId = __METHOD__ . "::templates::{$templates}";
         wfProfileIn($profileId);
         $templates = json_decode($templates, true);
         $templatesOutput = array();
         foreach ($templates as $template) {
             $params = !empty($template['params']) ? $template['params'] : array();
             if (!empty($template['controller']) && !empty($template['method'])) {
                 $res = $this->sendRequest($template['controller'], $template['method'], $params);
                 $templatesOutput["{$template['controller']}_{$template['method']}"] = $res->__toString();
             } else {
                 $templatesOutput[] = "Controller or method not given";
             }
         }
         $this->response->setVal('templates', $templatesOutput);
         wfProfileOut($profileId);
     }
     // handle SASS files
     if (!is_null($styles)) {
         $profileId = __METHOD__ . "::styles::{$styles}";
         wfProfileIn($profileId);
         $key = $this->getComponentMemcacheKey($styles, $sassParams);
         $data = $this->wg->Memc->get($key);
         if (empty($data)) {
             $styleFiles = explode(',', $styles);
             $data = '';
             foreach ($styleFiles as $styleFile) {
                 $builder = $this->getBuilder('sass', $styleFile);
                 if (!is_null($builder)) {
                     if (!empty($sassParams)) {
                         $builder->addParams($sassParams);
                     }
                     $data .= $builder->getContent();
                 }
             }
             $this->wg->Memc->set($key, $data, self::MEMC_TTL);
         }
         $this->response->setVal('styles', $data);
         wfProfileOut($profileId);
     }
     // handle assets manager JS packages
     if (!is_null($scripts)) {
         $profileId = __METHOD__ . "::scripts::{$scripts}";
         wfProfileIn($profileId);
         $key = $this->getComponentMemcacheKey($scripts);
         $data = $this->wg->Memc->get($key);
         if (empty($data)) {
             $scriptPackages = explode(',', $scripts);
             $data = array();
             foreach ($scriptPackages as $package) {
                 $builder = $this->getBuilder('group', $package);
                 if (!is_null($builder)) {
                     $data[] = $builder->getContent();
                 }
             }
             $this->wg->Memc->set($key, $data, self::MEMC_TTL);
         }
         $this->response->setVal('scripts', $data);
         wfProfileOut($profileId);
     }
     // handle JSMessages
     if (!is_null($messages)) {
         $profileId = __METHOD__ . "::messages::{$messages}";
         wfProfileIn($profileId);
         $messagePackages = explode(',', $messages);
         $this->response->setVal('messages', JSMessages::getPackages($messagePackages));
         wfProfileOut($profileId);
     }
     // handle mustache templates (BugId:30841)
     foreach (['mustache', 'handlebars'] as $templateLanguage) {
         $template = ${$templateLanguage};
         if (is_null($template)) {
             continue;
         }
         $profileId = __METHOD__ . "::{$templateLanguage}::{$template}";
         wfProfileIn($profileId);
         $templates = explode(',', $template);
         $this->response->setVal($templateLanguage, $this->getTemplates($templates, $templateLanguage));
         wfProfileOut($profileId);
     }
     $this->response->setCacheValidity(WikiaResponse::CACHE_LONG);
     $this->response->setFormat('json');
     wfProfileOut(__METHOD__);
 }
 /**
  * @brief this is a function that return rendered article
  *
  * @requestParam String title of a page
  */
 public function renderPage()
 {
     wfProfileIn(__METHOD__);
     $titleName = $this->request->getVal('page');
     $html = ApiService::call(array('action' => 'parse', 'page' => $titleName, 'prop' => 'text', 'redirects' => 1, 'useskin' => 'wikiamobile'));
     $this->response->setVal('globals', Skin::newFromKey('wikiamobile')->getTopScripts());
     $this->response->setVal('messages', JSMessages::getPackages(array('CuratedContent')));
     $this->response->setVal('title', Title::newFromText($titleName)->getText());
     // TODO: Remove 'infoboxFixSectionReplace', it's temporary fix for mobile aps
     // See: DAT-2864 and DAT-2859
     $this->response->setVal('html', $this->infoboxFixSectionReplace($html['parse']['text']['*']));
     wfProfileOut(__METHOD__);
 }