r105014 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105013‎ | r105014 | r105015 >
Date:22:22, 2 December 2011
Author:gregchiasson
Status:resolved (Comments)
Tags:
Comment:
AFTv5 - enable saving email addresses using the EmailCapture extension, same way v4 did it. Sort of think this should be it's own input and be stored in aft_article_answer, but for now let's keep it the same, I guess.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -44,6 +44,11 @@
4545 $pageId = $params['pageid'];
4646 $bucket = $params['bucket'];
4747 $revisionId = $params['revid'];
 48+ $email_data = array(
 49+ 'ratingData' => array(),
 50+ 'pageID' => $pageId,
 51+ 'bucketId' => $bucket
 52+ );
4853
4954 $user_answers = array();
5055 $fields = ApiArticleFeedbackv5Utils::getFields();
@@ -66,6 +71,7 @@
6772 $data["aa_response_$t"] = $t == $type ? $value : null;
6873 }
6974 $user_answers[] = $data;
 75+ $email_data['ratingData'][$field->afi_name] = $value;
7076 } else {
7177 // TODO: ERROR
7278 }
@@ -75,6 +81,12 @@
7682 $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket );
7783 $this->updateRollupTables( $pageId, $revisionId );
7884
 85+ if( $params['email'] ) {
 86+ $this->captureEmail ( $params['email'], json_encode(
 87+ $email_data
 88+ ) );
 89+ }
 90+
7991 $squidUpdate = new SquidUpdate( array(
8092 wfAppendQuery( wfScript( 'api' ), array(
8193 'action' => 'query',
@@ -102,6 +114,19 @@
103115 );
104116 }
105117
 118+ protected function captureEmail( $email, $json ) {
 119+ global $wgScriptPath, $wgServer;
 120+ $url = "$wgServer$wgScriptPath/api.php";
 121+ $body = "email=$email&info=$json&action=emailcapture&format=json";
 122+ $c = curl_init ( $url );
 123+ curl_setopt( $c, CURLOPT_POST, true );
 124+ curl_setopt( $c, CURLOPT_POSTFIELDS, $body );
 125+ curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
 126+
 127+ $rv = curl_exec( $c );
 128+ curl_close( $c );
 129+ }
 130+
106131 /**
107132 * Validates a value against a field type
108133 *
@@ -382,6 +407,11 @@
383408 ApiBase::PARAM_ISMULTI => false,
384409 ApiBase::PARAM_MIN => 0
385410 ),
 411+ 'email' => array(
 412+ ApiBase::PARAM_TYPE => 'string',
 413+ ApiBase::PARAM_REQUIRED => false,
 414+ ApiBase::PARAM_ISMULTI => false,
 415+ )
386416 );
387417
388418 $fields = ApiArticleFeedbackv5Utils::getFields();
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -29,11 +29,11 @@
3030 $params = $this->extractRequestParams();
3131 $html = '';
3232 $result = $this->getResult();
33 - $pageId = $params['pageid'];
 33+ $pageId = $params['pageid'];
3434 $length = 0;
3535 $count = $this->fetchFeedbackCount(
3636 $params['pageid'], $params['filter'] );
37 - $feedback = $this->fetchFeedback(
 37+ $feedback = $this->fetchFeedback(
3838 $params['pageid'],
3939 $params['filter'],
4040 $params['sort'],
@@ -41,14 +41,14 @@
4242 $params['offset']
4343 );
4444
45 - foreach ( $feedback as $record ) {
 45+ foreach ( $feedback as $record ) {
4646 $html .= $this->renderFeedback($record);
4747 $length++;
48 - }
 48+ }
4949
50 - $result->addValue( 'data', 'length', $length );
51 - $result->addValue( 'data', 'count', $count );
52 - $result->addValue( 'data', 'feedback', $html );
 50+ $result->addValue( 'data', 'length', $length );
 51+ $result->addValue( 'data', 'count', $count );
 52+ $result->addValue( 'data', 'feedback', $html );
5353 }
5454
5555 public function fetchOverallRating( $pageId ) {
@@ -85,10 +85,10 @@
8686 $where['af_page_id'] = $pageId;
8787
8888 return $dbr->selectField(
89 - array( 'aft_article_feedback' ),
90 - array( 'COUNT(*) AS count' ),
 89+ array( 'aft_article_feedback' ),
 90+ array( 'COUNT(*) AS count' ),
9191 $where
92 - );
 92+ );
9393 }
9494
9595 public function fetchFeedback( $pageId,
@@ -340,7 +340,7 @@
341341 *
342342 * @return array the example as the first element in an array
343343 */
344 - protected function getExamples() {
 344+ public function getExamples() {
345345 return array(
346346 'api.php?action=query&list=articlefeedbackv5-view-feedback&afpageid=1',
347347 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r105020Follow up to r105014, do the EmailCapture API call properly.gregchiasson22:57, 2 December 2011

Comments

#Comment by Johnduhart (talk | contribs)   22:32, 2 December 2011
+	protected function captureEmail( $email, $json ) {
+		global $wgScriptPath, $wgServer;
+		$url  = "$wgServer$wgScriptPath/api.php";
+		$body = "email=$email&info=$json&action=emailcapture&format=json";
+		$c = curl_init ( $url );
+		curl_setopt( $c, CURLOPT_POST, true );
+		curl_setopt( $c, CURLOPT_POSTFIELDS, $body );
+		curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
+
+		$rv = curl_exec( $c );
+		curl_close( $c );
+	}
+

Use the internal API, not HTTP requests....

#Comment by Gregchiasson (talk | contribs)   01:05, 9 December 2011

Fixed in r105020, still marked fixme.

#Comment by P858snake (talk | contribs)   06:06, 10 December 2011

Can someone un-fixme and manually add the follow up?

#Comment by P858snake (talk | contribs)   06:07, 10 December 2011

(Skip the part about followup, Didn't see it listed when I scanned the page)

Status & tagging log