Index: trunk/extensions/MoodBar/SpecialFeedbackDashboard.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | |
18 | 18 | public function execute( $par ) { |
19 | 19 | global $wgOut, $wgRequest; |
20 | | - |
| 20 | + |
21 | 21 | $limit = 20; |
22 | 22 | $offset = false; |
23 | 23 | $filterType = ''; |
— | — | @@ -63,6 +63,43 @@ |
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
| 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 | + /** |
67 | 104 | * Build the filter form. The state of each form element is preserved |
68 | 105 | * using data in $wgRequest. |
69 | 106 | * @param $filterType string Value to pass in the <form>'s data-filtertype attribute |
— | — | @@ -92,7 +129,13 @@ |
93 | 130 | array( 'id' => 'fbd-filters-username', 'class' => 'fbd-filters-input' ) ); |
94 | 131 | $filterType = htmlspecialchars( $filterType ); |
95 | 132 | |
| 133 | + $moodbarStat = $this->getMoodBarTypeStats(); |
| 134 | + $moodbarStatMsg = wfMessage( 'moodbar-type-stats' )->params( $moodbarStat['happy'], $moodbarStat['sad'], $moodbarStat['confused'] )->escaped(); |
| 135 | + |
96 | 136 | return <<<HTML |
| 137 | + <div id="fbd-description"> |
| 138 | + <div id="fbd-stats">$moodbarStatMsg</div> |
| 139 | + </div> |
97 | 140 | <div id="fbd-filters"> |
98 | 141 | <form action="$actionURL" data-filtertype="$filterType"> |
99 | 142 | <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 |
1 | 125 | + native |
Index: trunk/extensions/MoodBar/MoodBar.i18n.php |
— | — | @@ -119,10 +119,12 @@ |
120 | 120 | 'moodbar-invalid-item' => 'The system was unable to find the correct feedback item.', |
121 | 121 | 'moodbar-feedback-action-error' => 'An error occurred when trying to perform this action.', |
122 | 122 | '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', |
123 | 124 | // Mood types |
124 | 125 | 'moodbar-type-happy' => '{{GENDER:$1|Happy}}', |
125 | 126 | 'moodbar-type-sad' => '{{GENDER:$1|Sad}}', |
126 | 127 | 'moodbar-type-confused' => '{{GENDER:$1|Confused}}', |
| 128 | + 'moodbar-type-stats' => 'Moodbar feedback in the last 24 hours, Happy: $1, Sad: $2, Confused: $3', |
127 | 129 | // User types |
128 | 130 | 'moodbar-user-anonymized' => 'Anonymized', |
129 | 131 | 'moodbar-user-ip' => 'IP address', |
— | — | @@ -244,9 +246,11 @@ |
245 | 247 | 'moodbar-action-reason' => 'Text for Admin action reason', |
246 | 248 | 'moodbar-action-reason-required' => 'Text explaining admin action reason is required', |
247 | 249 | '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', |
248 | 251 | 'moodbar-type-happy' => '$1 is the username that can be used for GENDER. Message is used on Special:FeedbackDashboard.', |
249 | 252 | 'moodbar-type-sad' => '$1 is the username that can be used for GENDER. Message is used on Special:FeedbackDashboard.', |
250 | 253 | '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', |
251 | 255 | 'moodbar-user-ip' => '{{Identical|IP Address}}', |
252 | 256 | 'moodbar-response-terms' => 'Text of the user license agreement. Parameters: |
253 | 257 | * $1 {{msg-mw|moodbar-response-link}}', |
Index: trunk/extensions/MoodBar/ApiFeedbackDashboardResponse.php |
— | — | @@ -32,19 +32,24 @@ |
33 | 33 | if ( $commenter !== null && $commenter->isAnon() == false ) { |
34 | 34 | $talkPage = $commenter->getTalkPage(); |
35 | 35 | |
| 36 | + $response = Parser::cleanSigInSig($params['response']); |
| 37 | + |
36 | 38 | $feedback_link = wfMessage('moodbar-feedback-response-title')->inContentLanguage()-> |
37 | 39 | params( SpecialPage::getTitleFor( 'FeedbackDashboard', $item->getProperty('feedback') )-> |
38 | 40 | getPrefixedText() )->escaped(); |
39 | 41 | |
| 42 | + $summary = wfMessage('moodbar-feedback-edit-summary')->inContentLanguage()-> |
| 43 | + rawParams( $item->getProperty('feedback'), $response)->escaped(); |
| 44 | + |
40 | 45 | $api = new ApiMain( new FauxRequest( array( |
41 | 46 | 'action' => 'edit', |
42 | 47 | 'title' => $talkPage->getFullText(), |
43 | 48 | 'appendtext' => ( $talkPage->exists() ? "\n\n" : '' ) . |
44 | 49 | $feedback_link . "\n" . |
45 | 50 | '<span id="feedback-dashboard-response-' . $item->getProperty('id') . '"></span>' . "\n\n" . |
46 | | - Parser::cleanSigInSig($params['response']) . "\n\n~~~~", |
| 51 | + $response . "\n\n~~~~", |
47 | 52 | 'token' => $params['token'], |
48 | | - 'summary' => '', |
| 53 | + 'summary' => $summary, |
49 | 54 | 'notminor' => true, |
50 | 55 | ), true, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true ); |
51 | 56 | |
Index: trunk/extensions/MoodBar/MoodBar.php |
— | — | @@ -27,6 +27,8 @@ |
28 | 28 | $wgAPIModules['feedbackdashboard'] = 'ApiFeedbackDashboard'; |
29 | 29 | $wgAutoloadClasses['ApiFeedbackDashboardResponse'] = dirname(__FILE__).'/ApiFeedbackDashboardResponse.php'; |
30 | 30 | $wgAPIModules['feedbackdashboardresponse'] = 'ApiFeedbackDashboardResponse'; |
| 31 | +$wgAutoloadClasses['ApiMoodBarSetUserEmail'] = dirname(__FILE__).'/ApiMoodBarSetUserEmail.php'; |
| 32 | +$wgAPIModules['moodbarsetuseremail'] = 'ApiMoodBarSetUserEmail'; |
31 | 33 | |
32 | 34 | // Hooks |
33 | 35 | $wgAutoloadClasses['MoodBarHooks'] = dirname(__FILE__).'/MoodBar.hooks.php'; |