r106965 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106964‎ | r106965 | r106966 >
Date:19:04, 21 December 2011
Author:gregchiasson
Status:resolved (Comments)
Tags:aft 
Comment:
AFTv5 - enable use of feedback properties table to store user edit counts (if user is logged in).
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -90,6 +90,7 @@
9191 }
9292
9393 $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket );
 94+ $this->saveUserProperties( $revisionId );
9495 $this->updateRollupTables( $pageId, $revisionId, $user_answers );
9596
9697 if ( $params['email'] ) {
@@ -512,6 +513,82 @@
513514 return $ctaId;
514515 }
515516
 517+ /**
 518+ * Inserts or updates properties for a specific rating
 519+ * @param $revisionId int Revision ID
 520+ */
 521+ private function saveUserProperties( $revisionId ) {
 522+ global $wgUser;
 523+ $dbw = wfGetDB( DB_MASTER );
 524+ $dbr = wfGetDB( DB_SLAVE );
 525+ $rows = array();
 526+
 527+ // Only save data for logged-in users.
 528+ if( !$wgUser->isLoggedIn() ) {
 529+ return null;
 530+ }
 531+
 532+ // I'd really rather have this passed in, to save a query,
 533+ // and rule out consistency problems, but there doesn't seem
 534+ // to be a way to do 'RETUNING af_id' on the insert, or to
 535+ // pre-increment the ID column (since it's a MySQL auto-
 536+ // increment, not a sequence) before the insert. So, fetch
 537+ // the most recent feedback ID for this user on this revision.
 538+ // This gets called imediately after saving, so it'll almost
 539+ // certainly be the right one.
 540+ $feedbackId = $dbr->selectField(
 541+ 'aft_article_feedback',
 542+ 'af_id',
 543+ array(
 544+ 'af_revision_id' => $revisionId,
 545+ 'af_user_id' => $wgUser->getId()
 546+ ),
 547+ __METHOD__,
 548+ array(
 549+ 'ORDER BY' => 'af_id DESC',
 550+ 'LIMIT' => 1
 551+ )
 552+ );
 553+
 554+ // Total edits by this user
 555+ $rows[] = array(
 556+ 'afp_feedback_id' => $feedbackId,
 557+ 'afp_key' => 'contribs-lifetime',
 558+ 'afp_value_int' => ( integer ) $wgUser->getEditCount()
 559+ );
 560+
 561+ // Use the UserDailyContribs extension if it's present. Get
 562+ // edit counts for last 6 months, last 3 months, and last month.
 563+ if ( function_exists( 'getUserEditCountSince' ) ) {
 564+ $now = time();
 565+
 566+ $rows[] = array(
 567+ 'afp_feedback_id' => $feedbackId,
 568+ 'afp_key' => 'contribs-6-months',
 569+ 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 365 / 2 ) )
 570+ );
 571+
 572+ $rows[] = array(
 573+ 'afp_feedback_id' => $feedbackId,
 574+ 'afp_key' => 'contribs-3-months',
 575+ 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 365 / 4 ) )
 576+ );
 577+
 578+ $rows[] = array(
 579+ 'afp_feedback_id' => $feedbackId,
 580+ 'afp_key' => 'contribs-1-months',
 581+ 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 30 ) )
 582+ );
 583+ }
 584+
 585+ $dbw->insert(
 586+ 'aft_article_feedback_properties',
 587+ $rows,
 588+ __METHOD__
 589+ );
 590+ }
 591+
 592+
516593 /**
517594 * Picks a CTA to send the user to
518595 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r108505Remove boneheaded non-use of insertId in AFTv5 (actually already being used, ...gregchiasson15:17, 10 January 2012

Comments

#Comment by Catrope (talk | contribs)   11:12, 10 January 2012
		// I'd really rather have this passed in, to save a query,
+		// and rule out consistency problems, but there doesn't seem
+		// to be a way to do 'RETUNING af_id' on the insert, or to 
+		// pre-increment the ID column (since it's a MySQL auto-
+		// increment, not a sequence) before the insert.

There is a way to do this, actually. Use $afid = $dbw->insertId(); right after the INSERT query. Marking fixme because this is vulnerable to race conditions, and generally more complicated than it needs to be. OK otherwise.

Status & tagging log