/**
  * @desc Renders a table with wikis in visualization on corporate page plus pagination if needed
  *
  * @requestParam string $visualizationLang language code of wikis
  * @requestParam integer $page page number
  * @requestParam string $wikiHeadline a string filtering the list
  *
  * @return false if user does not have permissions
  */
 public function renderWikiListPage()
 {
     $this->wf->ProfileIn(__METHOD__);
     if (!$this->checkAccess()) {
         return false;
     }
     //todo: move to __construct() the same in index()
     if (empty($this->visualizationLang)) {
         $visualizationLang = $this->request->getVal('visualizationLang', $this->wg->contLang->getCode());
     } else {
         $visualizationLang = $this->visualizationLang;
     }
     $this->currentPage = $this->request->getVal('page', 1);
     //todo: new class for options
     $options = new stdClass();
     $options->lang = $visualizationLang;
     $options->wikiHeadline = $this->request->getVal('wikiHeadline', '');
     $count = $this->helper->getWikisCountForStaffTool($options);
     $options->limit = self::WHST_WIKIS_PER_PAGE;
     $options->offset = ($this->currentPage - 1) * self::WHST_WIKIS_PER_PAGE;
     $specialPage = F::build('Title', array('ManageWikiaHome', NS_SPECIAL), 'newFromText');
     //todo: getLocalUrl(array('vl' => $visualizationLang, 'page' => '%s')) doesn't work here because % sign is being escaped
     $url = $specialPage->getLocalUrl() . '?vl=' . $visualizationLang . '&page=%s';
     if ($count > self::WHST_WIKIS_PER_PAGE) {
         /** @var $paginator Paginator */
         $paginator = F::build('Paginator', array(array_fill(0, $count, ''), self::WHST_WIKIS_PER_PAGE), 'newFromArray');
         $paginator->setActivePage($this->currentPage - 1);
         $this->setVal('pagination', $paginator->getBarHTML($url));
     }
     $this->list = $this->helper->getWikisForStaffTool($options);
     $this->wf->ProfileOut(__METHOD__);
 }
 public function getWikisInVisualisationAsCSV()
 {
     wfProfileIn(__METHOD__);
     global $wgOut;
     if (!$this->checkAccess()) {
         wfProfileOut(__METHOD__);
         $this->response->setHeader('Cache-Control', 'no-cache');
         throw new PermissionsException('managewikiahome');
     }
     // get data
     $visualizationLang = $this->request->getVal('lang', $this->wg->contLang->getCode());
     $list = $this->helper->getWikisForStaffTool($this->prepareFilterOptions($visualizationLang, []));
     $collections = $this->getWikiaCollectionsModel()->getList($visualizationLang);
     $verticals = $this->helper->getWikiVerticals();
     // output data in csv format
     $out = fopen('php://memory', 'w');
     // header
     $outHeader = ['ID', 'Vertical', 'Title', 'Is blocked?', 'Is promoted?', 'Is official?'];
     foreach ($collections as $collection) {
         $outHeader[] = 'In collection: ' . $collection['name'] . '?';
     }
     fputcsv($out, $outHeader);
     foreach ($list as $wiki) {
         $outLine = [$wiki->city_id, $verticals[$wiki->city_vertical], $wiki->city_title, CityVisualization::isBlockedWiki($wiki->city_flags) ? 1 : 0, CityVisualization::isPromotedWiki($wiki->city_flags) ? 1 : 0, CityVisualization::isOfficialWiki($wiki->city_flags) ? 1 : 0];
         foreach ($collections as $collection) {
             $outLine[] = in_array($collection['id'], $wiki->collections) ? 1 : 0;
         }
         fputcsv($out, $outLine);
     }
     fseek($out, 0);
     $csv = stream_get_contents($out);
     fclose($out);
     // turn off usual rendering
     $wgOut->disable();
     // set up headers
     $this->response->setFormat(WikiaResponse::FORMAT_RAW);
     $this->response->setHeader('Cache-Control', 'private');
     $this->response->setHeader('Content-Description', 'File Transfer');
     $this->response->setHeader('Content-Disposition', 'attachment; filename=ManageWikiaHomeWikisList-' . $visualizationLang . '.csv');
     $this->response->setHeader('Content-Transfer-Encoding', 'binary');
     $this->response->setContentType('application/octet-stream');
     $this->response->setBody($csv);
     wfProfileOut(__METHOD__);
 }