r110139 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110138‎ | r110139 | r110140 >
Date:16:33, 27 January 2012
Author:rsterbin
Status:ok
Tags:aft 
Comment:
Flag as abuse is now sticky:
- modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css:
- Flag as abuse link, when the comment is marked abusive, should turn
red as stated in comments
- modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js:
- Updated setBinds() to give the abuse flag its own function, which
toggles the flag based on what the user has already done
- Updated flagFeedback() to switch the feedback link back and forth
between the saved and available text, and to handle marking it as abusive
- Updated loadFeedback() to update the text of the link if the user has
already flagged the comment as abuse
- ArticleFeedbackv5.php:
- New config variable $wgArticleFeedbackv5AbusiveThreshold
- api/ApiFlagFeedbackArticleFeedbackv5.php:
- Updated to send the abuse count as well as the abusive state, and to
use $wgArticleFeedbackv5AbusiveThreshold rather than a hardcoded value
- api/ApiViewFeedbackArticleFeedbackv5.php:
- Updated renderFeedback() to set the abusive class on the link if the
count is above $wgArticleFeedbackv5AbusiveThreshold
- Also fixed whitespace
- ArticleFeedbackv5.hooks.php:
- Updated to send 'articlefeedbackv5-form-abuse' to the special page js
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.css
@@ -210,6 +210,9 @@
211211 #articleFeedbackv5-show-feedback .articleFeedbackv5-abuse-link {
212212 margin-left: 150px;
213213 }
 214+#articleFeedbackv5-show-feedback .articleFeedbackv5-abuse-link.abusive {
 215+ color: red;
 216+}
214217 #articleFeedbackv5-show-feedback .articleFeedbackv5-comment-foot {
215218 line-height: 22px;
216219 float: left;
Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -175,8 +175,21 @@
176176 } )
177177 } );
178178
179 - $.each( ['unhide', 'undelete', 'oversight', 'hide', 'abuse', 'delete', 'unoversight'], function ( index, value ) {
 179+ $( '.articleFeedbackv5-abuse-link' ).live( 'click', function( e ) {
 180+ e.preventDefault();
 181+ var $l = $( e.target );
 182+ var id = $l.parents( '.articleFeedbackv5-feedback' ).attr( 'rel' );
 183+ var activity = $.articleFeedbackv5special.getActivity( id );
 184+ if ( activity.abuse ) {
 185+ $.articleFeedbackv5special.flagFeedback( id, 'abuse', -1 );
 186+ } else {
 187+ $.articleFeedbackv5special.flagFeedback( id, 'abuse', 1 );
 188+ }
 189+ } )
 190+
 191+ $.each( ['unhide', 'undelete', 'oversight', 'hide', 'delete', 'unoversight'], function ( index, value ) {
180192 $( '.articleFeedbackv5-' + value + '-link' ).live( 'click', function( e ) {
 193+ e.preventDefault();
181194 $.articleFeedbackv5special.flagFeedback( $.articleFeedbackv5special.stripID( this, 'articleFeedbackv5-' + value + '-link-' ), value, 1 );
182195 } )
183196 } );
@@ -368,7 +381,6 @@
369382 if ( 'articlefeedbackv5-flag-feedback' in data ) {
370383 if ( 'result' in data['articlefeedbackv5-flag-feedback'] ) {
371384 if ( data['articlefeedbackv5-flag-feedback'].result == 'Success' ) {
372 - msg = 'articlefeedbackv5-' + type + '-saved';
373385 if ( 'helpful' in data['articlefeedbackv5-flag-feedback'] ) {
374386 $( '#articleFeedbackv5-helpful-votes-' + id ).text( data['articlefeedbackv5-flag-feedback'].helpful );
375387 }
@@ -379,6 +391,21 @@
380392 } else {
381393 $l.removeClass( 'helpful-active' );
382394 }
 395+ } else if ( 'abuse' == type ) {
 396+ var $l = $( '#articleFeedbackv5-abuse-link-' + id );
 397+ if ( dir > 0 ) {
 398+ $l.text( mw.msg( 'articlefeedbackv5-abuse-saved' ) );
 399+ } else {
 400+ $l.text( mw.msg( 'articlefeedbackv5-form-abuse', data['articlefeedbackv5-flag-feedback'].abuse_count ) );
 401+ }
 402+ if ( data['articlefeedbackv5-flag-feedback'].abusive ) {
 403+ $l.addClass( 'abusive' );
 404+ } else {
 405+ $l.removeClass( 'abusive' );
 406+ }
 407+ } else {
 408+ msg = 'articlefeedbackv5-' + type + '-saved';
 409+ $( '#articleFeedbackv5-' + type + '-link-' + id ).text( mw.msg( msg ) );
383410 }
384411 // Save activity
385412 if ( !( id in $.articleFeedbackv5special.activity ) ) {
@@ -391,7 +418,6 @@
392419 }
393420 }
394421 }
395 - $( '#articleFeedbackv5-' + type + '-link-' + id ).text( mw.msg( msg ) );
396422 },
397423 'error': function ( data ) {
398424 $( '#articleFeedbackv5-' + type + '-link-' + id ).text( mw.msg( 'articlefeedbackv5-error-flagging' ) );
@@ -446,6 +472,10 @@
447473 if ( activity.unhelpful ) {
448474 $( this ).find( '#articleFeedbackv5-unhelpful-link-' + id ).addClass( 'helpful-active' );
449475 }
 476+ if ( activity.abuse ) {
 477+ var $l = $( this ).find( '#articleFeedbackv5-abuse-link-' + id );
 478+ $l.text( mw.msg( 'articlefeedbackv5-abuse-saved' ) );
 479+ }
450480 }
451481 } );
452482 $( '#articleFeedbackv5-show-feedback' ).append( $newList );
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
@@ -152,6 +152,15 @@
153153 );
154154
155155 /**
 156+ * Abusive threshold
 157+ *
 158+ * After this many users flag a comment as abusive, it is marked as such.
 159+ *
 160+ * @var int
 161+ */
 162+$wgArticleFeedbackv5AbusiveThreshold = 3;
 163+
 164+/**
156165 * Temporary hack: for now, only one CTA is allowed, so set it here.
157166 *
158167 * Allowed values: '0' (just a confirm message), '1' (call to edit), '2' (learn
Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
@@ -180,7 +180,9 @@
181181 __METHOD__
182182 );
183183 }
184 - if( $record->af_abuse_count > 3 ) {
 184+ global $wgArticleFeedbackv5AbusiveThreshold;
 185+ $results['abuse_count'] = $record->af_abuse_count;
 186+ if( $record->af_abuse_count > $wgArticleFeedbackv5AbusiveThreshold ) {
185187 // Return a flag in the JSON, that turns the link red.
186188 $results['abusive'] = 1;
187189 }
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -294,16 +294,16 @@
295295 $can_delete = $wgUser->isAllowed( 'aftv5-delete-feedback' );
296296
297297 // Taken from the Moodbar extension.
298 - $now = wfTimestamp( TS_UNIX );
299 - $timestamp = wfTimestamp( TS_UNIX, $record[0]->af_created );
 298+ $now = wfTimestamp( TS_UNIX );
 299+ $timestamp = wfTimestamp( TS_UNIX, $record[0]->af_created );
300300 $date;
301301
302302 // Relative dates for 48 hours, normal timestamps later.
303 - if( $timestamp > ( $now - ( 86400 * 2 ) ) ) {
304 - $time = $wgLang->formatTimePeriod(
 303+ if ( $timestamp > ( $now - ( 86400 * 2 ) ) ) {
 304+ $time = $wgLang->formatTimePeriod(
305305 ( $now - $timestamp ), 'avoidseconds'
306 - );
307 - $date = wfMessage( 'articleFeedbackv5-comment-ago', $time )->escaped();
 306+ );
 307+ $date = wfMessage( 'articleFeedbackv5-comment-ago', $time )->escaped();
308308 } elseif( $timestamp ) {
309309 $date = $wgLang->timeanddate($record[0]->af_created );
310310 }
@@ -327,7 +327,7 @@
328328 if( $record[0]->age > 0 ) {
329329 $details .= Linker::link(
330330 Title::newFromText( $record[0]->page_title ),
331 - wfMessage( 'articlefeedbackv5-updates-since', $record[0]->age )->escaped(),
 331+ wfMessage( 'articlefeedbackv5-updates-since', $record[0]->age )->escaped(),
332332 array(),
333333 array(
334334 'action' => 'historysubmit',
@@ -338,8 +338,7 @@
339339 }
340340
341341 $details .= Html::closeElement( 'div' )
342 - . Html::closeElement( 'div' );
343 -;
 342+ . Html::closeElement( 'div' );
344343
345344 $footer_links = Html::openElement( 'div', array(
346345 'class' => 'articleFeedbackv5-vote-wrapper'
@@ -364,9 +363,14 @@
365364 'id' => "articleFeedbackv5-helpful-votes-$id"
366365 ), wfMessage( 'articlefeedbackv5-form-helpful-votes', $record[0]->af_helpful_count, $record[0]->af_unhelpful_count ) );
367366 if ( $can_flag ) {
 367+ $aclass = 'articleFeedbackv5-abuse-link';
 368+ global $wgArticleFeedbackv5AbusiveThreshold;
 369+ if ( $record[0]->af_abuse_count > $wgArticleFeedbackv5AbusiveThreshold ) {
 370+ $aclass .= ' abusive';
 371+ }
368372 $footer_links .= Html::element( 'a', array(
369373 'id' => "articleFeedbackv5-abuse-link-$id",
370 - 'class' => 'articleFeedbackv5-abuse-link'
 374+ 'class' => $aclass
371375 ), wfMessage( 'articlefeedbackv5-form-abuse', $record[0]->af_abuse_count )->text() );
372376 }
373377 $footer_links .= Html::closeElement( 'p' )
@@ -448,7 +452,7 @@
449453 . Html::closeElement( 'div' );
450454 }
451455
452 - return Html::openElement( 'div', array(
 456+ return Html::openElement( 'div', array(
453457 'class' => 'articleFeedbackv5-feedback',
454458 'rel' => $id
455459 ) )
@@ -530,7 +534,7 @@
531535 'articlefeedbackv5-form5-header',
532536 $class,
533537 $record[0]
534 - );
 538+ );
535539
536540 return $head . $body;
537541 }
@@ -600,8 +604,8 @@
601605 ) )
602606 . Linker::link( Title::newFromText( $link ), $name )
603607 . Html::element( 'span', array( 'class' => 'icon' ) )
604 - . Html::element( 'span',
605 - array( 'class' => 'result' ),
 608+ . Html::element( 'span',
 609+ array( 'class' => 'result' ),
606610 wfMessage( $message, $gender, $extra )->text()
607611 )
608612 . Html::closeElement( 'h3' );
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.hooks.php
@@ -165,6 +165,7 @@
166166 'articlefeedbackv5-error-flagging',
167167 'articlefeedbackv5-invalid-feedback-id',
168168 'articlefeedbackv5-invalid-feedback-flag',
 169+ 'articlefeedbackv5-form-abuse',
169170 'articlefeedbackv5-abuse-saved',
170171 'articlefeedbackv5-hide-saved',
171172 'articlefeedbackv5-hidden',

Status & tagging log