r88968 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88967‎ | r88968 | r88969 >
Date:11:57, 27 May 2011
Author:janpaul123
Status:ok
Tags:
Comment:
Fixed logging:
* E-mail notifications are logged correctly now
* Errors are displayed correctly
* Raw message and not the final wikitext are logged. This is because the final wikitext is not interesting, the actual message that was typed is much more useful as we can do data mining on that.
Modified paths:
  • /trunk/extensions/WikiLove/WikiLove.api.php (modified) (history)
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js (modified) (history)
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/WikiLove.api.php
@@ -16,7 +16,7 @@
1717 }
1818
1919 if ( $wgWikiLoveLogging ) {
20 - $this->saveInDb( $talk, $params['subject'], $params['text'], $params['type'], isset( $params['email'] ) ? 1 : 0 );
 20+ $this->saveInDb( $talk, $params['subject'], $params['message'], $params['type'], isset( $params['email'] ) ? 1 : 0 );
2121 }
2222
2323 $api = new ApiMain( new FauxRequest( array(
@@ -30,7 +30,7 @@
3131 ), false, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
3232
3333 if ( isset( $params['email'] ) ) {
34 - $this->emailUser( $talk, $params['subject'], $params['email'] );
 34+ $this->emailUser( $talk, $params['subject'], $params['email'], $params['token'] );
3535 }
3636
3737 $api->execute();
@@ -46,11 +46,12 @@
4747 /**
4848 * @param $talk Title
4949 * @param $subject
50 - * @param $text
 50+ * @param $message
5151 * @param $type
 52+ * @param $email
5253 * @return void
5354 */
54 - private function saveInDb( $talk, $subject, $text, $type, $email ) {
 55+ private function saveInDb( $talk, $subject, $message, $type, $email ) {
5556 global $wgUser;
5657 $dbw = wfGetDB( DB_MASTER );
5758 $values = array(
@@ -59,7 +60,7 @@
6061 'wll_receiver' => User::newFromName( $talk->getSubjectPage()->getBaseText() )->getId(),
6162 'wll_type' => $type,
6263 'wll_subject' => $subject,
63 - 'wll_message' => $text,
 64+ 'wll_message' => $message,
6465 'wll_email' => $email,
6566 );
6667 try{
@@ -69,12 +70,14 @@
7071 }
7172 }
7273
73 - private function emailUser( $talk, $subject, $text ) {
 74+ private function emailUser( $talk, $subject, $text, $token ) {
 75+ global $wgRequest;
7476 $api = new ApiMain( new FauxRequest( array(
7577 'action' => 'emailuser',
7678 'target' => User::newFromName( $talk->getSubjectPage()->getBaseText() )->getName(),
7779 'subject' => $subject,
7880 'text' => $text,
 81+ 'token' => $token,
7982 ), false, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
8083 try{
8184 $api->execute();
@@ -93,6 +96,10 @@
9497 ApiBase::PARAM_TYPE => 'string',
9598 ApiBase::PARAM_REQUIRED => true,
9699 ),
 100+ 'message' => array(
 101+ ApiBase::PARAM_TYPE => 'string',
 102+ ApiBase::PARAM_REQUIRED => true,
 103+ ),
97104 'token' => array(
98105 ApiBase::PARAM_TYPE => 'string',
99106 ApiBase::PARAM_REQUIRED => true,
@@ -114,6 +121,7 @@
115122 return array(
116123 'title' => 'Title of the user or user talk page to send WikiLove to',
117124 'text' => 'Raw wikitext to add in the new section',
 125+ 'message' => 'Actual message the user has entered, for logging purposes',
118126 'token' => 'Edit token. You can get one of these through prop=info',
119127 'subject' => 'Subject header of the new section',
120128 'type' => array( 'Type of WikiLove (for statistics); this corresponds with a type',
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js
@@ -26,7 +26,7 @@
2727 header: 'A barnstar for you!', // header that appears at the top of the talk page post (optional)
2828 title: 'The Original Barnstar', // title that appears inside the award box (optional)
2929 image: 'Original Barnstar Hires.png', // image for the award
30 - mail: 'Hello $7!\n\nI just awarded you a barnstar.' // message to use in email notification; $7 is replaced by the recipient's username
 30+ email: 'Hello $7!\n\nI just awarded you a barnstar.' // message to use in eemail notification; $7 is replaced by the recipient's username
3131 },
3232 'admins': {
3333 fields: [ 'notify' ],
@@ -35,7 +35,7 @@
3636 header: 'A barnstar for you!',
3737 title: 'The Admin\'s Barnstar',
3838 image: 'Administrator Barnstar Hires.png',
39 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 39+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
4040 },
4141 'antivandalism': {
4242 fields: [ 'notify' ],
@@ -44,7 +44,7 @@
4545 header: 'A barnstar for you!',
4646 title: 'The Anti-Vandalism Barnstar',
4747 image: 'Barnstar of Reversion Hires.png',
48 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 48+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
4949 },
5050 'diligence': {
5151 fields: [ 'notify' ],
@@ -53,7 +53,7 @@
5454 header: 'A barnstar for you!',
5555 title: 'The Barnstar of Diligence',
5656 image: 'Barnstar of Diligence Hires.png',
57 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 57+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
5858 },
5959 'diplomacy': {
6060 fields: [ 'notify' ],
@@ -62,7 +62,7 @@
6363 header: 'A barnstar for you!',
6464 title: 'The Barnstar of Diplomacy',
6565 image: 'Peace Barnstar Hires.png',
66 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 66+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
6767 },
6868 'goodhumor': {
6969 fields: [ 'notify' ],
@@ -71,7 +71,7 @@
7272 header: 'A barnstar for you!',
7373 title: 'The Barnstar of Good Humor',
7474 image: 'Barnstar of Reversion Hires.png',
75 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 75+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
7676 },
7777 'brilliant': {
7878 fields: [ 'notify' ],
@@ -80,7 +80,7 @@
8181 header: 'A barnstar for you!',
8282 title: 'The Brilliant Idea Barnstar',
8383 image: 'Brilliant Idea Barnstar Hires.png',
84 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 84+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
8585 },
8686 'citation': {
8787 fields: [ 'notify' ],
@@ -89,7 +89,7 @@
9090 header: 'A barnstar for you!',
9191 title: 'The Citation Barnstar',
9292 image: 'Citation Barnstar Hires.png',
93 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 93+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
9494 },
9595 'civility': {
9696 fields: [ 'notify' ],
@@ -98,7 +98,7 @@
9999 header: 'A barnstar for you!',
100100 title: 'The Civility Barnstar',
101101 image: 'Civility Barnstar Hires.png',
102 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 102+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
103103 },
104104 'copyeditor': {
105105 fields: [ 'notify' ],
@@ -107,7 +107,7 @@
108108 header: 'A barnstar for you!',
109109 title: 'The Copyeditor\'s Barnstar',
110110 image: 'Copyeditor Barnstar Hires.png',
111 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 111+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
112112 },
113113 'defender': {
114114 fields: [ 'notify' ],
@@ -116,7 +116,7 @@
117117 header: 'A barnstar for you!',
118118 title: 'The Defender of the Wiki Barnstar',
119119 image: 'WikiDefender Barnstar Hires.png',
120 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 120+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
121121 },
122122 'editors': {
123123 fields: [ 'notify' ],
@@ -125,7 +125,7 @@
126126 header: 'A barnstar for you!',
127127 title: 'The Editor\'s Barnstar',
128128 image: 'Editors Barnstar Hires.png',
129 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 129+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
130130 },
131131 'designers': {
132132 fields: [ 'notify' ],
@@ -134,7 +134,7 @@
135135 header: 'A barnstar for you!',
136136 title: 'The Graphic Designer\'s Barnstar',
137137 image: 'Rosetta Barnstar Hires.png',
138 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 138+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
139139 },
140140 'half': {
141141 fields: [ 'notify' ],
@@ -143,7 +143,7 @@
144144 header: 'A barnstar for you!',
145145 title: 'The Half Barnstar',
146146 image: 'Halfstar Hires.png',
147 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 147+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
148148 },
149149 'minor': {
150150 fields: [ 'notify' ],
@@ -152,7 +152,7 @@
153153 header: 'A barnstar for you!',
154154 title: 'The Minor barnstar',
155155 image: 'Minor Barnstar Hires.png',
156 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 156+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
157157 },
158158 'antispam': {
159159 fields: [ 'notify' ],
@@ -161,7 +161,7 @@
162162 header: 'A barnstar for you!',
163163 title: 'The No Spam Barnstar',
164164 image: 'No Spam Barnstar Hires.png',
165 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 165+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
166166 },
167167 'photographers': {
168168 fields: [ 'notify' ],
@@ -170,7 +170,7 @@
171171 header: 'A barnstar for you!',
172172 title: 'The Photographer\'s Barnstar',
173173 image: 'Camera Barnstar Hires.png',
174 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 174+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
175175 },
176176 'kindness': {
177177 fields: [ 'notify' ],
@@ -179,7 +179,7 @@
180180 header: 'A barnstar for you!',
181181 title: 'The Random Acts of Kindness barnstar',
182182 image: 'Kindness Barnstar Hires.png',
183 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 183+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
184184 },
185185 'reallife': {
186186 fields: [ 'notify' ],
@@ -188,7 +188,7 @@
189189 header: 'A barnstar for you!',
190190 title: 'The Real Life Barnstar',
191191 image: 'Real Life Barnstar.jpg',
192 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 192+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
193193 },
194194 'resilient': {
195195 fields: [ 'notify' ],
@@ -197,7 +197,7 @@
198198 header: 'A barnstar for you!',
199199 title: 'The Resilient Barnstar',
200200 image: 'Resilient Barnstar Hires.png',
201 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 201+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
202202 },
203203 'rosetta': {
204204 fields: [ 'notify' ],
@@ -206,7 +206,7 @@
207207 header: 'A barnstar for you!',
208208 title: 'The Rosetta Barnstar',
209209 image: 'Rosetta Barnstar Hires.png',
210 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 210+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
211211 },
212212 'special': {
213213 fields: [ 'notify' ],
@@ -215,7 +215,7 @@
216216 header: 'A barnstar for you!',
217217 title: 'The Special Barnstar',
218218 image: 'Special Barnstar Hires.png',
219 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 219+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
220220 },
221221 'surreal': {
222222 fields: [ 'notify' ],
@@ -224,7 +224,7 @@
225225 header: 'A barnstar for you!',
226226 title: 'The Surreal Barnstar',
227227 image: 'Surreal Barnstar Hires.png',
228 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 228+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
229229 },
230230 'teamwork': {
231231 fields: [ 'notify' ],
@@ -233,7 +233,7 @@
234234 header: 'A barnstar for you!',
235235 title: 'The Teamwork Barnstar',
236236 image: 'Team Barnstar Hires.png',
237 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 237+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
238238 },
239239 'technical': {
240240 fields: [ 'notify' ],
@@ -242,7 +242,7 @@
243243 header: 'A barnstar for you!',
244244 title: 'The Technical Barnstar',
245245 image: 'Vitruvian Barnstar Hires.png',
246 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 246+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
247247 },
248248 'tireless': {
249249 fields: [ 'notify' ],
@@ -251,7 +251,7 @@
252252 header: 'A barnstar for you!',
253253 title: 'The Tireless Contributor Barnstar',
254254 image: 'Tireless Contributor Barnstar Hires.gif',
255 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 255+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
256256 },
257257 'writers': {
258258 fields: [ 'notify' ],
@@ -260,7 +260,7 @@
261261 header: 'A barnstar for you!',
262262 title: 'The Writer\'s Barnstar',
263263 image: 'Writers Barnstar Hires.png',
264 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 264+ email: 'Hello $7!\n\nI just awarded you a barnstar.'
265265 }
266266 },
267267 icon: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/extensions/WikiLove/modules/ext.wikiLove/images/icons/wikilove-icon-barnstar.png' // icon for left-side menu
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
@@ -240,9 +240,10 @@
241241 $.wikiLove.showGallery(); // build gallery from array of images
242242 } else {
243243 // gallery is a category
244 - $( '#mw-wikilove-gallery-label' ).show();
245 - $( '#mw-wikilove-gallery' ).show();
246 - $.wikiLove.makeGallery(); // build gallery from category
 244+ // not supported right now
 245+ $( '#mw-wikilove-gallery-label' ).hide();
 246+ $( '#mw-wikilove-gallery' ).hide();
 247+ //$.wikiLove.makeGallery(); // build gallery from category
247248 }
248249 }
249250 else {
@@ -294,23 +295,24 @@
295296 $.wikiLove.showError( 'wikilove-err-sig' ); return false;
296297 }
297298
298 - var msg = $.wikiLove.prepareMsg(
 299+ var text = $.wikiLove.prepareMsg(
299300 $.wikiLove.currentTypeOrSubtype.text || $.wikiLove.options.defaultText,
300301 $.wikiLove.currentTypeOrSubtype.imageSize,
301302 $.wikiLove.currentTypeOrSubtype.backgroundColor,
302303 $.wikiLove.currentTypeOrSubtype.borderColor
303304 );
304305
305 - $.wikiLove.doPreview( '==' + $( '#mw-wikilove-header' ).val() + "==\n" + msg );
 306+ $.wikiLove.doPreview( '==' + $( '#mw-wikilove-header' ).val() + "==\n" + text );
306307 $.wikiLove.previewData = {
307308 'header': $( '#mw-wikilove-header' ).val(),
308 - 'msg': msg,
 309+ 'text': text,
 310+ 'message': $( '#mw-wikilove-message' ).val(),
309311 'type': $.wikiLove.currentTypeId
310312 + ($.wikiLove.currentSubtypeId !== null ? '-' + $.wikiLove.currentSubtypeId : '')
311313 };
312314
313315 if ( $( '#mw-wikilove-notify-checkbox:checked' ).val() && $.wikiLove.emailable ) {
314 - $.wikiLove.previewData.mail = $.wikiLove.prepareMsg( $.wikiLove.currentTypeOrSubtype.mail );
 316+ $.wikiLove.previewData.email = $.wikiLove.prepareMsg( $.wikiLove.currentTypeOrSubtype.email );
315317 }
316318 },
317319
@@ -385,14 +387,14 @@
386388 */
387389 submitSend: function( e ) {
388390 e.preventDefault();
389 - $.wikiLove.doSend( $.wikiLove.previewData.header, $.wikiLove.previewData.msg,
390 - $.wikiLove.previewData.type, $.wikiLove.previewData.notify );
 391+ $.wikiLove.doSend( $.wikiLove.previewData.header, $.wikiLove.previewData.text,
 392+ $.wikiLove.previewData.message, $.wikiLove.previewData.type, $.wikiLove.previewData.email );
391393 },
392394
393395 /*
394396 * Fires the final AJAX request and then redirects to the talk page where the content is added.
395397 */
396 - doSend: function( subject, wikitext, type, mail ) {
 398+ doSend: function( subject, wikitext, message, type, email ) {
397399 $( '#mw-wikilove-send-spinner' ).fadeIn( 200 );
398400
399401 var sendData = {
@@ -401,12 +403,13 @@
402404 'title': mw.config.get( 'wgPageName' ),
403405 'type': type,
404406 'text': wikitext,
 407+ 'message': message,
405408 'subject': subject,
406409 'token': mw.user.tokens.get( 'editToken' )
407410 };
408411
409 - if ( mail ) {
410 - sendData.email = mail;
 412+ if ( email ) {
 413+ sendData.email = email;
411414 }
412415
413416 $.ajax({
@@ -418,7 +421,7 @@
419422 $( '#mw-wikilove-send-spinner' ).fadeOut( 200 );
420423
421424 if ( typeof data.error !== 'undefined' ) {
422 - $( '#mw-wikilove-preview' ).append( '<div class="wlError">' + mw.html.escape( data.error.info ) + '<div>' );
 425+ $( '#mw-wikilove-preview' ).append( '<div class="mw-wikilove-error">' + mw.html.escape( data.error.info ) + '<div>' );
423426 return;
424427 }
425428

Status & tagging log