public function execute() { $params = $this->extractRequestParams(); $data = array(); $ucprop = $params['ucprop']; if (isset($params['campaigns'])) { $campaigns = $params['campaigns']; } else { $dbr = wfGetDB(DB_SLAVE); $rows = $dbr->select('uw_campaigns', 'campaign_name', '1', __METHOD__); $campaigns = array(); foreach ($rows as $row) { $campaigns[] = $row->campaign_name; } } foreach ($campaigns as $campaign) { $campaign = UploadWizardCampaign::newFromName($campaign); if ($campaign) { $data[] = $this->formatRow($campaign, $ucprop); } } $result = $this->getResult(); $result->setIndexedTagName($data, 'campaign'); $result->addValue(array('uploadcampaign'), 'campaigns', $data); }
public function execute($subPage) { $request = $this->getRequest(); $dbr = wfGetDB(DB_SLAVE); $start = (int) $request->getVal('start'); $limit = 50; $cond = array('campaign_enabled = 1'); if ($start !== null) { // Not SQL Injection, since $start is cast to (int) $cond[] = "campaign_id > {$start}"; } $res = $dbr->select('uw_campaigns', array('campaign_id', 'campaign_name'), $cond, __METHOD__, array('LIMIT' => $limit + 1)); $this->getOutput()->setPageTitle($this->msg('mwe-upload-campaigns-list-title')); $this->getOutput()->addModules('ext.uploadWizard.uploadCampaign.list'); $this->getOutput()->addHTML('<dl>'); $curCount = 0; $lastId = null; foreach ($res as $row) { $curCount++; if ($curCount > $limit) { // We've an extra element. Paginate! $lastId = $row->campaign_id; break; } else { $campaign = UploadWizardCampaign::newFromName($row->campaign_name); $this->getOutput()->addHTML($this->getHtmlForCampaign($campaign)); } } $this->getOutput()->addHTML('</dl>'); // Pagination links! if ($lastId !== null) { $this->getOutput()->addHTML($this->getHtmlForPagination($lastId)); } }
/** * Handles the campaign parameter. * * @since 1.2 */ protected function handleCampaign() { global $wgRequest; $campaignName = $wgRequest->getVal('campaign'); if ($campaignName != '') { $campaign = UploadWizardCampaign::newFromName($campaignName, false); if ($campaign === false) { $this->displayError(wfMsgExt('mwe-upwiz-error-nosuchcampaign', 'parsemag', $campaignName)); } else { if ($campaign->getIsEnabled()) { $this->campaign = $campaignName; } else { $this->displayError(wfMsgExt('mwe-upwiz-error-campaigndisabled', 'parsemag', $campaignName)); } } } }
public function execute() { $params = $this->extractRequestParams(); $limit = $params['limit']; $this->addTables('uw_campaigns'); $this->addWhereIf(array('campaign_enabled' => 1), $params['enabledonly']); $this->addOption('LIMIT', $limit + 1); $this->addOption('ORDER BY', 'campaign_id'); // Not sure if required? $this->addFields(array('campaign_id', 'campaign_name', 'campaign_enabled')); if (!is_null($params['continue'])) { $from_id = (int) $params['continue']; $this->addWhere("campaign_id >= {$from_id}"); // Not SQL Injection, since we already force this to be an integer } $res = $this->select(__METHOD__); $result = $this->getResult(); $count = 0; foreach ($res as $row) { if (++$count > $limit) { // We have more results than $limit. Set continue $this->setContinueEnumParameter('continue', $row->campaign_id); break; } $campaign = UploadWizardCampaign::newFromName($row->campaign_name); $campaignPath = array('query', $this->getModuleName(), $row->campaign_id); $result->addValue($campaignPath, '*', json_encode($campaign->getParsedConfig())); $result->addValue($campaignPath, 'name', $campaign->getName()); $result->addValue($campaignPath, 'trackingCategory', $campaign->getTrackingCategory()->getDBKey()); $result->addValue($campaignPath, 'totalUploads', $campaign->getUploadedMediaCount()); if (UploadWizardConfig::getSetting('campaignExpensiveStatsEnabled') === true) { $result->addValue($campaignPath, 'totalContributors', $campaign->getTotalContributorsCount()); } } if (defined('ApiResult::META_CONTENT')) { $result->addIndexedTagName(array('query', $this->getModuleName()), 'campaign'); } else { $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'campaign'); } }
/** * Returns the configuration of the specified campaign, * or an empty array when the campaign is not found or not enabled. * * @since 1.2 * * @param string $campaignName * * @return array */ protected static function getCampaignConfig($campaignName) { if (!is_null($campaignName)) { $campaign = UploadWizardCampaign::newFromName($campaignName); if ($campaign !== false && $campaign->getIsEnabled()) { return $campaign->getConfigForGlobalMerge(); } } return array(); }
/** * Process the form. At this point we know that the user passes all the criteria in * userCanExecute(), and if the data array contains 'Username', etc, then Username * resets are allowed. * @param $data array * @return Bool|Array */ public function onSubmit(array $data) { $id = $data['Campaignid'] == '' ? null : $data['Campaignid']; unset($data['Campaignid']); $name = $data['Campaignname']; unset($data['Campaignname']); $enabled = $data['Campaignenabled']; unset($data['Campaignenabled']); if (is_null($id)) { $existingCampaign = UploadWizardCampaign::newFromName($name, false); $id = $existingCampaign === false ? null : $existingCampaign->getId(); } $campaign = new UploadWizardCampaign($id, $name, $enabled, $data); $success = $campaign->writeToDB(); if ($success) { return true; } else { return array(); // TODO } }
/** * Handles the campaign parameter. * * @since 1.2 */ protected function handleCampaign() { $campaignName = $this->getRequest()->getVal('campaign'); if ($campaignName != '') { $campaign = UploadWizardCampaign::newFromName($campaignName, false); if ($campaign === false) { $this->displayError($this->msg('mwe-upwiz-error-nosuchcampaign', $campaignName)->text()); } else { if ($campaign->getIsEnabled()) { $this->campaign = $campaignName; } else { $this->displayError($this->msg('mwe-upwiz-error-campaigndisabled', $campaignName)->text()); } } } }