Index: trunk/extensions/MoodBar/sql/MoodBar.sql |
— | — | @@ -28,4 +28,3 @@ |
29 | 29 | -- A little overboard with the indexes perhaps, but we want to be able to dice this data a lot! |
30 | 30 | CREATE INDEX /*i*/type_timestamp ON /*_*/moodbar_feedback (mbf_type,mbf_timestamp); |
31 | 31 | CREATE INDEX /*i*/title_type ON /*_*/moodbar_feedback (mbf_namespace,mbf_title,mbf_type,mbf_timestamp); |
32 | | - |
Index: trunk/extensions/MoodBar/ApiMoodBar.php |
— | — | @@ -88,6 +88,11 @@ |
89 | 89 | 'useragent' => 'The User-Agent header of the browser', |
90 | 90 | 'system' => 'The operating system being used', |
91 | 91 | 'locale' => 'The locale in use', |
| 92 | + 'token' => 'An edit token', |
92 | 93 | ); |
93 | 94 | } |
| 95 | + |
| 96 | + public function getDescription() { |
| 97 | + return 'Allows users to submit feedback about their experiences on the site'; |
| 98 | + } |
94 | 99 | } |
Index: trunk/extensions/MoodBar/MoodBar.i18n.php |
— | — | @@ -47,6 +47,16 @@ |
48 | 48 | 'moodbar-header-useragent' => 'User-Agent', |
49 | 49 | 'moodbar-header-comment' => 'Comments', |
50 | 50 | 'moodbar-header-user-editcount' => 'User edit count', |
| 51 | + 'moodbar-header-namespace' => 'Namespace', |
| 52 | + 'moodbar-header-own-talk' => 'Own talk page', |
| 53 | + // Mood types |
| 54 | + 'moodbar-type-happy' => 'Happy', |
| 55 | + 'moodbar-type-sad' => 'Sad', |
| 56 | + 'moodbar-type-confused' => 'Confused', |
| 57 | + // User types |
| 58 | + 'moodbar-user-anonymized' => 'Anonymized', |
| 59 | + 'moodbar-user-ip' => 'IP Address', |
| 60 | + 'moodbar-user-user' => 'Registered user', |
51 | 61 | ); |
52 | 62 | |
53 | 63 | /** Message documentation (Message documentation) |
Index: trunk/extensions/MoodBar/MoodBar.php |
— | — | @@ -85,3 +85,8 @@ |
86 | 86 | 'jquery.client', |
87 | 87 | ), |
88 | 88 | ); |
| 89 | + |
| 90 | + |
| 91 | +/** Configuration **/ |
| 92 | +/** The registration time after which users will be shown the MoodBar **/ |
| 93 | +$wgMoodBarCutoffTime = null; |
Index: trunk/extensions/MoodBar/SpecialMoodBar.php |
— | — | @@ -5,7 +5,9 @@ |
6 | 6 | 'id', |
7 | 7 | 'timestamp', |
8 | 8 | 'type', |
| 9 | + 'namespace', |
9 | 10 | 'page', |
| 11 | + 'own-talk', |
10 | 12 | 'usertype', |
11 | 13 | 'user', |
12 | 14 | 'user-editcount', |
— | — | @@ -84,31 +86,7 @@ |
85 | 87 | $outData = array(); |
86 | 88 | |
87 | 89 | foreach( $this->fields as $field ) { |
88 | | - switch( $field ) { |
89 | | - case 'usertype': |
90 | | - $user = $data->getProperty('user'); |
91 | | - if ( $data->getProperty('anonymize') ) { |
92 | | - $outData[] = 'anonymized'; |
93 | | - } else if ( $user->isAnon() ) { |
94 | | - $outData[] = 'ip'; |
95 | | - } else { |
96 | | - $outData[] = 'user'; |
97 | | - } |
98 | | - break; |
99 | | - case 'user': |
100 | | - $user = $data->getProperty('user'); |
101 | | - if ( $data->getProperty('anonymize') ) { |
102 | | - $outData[] = ''; |
103 | | - } else { |
104 | | - $outData[] = $user->getName(); |
105 | | - } |
106 | | - break; |
107 | | - case 'page': |
108 | | - $outData[] = $data->getProperty('page')->getPrefixedText(); |
109 | | - break; |
110 | | - default: |
111 | | - $outData[] = $data->getProperty($field); |
112 | | - } |
| 90 | + $outData[] = $this->getInternalRepresentation( $data, $field ); |
113 | 91 | } |
114 | 92 | |
115 | 93 | fputcsv( $fh, $outData ); |
— | — | @@ -141,41 +119,7 @@ |
142 | 120 | $outData = null; |
143 | 121 | |
144 | 122 | foreach( $this->fields as $field ) { |
145 | | - switch( $field ) { |
146 | | - case 'usertype': |
147 | | - $user = $data->getProperty('user'); |
148 | | - if ( $data->getProperty('anonymize') ) { |
149 | | - $outData = 'anonymized'; |
150 | | - } else if ( $user->isAnon() ) { |
151 | | - $outData = 'ip'; |
152 | | - } else { |
153 | | - $outData = 'user'; |
154 | | - } |
155 | | - break; |
156 | | - case 'user': |
157 | | - $user = $data->getProperty('user'); |
158 | | - if ( $data->getProperty('anonymize') ) { |
159 | | - $outData = ''; |
160 | | - } else { |
161 | | - $outData = $user->getName(); |
162 | | - } |
163 | | - break; |
164 | | - case 'page': |
165 | | - $title = $data->getProperty('page'); |
166 | | - |
167 | | - global $wgUser; |
168 | | - $linker = $wgUser->getSkin(); |
169 | | - $outData = $linker->link( $title ); |
170 | | - break; |
171 | | - case 'timestamp': |
172 | | - global $wgLang; |
173 | | - $outData = $wgLang->timeanddate( $data->getProperty('timestamp') ); |
174 | | - break; |
175 | | - default: |
176 | | - $outData = $data->getProperty($field); |
177 | | - break; |
178 | | - } |
179 | | - |
| 123 | + $outData = $this->getHTMLRepresentation( $data, $field ); |
180 | 124 | $out .= Xml::tags( 'td', null, $outData ); |
181 | 125 | } |
182 | 126 | |
— | — | @@ -183,5 +127,89 @@ |
184 | 128 | |
185 | 129 | return $out; |
186 | 130 | } |
| 131 | + |
| 132 | + /** |
| 133 | + * Gets the viewer's representation of $field from $data. |
| 134 | + * @param $data MBFeedbackItem to retrieve the data from. |
| 135 | + * @param $field String name of the field to fill. Valid values in $this->fields |
| 136 | + * @return String HTML for putting in the table. |
| 137 | + */ |
| 138 | + public function getHTMLRepresentation( $data, $field ) { |
| 139 | + switch( $field ) { |
| 140 | + case 'page': |
| 141 | + $title = $data->getProperty('page'); |
| 142 | + |
| 143 | + global $wgUser; |
| 144 | + $linker = $wgUser->getSkin(); |
| 145 | + $outData = $linker->link( $title ); |
| 146 | + break; |
| 147 | + case 'timestamp': |
| 148 | + global $wgLang; |
| 149 | + $outData = $wgLang->timeanddate( $data->getProperty('timestamp') ); |
| 150 | + $outData = htmlspecialchars($outData); |
| 151 | + break; |
| 152 | + case 'type': |
| 153 | + $internal = $this->getInternalRepresentation( $data, $field ); |
| 154 | + $outData = wfMessage("moodbar-type-$internal")->parse(); |
| 155 | + break; |
| 156 | + case 'usertype': |
| 157 | + $internal = $this->getInternalRepresentation( $data, $field ); |
| 158 | + $outData = wfMessage("moodbar-user-$internal")->parse(); |
| 159 | + break; |
| 160 | + default: |
| 161 | + $outData = $this->getInternalRepresentation($data, $field); |
| 162 | + $outData = htmlspecialchars( $outData ); |
| 163 | + break; |
| 164 | + } |
| 165 | + |
| 166 | + return $outData; |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * Gets an internal representation of $field from $data. |
| 171 | + * @param $data MBFeedbackItem to retrieve the data from. |
| 172 | + * @param $field String name of the field to fill. Valid values in $this->fields |
| 173 | + * @return String value appropriate for putting in CSV |
| 174 | + */ |
| 175 | + public function getInternalRepresentation( $data, $field ) { |
| 176 | + $outData = null; |
| 177 | + switch( $field ) { |
| 178 | + case 'namespace': |
| 179 | + $page = $data->getProperty('page'); |
| 180 | + $outData = $page->getNsText(); |
| 181 | + break; |
| 182 | + case 'own-talk': |
| 183 | + $page = $data->getProperty('page'); |
| 184 | + $user = $data->getProperty('user'); |
| 185 | + $userTalk = $user->getUserPage()->getTalkPage(); |
| 186 | + $outData = $page->equals( $userTalk ); |
| 187 | + break; |
| 188 | + case 'usertype': |
| 189 | + $user = $data->getProperty('user'); |
| 190 | + if ( $data->getProperty('anonymize') ) { |
| 191 | + $outData = 'anonymized'; |
| 192 | + } else if ( $user->isAnon() ) { |
| 193 | + $outData = 'ip'; |
| 194 | + } else { |
| 195 | + $outData = 'user'; |
| 196 | + } |
| 197 | + break; |
| 198 | + case 'user': |
| 199 | + $user = $data->getProperty('user'); |
| 200 | + if ( $data->getProperty('anonymize') ) { |
| 201 | + $outData = ''; |
| 202 | + } else { |
| 203 | + $outData = $user->getName(); |
| 204 | + } |
| 205 | + break; |
| 206 | + case 'page': |
| 207 | + $outData = $data->getProperty('page')->getPrefixedText(); |
| 208 | + break; |
| 209 | + default: |
| 210 | + $outData = $data->getProperty($field); |
| 211 | + } |
| 212 | + |
| 213 | + return $outData; |
| 214 | + } |
187 | 215 | } |
188 | 216 | |
Index: trunk/extensions/MoodBar/MoodBar.hooks.php |
— | — | @@ -16,19 +16,44 @@ |
17 | 17 | * Determines whether or not we should show the MoodBar. |
18 | 18 | */ |
19 | 19 | public static function shouldShowMoodbar( &$output, &$skin ) { |
20 | | - if ( |
21 | | - // Front-end appends to header elements, which have different |
22 | | - // locations and IDs in every skin. |
23 | | - // Untill there is some kind of central registry of element-ids |
24 | | - // that skins implement, or a fixed name for each of them, just |
25 | | - // show it in Vector for now. |
26 | | - $skin->getSkinName() == 'vector' && |
27 | | - |
28 | | - // Only for logged-in users |
29 | | - $output->getUser()->isLoggedIn() |
30 | | - ) { |
31 | | - return true; |
| 20 | + // Front-end appends to header elements, which have different |
| 21 | + // locations and IDs in every skin. |
| 22 | + // Untill there is some kind of central registry of element-ids |
| 23 | + // that skins implement, or a fixed name for each of them, just |
| 24 | + // show it in Vector for now. |
| 25 | + if ( $skin->getSkinName() !== 'vector' ) { |
| 26 | + return false; |
32 | 27 | } |
| 28 | + $user = $output->getUser(); |
| 29 | + |
| 30 | + if ( $user->isAnon() ) { |
| 31 | + return false; |
| 32 | + } |
| 33 | + |
| 34 | + // Only show MoodBar for users registered after a certain time |
| 35 | + global $wgMoodBarCutoffTime; |
| 36 | + if ( $wgMoodBarCutoffTime && |
| 37 | + $user->getRegistration() < $wgMoodBarCutoffTime ) |
| 38 | + { |
| 39 | + return false; |
| 40 | + } |
| 41 | + |
| 42 | + $buckets = self::getUserBuckets( $user ); |
| 43 | + |
| 44 | + if ( in_array( 'moodbar-always', $buckets ) ) { |
| 45 | + return true; |
| 46 | + } elseif( in_array( 'no-moodbar', $buckets ) ) { |
| 47 | + return false; |
| 48 | + } elseif ( in_array( 'moodbar-on-submit', $buckets ) ) { |
| 49 | + // MoodBar is shown when a user has submitted an edit |
| 50 | + return ( $user->getEditCount() > 0 ); |
| 51 | + } elseif ( in_array( 'moodbar-on-edit', $buckets ) && |
| 52 | + class_exists('EditPageTracking') ) |
| 53 | + { |
| 54 | + // MoodBar is shown when a user has previously loaded the edit form |
| 55 | + return ((bool)EditPageTracking::getFirstEditPage($user)); |
| 56 | + } |
| 57 | + |
33 | 58 | return false; |
34 | 59 | } |
35 | 60 | |
— | — | @@ -36,8 +61,10 @@ |
37 | 62 | * ResourceLoaderGetConfigVars hook |
38 | 63 | */ |
39 | 64 | public static function resourceLoaderGetConfigVars( &$vars ) { |
| 65 | + global $wgUser; |
40 | 66 | $vars['mbConfig'] = array( |
41 | 67 | 'validTypes' => MBFeedbackItem::getValidTypes(), |
| 68 | + 'userBuckets' => MoodBarHooks::getUserBuckets( $wgUser ), |
42 | 69 | ); |
43 | 70 | return true; |
44 | 71 | } |
— | — | @@ -55,4 +82,29 @@ |
56 | 83 | |
57 | 84 | return true; |
58 | 85 | } |
| 86 | + |
| 87 | + /** |
| 88 | + * Gets the MoodBar testing bucket that a user is in. |
| 89 | + * @param $user The user to check |
| 90 | + * @return array of bucket names |
| 91 | + */ |
| 92 | + public static function getUserBuckets( $user ) { |
| 93 | + $id = $user->getID(); |
| 94 | + |
| 95 | + // 60 is divisible by 2, 3, 4, 5, 6 and 10 |
| 96 | + $bucketId = $id % 60; |
| 97 | + $buckets = array(); |
| 98 | + |
| 99 | + if ( $bucketId < 15 ) { |
| 100 | + $buckets[] = 'no-moodbar'; |
| 101 | + } elseif ( $bucketId < 30 ) { |
| 102 | + $buckets[] = 'moodbar-on-edit'; |
| 103 | + } elseif ( $bucketId < 45 ) { |
| 104 | + $buckets[] = 'moodbar-on-submit'; |
| 105 | + } elseif ( $bucektId < 60 ) { |
| 106 | + $buckets[] = 'moodbar-always'; |
| 107 | + } |
| 108 | + |
| 109 | + return $buckets; |
| 110 | + } |
59 | 111 | } |