public function index() { wfProfileIn(__METHOD__); $this->wg->Out->setPageTitle(wfMsg('managewikiahome')); if (!$this->checkAccess()) { wfProfileOut(__METHOD__); $this->forward('ManageWikiaHome', 'onWrongRights'); return false; } $this->setVal('slotsInTotal', WikiaHomePageHelper::SLOTS_IN_TOTAL); $this->infoMsg = FlashMessages::pop(); //wikis with visualization selectbox $visualizationLang = $this->wg->request->getVal(self::WHST_VISUALIZATION_LANG_VAR_NAME, $this->wg->contLang->getCode()); $visualizationLang = substr(strtolower($visualizationLang), 0, 2); $this->visualizationLang = $visualizationLang; $this->visualizationWikisData = $this->helper->getVisualizationWikisData(); $this->currentPage = $this->request->getVal('page', 1); $this->corpWikiId = $this->visualizationWikisData[$this->visualizationLang]['wikiId']; $this->filterOptions = array_merge($this->initFilterOptions(), $this->request->getParams()); $this->exportListAsCSVUri = $this->getExportListAsCSVUri(); //verticals slots' configuration /* @var $this->helper WikiaHomePageHelper */ $videoGamesAmount = $this->request->getVal('video-games-amount', $this->helper->getNumberOfVideoGamesSlots($this->visualizationLang)); $entertainmentAmount = $this->request->getVal('entertainment-amount', $this->helper->getNumberOfEntertainmentSlots($this->visualizationLang)); $lifestyleAmount = $this->request->getVal('lifestyle-amount', $this->helper->getNumberOfLifestyleSlots($this->visualizationLang)); $this->form = new CollectionsForm(); $this->statsForm = new StatsForm(); $this->hubsForm = new HubsSlotsForm(); $savedSlotsValues = $this->helper->getHubSlotsFromWF($this->corpWikiId, $visualizationLang); $homePageSlotsValues = $this->prepareSlots($savedSlotsValues); $collectionsModel = $this->getWikiaCollectionsModel(); $this->collectionsList = $collectionsModel->getList($this->visualizationLang); $collectionValues = $this->prepareArrayFieldsToShow($this->collectionsList); $wikisPerCollection = $this->getWikisPerCollection($this->collectionsList); $statsValues = $this->app->sendRequest('WikiaStatsController', 'getWikiaStatsFromWF')->getData(); if ($this->request->wasPosted()) { if ($this->request->getVal('wikis-in-slots', false)) { //todo: separate post request handling //todo: move validation from saveSlotsConfigInWikiFactory() to helper $total = intval($videoGamesAmount) + intval($entertainmentAmount) + intval($lifestyleAmount); if ($total !== WikiaHomePageHelper::SLOTS_IN_TOTAL) { $this->errorMsg = wfMessage('manage-wikia-home-error-invalid-total-no-of-slots')->params(array($total, WikiaHomePageHelper::SLOTS_IN_TOTAL))->text(); } elseif ($this->isAnySlotNumberNegative($videoGamesAmount, $entertainmentAmount, $lifestyleAmount)) { $this->errorMsg = wfMessage('manage-wikia-home-error-negative-slots-number-not-allowed')->text(); } else { $this->saveSlotsConfigInWikiFactory($this->corpWikiId, $visualizationLang, array(WikiaHomePageHelper::VIDEO_GAMES_SLOTS_VAR_NAME => $videoGamesAmount, WikiaHomePageHelper::ENTERTAINMENT_SLOTS_VAR_NAME => $entertainmentAmount, WikiaHomePageHelper::LIFESTYLE_SLOTS_VAR_NAME => $lifestyleAmount)); } } elseif ($this->request->getVal('collections', false)) { $collectionValues = $this->request->getParams(); $collectionValues = $this->form->filterData($collectionValues); $isValid = $this->form->validate($collectionValues); if ($isValid) { $collectionSavedValues = $this->prepareArrayFieldsForSave($collectionValues); $collectionsModel->saveAll($this->visualizationLang, $collectionSavedValues); FlashMessages::put(wfMessage('manage-wikia-home-collections-success')->text()); $this->response->redirect($_SERVER['REQUEST_URI']); } else { $this->errorMsg = wfMessage('manage-wikia-home-collections-failure')->text(); } } elseif ($this->request->getVal('stats', false)) { $statsValues = $this->request->getParams(); $statsValues = $this->statsForm->filterData($statsValues); $isValid = $this->statsForm->validate($statsValues); if ($isValid) { $isAllowed = true; try { $this->app->sendRequest('WikiaStatsController', 'saveWikiaStatsInWF', array('statsValues' => $statsValues)); } catch (PermissionsException $ex) { $isAllowed = false; } if ($isAllowed) { FlashMessages::put(wfMessage('manage-wikia-home-stats-success')->text()); $this->response->redirect($_SERVER['REQUEST_URI']); } else { $this->errorMsg = wfMessage('manage-wikia-home-stats-permissions-error')->text(); } } else { $this->errorMsg = wfMessage('manage-wikia-home-stats-failure')->text(); } } elseif ($this->request->getVal('hubs-slots', false)) { $homePageSlotsValues = $this->request->getParams(); $homePageSlotsValues = $this->hubsForm->filterData($homePageSlotsValues); $homePageSlotsValues = $this->filterUrls($homePageSlotsValues); $hubSavedSlotsValues = $homePageSlotsValues['hub_slot']; $marketingSlotsValues = $this->getMarketingSlotsValues($homePageSlotsValues); $marketingSavedSlotsValues = $this->prepareArrayFieldsForSave($marketingSlotsValues); $isValid = $this->hubsForm->validate($homePageSlotsValues); $isValid &= $this->validateMarketingSlots($marketingSavedSlotsValues); if ($isValid) { $savedSlotsValues = ['hub_slot' => $hubSavedSlotsValues, 'marketing_slot' => $marketingSavedSlotsValues]; $status = $this->helper->saveHubSlotsToWF($savedSlotsValues, $this->corpWikiId, $this->visualizationLang, 'wgWikiaHomePageHubsSlotsV2'); if ($status) { $this->infoMsg = wfMessage('manage-wikia-home-hubs-slot-success')->text(); } else { $this->errorMsg = wfMessage('manage-wikia-home-hubs-slot-error')->text(); } } } } $this->form->setFieldsValues($collectionValues); $this->statsForm->setFieldsValues($statsValues); $this->verticals = $this->helper->getWikiVerticals(); $this->marketingImages = []; if (array_key_exists('marketing_slots', $savedSlotsValues)) { $this->marketingImages = $this->prepareMarketingSlotImages($savedSlotsValues['marketing_slot']); } $this->prepareHubsForm($homePageSlotsValues); $this->setVal('videoGamesAmount', $videoGamesAmount); $this->setVal('entertainmentAmount', $entertainmentAmount); $this->setVal('lifestyleAmount', $lifestyleAmount); $this->setVal('wikisPerCollection', $wikisPerCollection); $this->response->addAsset('/extensions/wikia/SpecialManageWikiaHome/css/ManageWikiaHome.scss'); $this->response->addAsset('manage_wikia_home_js'); JSMessages::enqueuePackage('ManageWikiaHome', JSMessages::EXTERNAL); $this->wg->Out->addJsConfigVars(['wgWikisPerCollection' => $wikisPerCollection, 'wgSlotsInTotal' => WikiaHomePageHelper::SLOTS_IN_TOTAL]); wfProfileOut(__METHOD__); }
/** * Main action for editing hub modules */ public function editHubAction() { global $wgCityId; if (!$this->checkAccess()) { return false; } $this->retriveDataFromUrl(); $this->wg->Out->addJsConfigVars(['wgEditHubModuleIdSelected' => $this->selectedModuleId, 'wgEditHubModuleIdPopularVideos' => WikiaHubsModulePopularvideosService::MODULE_ID, 'wgEditHubModuleIdFeaturedVideo' => WikiaHubsModuleFeaturedvideoService::MODULE_ID]); $this->checkDate($this->date); $this->flashMessage = FlashMessages::pop(); $modulesData = $this->editHubModel->getModulesData($wgCityId, $this->date, $this->selectedModuleId); $this->prepareLayoutData($this->selectedModuleId, $modulesData); $this->response->addAsset('resources/jquery/jquery.validate.js'); $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/EditHub.js'); $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/EditHubNavigation.js'); $this->response->addAsset('/extensions/wikia/SpecialEditHub/js/jquery.MetaData.js'); $selectedModuleValues = $modulesData['moduleList'][$this->selectedModuleId]['data']; $module = WikiaHubsModuleService::getModuleByName($this->editHubModel->getNotTranslatedModuleName($this->selectedModuleId), $wgCityId); $form = new FormBuilderService(EditHubModel::FORM_FIELD_PREFIX); $form->setFields($module->getFormFields()); if ($this->request->wasPosted()) { $selectedModuleValues = $this->request->getParams(); $selectedModuleValues = $module->filterData($selectedModuleValues); $isValid = $form->validate($selectedModuleValues); if ($isValid) { $this->editHubModel->saveModule(['cityId' => $wgCityId, 'langCode' => $this->wg->ContLang->getCode(), 'verticalId' => WikiFactoryHub::getInstance()->getCategoryId($wgCityId)], $this->date, $this->selectedModuleId, $selectedModuleValues, $this->wg->user->getId()); $this->purgeCache($module); FlashMessages::put(wfMessage('edit-hub-module-save-ok', $modulesData['activeModuleName'])->escaped()); $nextUrl = $this->getNextModuleUrl(); $this->response->redirect($nextUrl); } else { $this->errorMessage = wfMessage('edit-hub-module-save-error')->escaped(); } } $form->setFieldsValues($selectedModuleValues); $this->moduleName = $modulesData['activeModuleName']; $this->moduleContent = $module->renderEditor(['form' => $form]); $this->overrideTemplate('editHub'); }