r105385 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105384‎ | r105385 | r105386 >
Date:23:52, 6 December 2011
Author:bsitu
Status:resolved
Tags:
Comment:
Add Moodbar type stat for feedbackdashboard page, MoodBarSetUserEmal API and edit summary
Modified paths:
  • /trunk/extensions/MoodBar/ApiFeedbackDashboardResponse.php (modified) (history)
  • /trunk/extensions/MoodBar/ApiMoodBarSetUserEmail.php (added) (history)
  • /trunk/extensions/MoodBar/MoodBar.i18n.php (modified) (history)
  • /trunk/extensions/MoodBar/MoodBar.php (modified) (history)
  • /trunk/extensions/MoodBar/SpecialFeedbackDashboard.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/SpecialFeedbackDashboard.php
@@ -16,7 +16,7 @@
1717
1818 public function execute( $par ) {
1919 global $wgOut, $wgRequest;
20 -
 20+
2121 $limit = 20;
2222 $offset = false;
2323 $filterType = '';
@@ -63,6 +63,43 @@
6464 }
6565
6666 /**
 67+ * Get the stats for the moodbar type in the last 24 hours
 68+ * @return array - count of number for each moodbar type
 69+ */
 70+ public function getMoodBarTypeStats( ) {
 71+
 72+ global $wgMemc;
 73+
 74+ $timestamp = time() - 24 * 60 * 60; // 24 hours ago
 75+
 76+ // Try cache first
 77+ $key = wfMemcKey( 'moodbar_feedback', 'type_stats', 'last_day' );
 78+ $moodbarStat = $wgMemc->get( $key );
 79+
 80+ if ( $moodbarStat === false ) {
 81+ $dbr = wfGetDB( DB_SLAVE );
 82+ $res = $dbr->select( array( 'moodbar_feedback' ),
 83+ array( 'mbf_type', 'COUNT(*) AS number' ),
 84+ array( 'mbf_hidden_state' => 0, 'mbf_timestamp > ' . $dbr->addQuotes( wfTimestamp( TS_MW, $timestamp ) ) ),
 85+ __METHOD__,
 86+ array( 'GROUP BY' => 'mbf_type' )
 87+ );
 88+
 89+ $moodbarStat = array('happy' => 0, 'sad' => 0, 'confused' => 0);
 90+
 91+ foreach ( $res as $row ) {
 92+ $moodbarStat[$row->mbf_type] = $row->number;
 93+ }
 94+
 95+ // Cache the results in cache for 1 hour
 96+ $wgMemc->set( $key, $moodbarStat, 60 * 60 );
 97+ }
 98+
 99+ return $moodbarStat;
 100+
 101+ }
 102+
 103+ /**
67104 * Build the filter form. The state of each form element is preserved
68105 * using data in $wgRequest.
69106 * @param $filterType string Value to pass in the <form>'s data-filtertype attribute
@@ -92,7 +129,13 @@
93130 array( 'id' => 'fbd-filters-username', 'class' => 'fbd-filters-input' ) );
94131 $filterType = htmlspecialchars( $filterType );
95132
 133+ $moodbarStat = $this->getMoodBarTypeStats();
 134+ $moodbarStatMsg = wfMessage( 'moodbar-type-stats' )->params( $moodbarStat['happy'], $moodbarStat['sad'], $moodbarStat['confused'] )->escaped();
 135+
96136 return <<<HTML
 137+ <div id="fbd-description">
 138+ <div id="fbd-stats">$moodbarStatMsg</div>
 139+ </div>
97140 <div id="fbd-filters">
98141 <form action="$actionURL" data-filtertype="$filterType">
99142 <h3 id="fbd-filters-title">$filtersMsg</h3>
Index: trunk/extensions/MoodBar/ApiMoodBarSetUserEmail.php
@@ -0,0 +1,123 @@
 2+<?php
 3+
 4+
 5+class ApiMoodBarSetUserEmail extends ApiBase {
 6+
 7+ public function execute() {
 8+ global $wgUser, $wgAuth;
 9+
 10+ if ( $wgUser->isAnon() ) {
 11+ $this->dieUsage( "You don't have permission to do that", 'permission-denied' );
 12+ }
 13+
 14+ $params = $this->extractRequestParams();
 15+
 16+ $error = false;
 17+
 18+ switch ( $params['mbaction']) {
 19+
 20+ case 'setemail':
 21+ if ( !$wgAuth->allowPropChange( 'emailaddress' ) ) {
 22+ $error = wfMsgExt( 'cannotchangeemail', 'parseinline' );
 23+ }
 24+ else {
 25+ //only set email if user does not have email on profile yet
 26+ if ( !$wgUser->getEmail() ) {
 27+
 28+ if ( !isset( $params['email'] ) || !Sanitizer::validateEmail( $params['email'] ) ) {
 29+ $error = wfMsgExt( 'invalidemailaddress', 'parseinline' ) ;
 30+ }
 31+ else {
 32+ list( $status, $info ) = Preferences::trySetUserEmail( $wgUser, $params['email'] );
 33+
 34+ // Status Object
 35+ if ( $status !== true ) {
 36+ $error = $status->getWikiText( $info );
 37+ }
 38+ else {
 39+ $wgUser->saveSettings();
 40+ }
 41+ }
 42+
 43+ }
 44+ }
 45+ break;
 46+
 47+ case 'resendverification':
 48+ //only sends the email if the email has not been verified
 49+ if ( $wgUser->getEmailAuthenticationTimestamp() === null ) {
 50+ $status = $wgUser->sendConfirmationMail( 'set' );
 51+ if ( !$status->isGood() ) {
 52+ $error = $status->getWikiText( 'mailerror' );
 53+ }
 54+ }
 55+ break;
 56+
 57+ default:
 58+ throw new MWApiMoodBarSetUserEmailInvalidActionException( "Action {$params['mbaction']} not implemented" );
 59+ break;
 60+
 61+ }
 62+
 63+ if ( $error === false ) {
 64+ $result = array( 'result' => 'success' );
 65+ } else {
 66+ $result = array( 'result' => 'error', 'error' => $error );
 67+ }
 68+
 69+ $this->getResult()->addValue( null, $this->getModuleName(), $result );
 70+ }
 71+
 72+ public function needsToken() {
 73+ return true;
 74+ }
 75+
 76+ public function getTokenSalt() {
 77+ return '';
 78+ }
 79+
 80+ public function getAllowedParams() {
 81+ return array(
 82+ 'mbaction' => array(
 83+ ApiBase::PARAM_REQUIRED => true,
 84+ ApiBase::PARAM_TYPE => array(
 85+ 'setemail',
 86+ 'resendverification',
 87+ ),
 88+ ),
 89+
 90+ 'email' => array(
 91+ ApiBase::PARAM_TYPE => 'string'
 92+ ),
 93+
 94+ 'token' => array(
 95+ ApiBase::PARAM_REQUIRED => true,
 96+ ),
 97+ );
 98+ }
 99+
 100+ public function mustBePosted() {
 101+ return true;
 102+ }
 103+
 104+ public function isWriteMode() {
 105+ return true;
 106+ }
 107+
 108+ public function getVersion() {
 109+ return __CLASS__ . ': $Id: ApiMoodBarSetUserEmail.php 103224 2011-11-15 21:24:44Z bsitu $';
 110+ }
 111+
 112+ public function getParamDescription() {
 113+ return array(
 114+ 'mbaction' => 'The action to take',
 115+ 'email' => 'the email which a user sets or resends verification to'
 116+ );
 117+ }
 118+
 119+ public function getDescription() {
 120+ return 'Sets the profile email for a user or resends the verification email to a user';
 121+ }
 122+}
 123+
 124+class MWApiMoodBarSetUserEmailInvalidActionException extends MWException {};
Property changes on: trunk/extensions/MoodBar/ApiMoodBarSetUserEmail.php
___________________________________________________________________
Added: svn:eol-style
1125 + native
Index: trunk/extensions/MoodBar/MoodBar.i18n.php
@@ -119,10 +119,12 @@
120120 'moodbar-invalid-item' => 'The system was unable to find the correct feedback item.',
121121 'moodbar-feedback-action-error' => 'An error occurred when trying to perform this action.',
122122 'moodbar-feedback-response-summary' => '[[$1|$2]] [[$3|responded]] to this comment $4 ago',
 123+ 'moodbar-feedback-edit-summary' => 'Response to [[Special:FeedbackDashboard/$1|user feedback]]: $2',
123124 // Mood types
124125 'moodbar-type-happy' => '{{GENDER:$1|Happy}}',
125126 'moodbar-type-sad' => '{{GENDER:$1|Sad}}',
126127 'moodbar-type-confused' => '{{GENDER:$1|Confused}}',
 128+ 'moodbar-type-stats' => 'Moodbar feedback in the last 24 hours, Happy: $1, Sad: $2, Confused: $3',
127129 // User types
128130 'moodbar-user-anonymized' => 'Anonymized',
129131 'moodbar-user-ip' => 'IP address',
@@ -244,9 +246,11 @@
245247 'moodbar-action-reason' => 'Text for Admin action reason',
246248 'moodbar-action-reason-required' => 'Text explaining admin action reason is required',
247249 'moodbar-feedback-response-summary' => 'Text providing a summary of a user response, $1 is user page, $2 is user name, $3 is user talk page, $4 is time',
 250+ 'moodbar-feedback-edit-summary' => 'Auto generated Edit summary for feedback response, $1 is the feedback id and $2 is the response text',
248251 'moodbar-type-happy' => '$1 is the username that can be used for GENDER. Message is used on Special:FeedbackDashboard.',
249252 'moodbar-type-sad' => '$1 is the username that can be used for GENDER. Message is used on Special:FeedbackDashboard.',
250253 'moodbar-type-confused' => '$1 is the username that can be used for GENDER. Message is used on Special:FeedbackDashboard.',
 254+ 'moodbar-type-stats' => 'The stats for Moodbar feedback in the last 24 hours, $1 is the number of Happy, $2 is the number of Sad, $3 is the number of Confused',
251255 'moodbar-user-ip' => '{{Identical|IP Address}}',
252256 'moodbar-response-terms' => 'Text of the user license agreement. Parameters:
253257 * $1 {{msg-mw|moodbar-response-link}}',
Index: trunk/extensions/MoodBar/ApiFeedbackDashboardResponse.php
@@ -32,19 +32,24 @@
3333 if ( $commenter !== null && $commenter->isAnon() == false ) {
3434 $talkPage = $commenter->getTalkPage();
3535
 36+ $response = Parser::cleanSigInSig($params['response']);
 37+
3638 $feedback_link = wfMessage('moodbar-feedback-response-title')->inContentLanguage()->
3739 params( SpecialPage::getTitleFor( 'FeedbackDashboard', $item->getProperty('feedback') )->
3840 getPrefixedText() )->escaped();
3941
 42+ $summary = wfMessage('moodbar-feedback-edit-summary')->inContentLanguage()->
 43+ rawParams( $item->getProperty('feedback'), $response)->escaped();
 44+
4045 $api = new ApiMain( new FauxRequest( array(
4146 'action' => 'edit',
4247 'title' => $talkPage->getFullText(),
4348 'appendtext' => ( $talkPage->exists() ? "\n\n" : '' ) .
4449 $feedback_link . "\n" .
4550 '<span id="feedback-dashboard-response-' . $item->getProperty('id') . '"></span>' . "\n\n" .
46 - Parser::cleanSigInSig($params['response']) . "\n\n~~~~",
 51+ $response . "\n\n~~~~",
4752 'token' => $params['token'],
48 - 'summary' => '',
 53+ 'summary' => $summary,
4954 'notminor' => true,
5055 ), true, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
5156
Index: trunk/extensions/MoodBar/MoodBar.php
@@ -27,6 +27,8 @@
2828 $wgAPIModules['feedbackdashboard'] = 'ApiFeedbackDashboard';
2929 $wgAutoloadClasses['ApiFeedbackDashboardResponse'] = dirname(__FILE__).'/ApiFeedbackDashboardResponse.php';
3030 $wgAPIModules['feedbackdashboardresponse'] = 'ApiFeedbackDashboardResponse';
 31+$wgAutoloadClasses['ApiMoodBarSetUserEmail'] = dirname(__FILE__).'/ApiMoodBarSetUserEmail.php';
 32+$wgAPIModules['moodbarsetuseremail'] = 'ApiMoodBarSetUserEmail';
3133
3234 // Hooks
3335 $wgAutoloadClasses['MoodBarHooks'] = dirname(__FILE__).'/MoodBar.hooks.php';

Follow-up revisions

RevisionCommit summaryAuthorDate
r105635Send out email verification only if the user has email and the email has not ...bsitu01:40, 9 December 2011
r106155followup to -r105385 - Change text copy for moodbar type statsbsitu01:26, 14 December 2011

Status & tagging log