https://www.mediawiki.org/wiki/Special:Code/MediaWiki/106965
Revision: 106965 Author: gregchiasson Date: 2011-12-21 19:04:14 +0000 (Wed, 21 Dec 2011) Log Message: ----------- 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: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php =================================================================== --- trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php 2011-12-21 18:58:27 UTC (rev 106964) +++ trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php 2011-12-21 19:04:14 UTC (rev 106965) @@ -90,6 +90,7 @@ } $ctaId = $this->saveUserRatings( $user_answers, $feedbackId, $bucket ); + $this->saveUserProperties( $revisionId ); $this->updateRollupTables( $pageId, $revisionId, $user_answers ); if ( $params['email'] ) { @@ -512,6 +513,82 @@ return $ctaId; } + /** + * Inserts or updates properties for a specific rating + * @param $revisionId int Revision ID + */ + private function saveUserProperties( $revisionId ) { + global $wgUser; + $dbw = wfGetDB( DB_MASTER ); + $dbr = wfGetDB( DB_SLAVE ); + $rows = array(); + + // Only save data for logged-in users. + if( !$wgUser->isLoggedIn() ) { + return null; + } + + // 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. So, fetch + // the most recent feedback ID for this user on this revision. + // This gets called imediately after saving, so it'll almost + // certainly be the right one. + $feedbackId = $dbr->selectField( + 'aft_article_feedback', + 'af_id', + array( + 'af_revision_id' => $revisionId, + 'af_user_id' => $wgUser->getId() + ), + __METHOD__, + array( + 'ORDER BY' => 'af_id DESC', + 'LIMIT' => 1 + ) + ); + + // Total edits by this user + $rows[] = array( + 'afp_feedback_id' => $feedbackId, + 'afp_key' => 'contribs-lifetime', + 'afp_value_int' => ( integer ) $wgUser->getEditCount() + ); + + // Use the UserDailyContribs extension if it's present. Get + // edit counts for last 6 months, last 3 months, and last month. + if ( function_exists( 'getUserEditCountSince' ) ) { + $now = time(); + + $rows[] = array( + 'afp_feedback_id' => $feedbackId, + 'afp_key' => 'contribs-6-months', + 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 365 / 2 ) ) + ); + + $rows[] = array( + 'afp_feedback_id' => $feedbackId, + 'afp_key' => 'contribs-3-months', + 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 365 / 4 ) ) + ); + + $rows[] = array( + 'afp_feedback_id' => $feedbackId, + 'afp_key' => 'contribs-1-months', + 'afp_value_int' => getUserEditCountSince( $now - ( 60 * 60 * 24 * 30 ) ) + ); + } + + $dbw->insert( + 'aft_article_feedback_properties', + $rows, + __METHOD__ + ); + } + + /** * Picks a CTA to send the user to * _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs