/** * Execute the API call: Save the form values */ public function execute() { global $wgUser, $wgArticleFeedbackv5SMaxage; $params = $this->extractRequestParams(); // Anon token check $token = $this->getAnonToken($params); // Is feedback enabled on this page check? if (!ApiArticleFeedbackv5Utils::isFeedbackEnabled($params)) { $this->dieUsage('ArticleFeedback is not enabled on this page', 'invalidpage'); } $dbr = wfGetDB(DB_SLAVE); $pageId = $params['pageid']; $bucket = $params['bucket']; $revisionId = $params['revid']; $error = null; $userAnswers = array(); $fields = ApiArticleFeedbackv5Utils::getFields(); $emailData = array('ratingData' => array(), 'pageID' => $pageId, 'bucketId' => $bucket); // Validate the response data foreach ($fields as $field) { $field_name = $field['afi_name']; if ($field['afi_bucket_id'] != $bucket) { continue; } if (isset($params[$field['afi_name']])) { $value = $params[$field_name]; $type = $field['afi_data_type']; if ($value === '') { continue; } if (!$this->validateParam($value, $type, $field['afi_id'], $pageId)) { $error = 'articlefeedbackv5-error-validation'; break; } if ('text' == $type && $this->findAbuse($value, $pageId)) { $error = 'articlefeedbackv5-error-abuse'; break; } $data = array('aa_field_id' => $field['afi_id']); foreach (array('rating', 'text', 'boolean', 'option_id') as $t) { $data["aa_response_{$t}"] = $t == $type ? $value : null; } $userAnswers[] = $data; $emailData['ratingData'][$field_name] = $value; } } if ($error) { $this->getResult()->addValue(null, 'error', $error); return; } // Save the response data $ratingIds = $this->saveUserRatings($userAnswers, $bucket, $params); $ctaId = $ratingIds['cta_id']; $feedbackId = $ratingIds['feedback_id']; $this->saveUserProperties($feedbackId); $this->updateRollupTables($pageId, $revisionId, $userAnswers); $this->updateFilterCounts($pageId, $userAnswers); // If we have an email address, capture it if ($params['email']) { $this->captureEmail($params['email'], FormatJson::encode($emailData)); } $squidUpdate = new SquidUpdate(array(wfAppendQuery(wfScript('api'), array('action' => 'query', 'format' => 'json', 'list' => 'articlefeedbackv5-view-ratings', 'afpageid' => $pageId, 'maxage' => 0, 'smaxage' => $wgArticleFeedbackv5SMaxage)))); $squidUpdate->doUpdate(); wfRunHooks('ArticleFeedbackChangeRating', array($params)); $this->getResult()->addValue(null, $this->getModuleName(), array('result' => 'Success', 'feedback_id' => $feedbackId, 'cta_id' => $ctaId)); }