Phuedx has uploaded a new change for review.
https://gerrit.wikimedia.org/r/167574
Change subject: WIP Add the WikiGrokResponse API
......................................................................
WIP Add the WikiGrokResponse API
Log a MobileWebWikiGrokResponse event for each claim, selected or not.
Change-Id: Ic15cef7375e635cc5d9398730222417ebc590fae
---
A includes/api/ApiWikiGrokResponse.php
1 file changed, 140 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/74/167574/1
diff --git a/includes/api/ApiWikiGrokResponse.php
b/includes/api/ApiWikiGrokResponse.php
new file mode 100644
index 0000000..c2091ba
--- /dev/null
+++ b/includes/api/ApiWikiGrokResponse.php
@@ -0,0 +1,140 @@
+<?php
+/**
+ * ApiWikiGrokResponse.php
+ */
+
+/**
+ * Logs each claim in a WikiGrok response with the MobileWebWikiGrok schema.
+ */
+class ApiWikiGrokResponse extends ApiBase {
+
+ const MOBILEWEBWIKIGROKRESPONSE_SCHEMA = 'MobileWebWikiGrokResponse';
+ const MOBILEWEBWIKIGROKRESPONSE_SCHEMA_REV_ID = 10255772;
+
+ /**
+ * Executes the action.
+ *
+ * @see ApiBase::execute
+ */
+ public function execute() {
+ $params = $this->extractRequestParams();
+ $userId = $params['user_id'];
+ $user = User::newFromId( $userId );
+ $claims = $this->extractClaims( $params['claims'] );
+ $baseEvent = array(
+ 'pageId' => $params['subject_id'],
+ 'userId' => $userId,
+ 'userEditCount' => $user->getEditCount(),
+ 'taskToken' => $params['task_token'],
+ 'taskType' => $params['task_type'],
+ 'mobileMode' => $params['mobile_mode'],
+ );
+
+ foreach ( $claims as $claim ) {
+ $event = $baseEvent + array(
+ 'propertyId' => $claim['propid'],
+ 'property' => $claim['prop'],
+ 'valueId' => $claim['valueid'],
+ 'value' => $claim['value'],
+ 'valueSelected' => $claim['correct'],
+ );
+ EventLogging::logEvent(
+ MOBILEWEBWIKIGROKRESPONSE_SCHEMA,
+ MOBILEWEBWIKIGROKRESPONSE_SCHEMA_REV_ID,
+ $event
+ );
+ }
+ }
+
+ /**
+ * Extracts claims from the claims parameter.
+ *
+ * @param string $rawClaims
+ * @return array One or more claims
+ */
+ private function extractClaims( $rawClaims ) {
+ return json_decode( $rawClaims, true );
+ }
+
+ /**
+ * Gets the token type.
+ *
+ * @return string Always 'csrf'
+ */
+ public function needsToken() {
+ return 'csrf';
+ }
+
+ /**
+ * Gets the allowed parameters.
+ *
+ * @return array
+ */
+ protected function getAllowedParams() {
+ return array(
+ 'subject_id' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
+ 'user_id' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
+ 'user_edit_count' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_TYPE => 'integer'
+ ),
+ 'task_token' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBasE::PARAM_TYPE => 'string',
+ ),
+ 'claims' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBasE::PARAM_TYPE => 'string',
+ ),
+ 'task_type' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBasE::PARAM_TYPE => 'string',
+ ),
+ 'mobile_mode' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBasE::PARAM_TYPE => array(
+ 'stable',
+ 'alpha',
+ 'beta',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Gets the descriptions of the allowed parameters.
+ *
+ * @return array
+ */
+ public function getParamDescription() {
+ return array(
+ 'subject_id' => 'The ID of the page where the response
was submitted',
+ 'user_id' => 'The ID of the user who submitted the
response',
+ 'user_edit_count' => 'The edit count of the user who
submitted the response',
+ 'task_token' => 'The unique WikiGrok instance token',
+ 'claims' => 'The JSON encoded claims that the user
submitted',
+ 'task_type' => 'The version of WikiGrok that the user
interacted with',
+ 'mobile_mode' => 'The version of MobileFrontend that
the user was using',
+ );
+ }
+
+ /**
+ * Get the description of the action.
+ *
+ * @return string
+ */
+ public function getDescription() {
+ return 'Logs each claim in a WikiGrok response with the
MobileWebWikiGrok schema.';
+ }
+
+ // TODO (phuedx, 2014/10/20): Document this action on mw.org.
+ //public function getHelpUrls() {
+ // return
'https://www.mediawiki.org/wiki/Extension:MobileFrontend#action.3Dwikigrokresponse';
+ //}
+}
--
To view, visit https://gerrit.wikimedia.org/r/167574
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic15cef7375e635cc5d9398730222417ebc590fae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Phuedx <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits