r112142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112141‎ | r112142 | r112143 >
Date:20:37, 22 February 2012
Author:emsmith
Status:ok
Tags:
Comment:
bug 34090 - toggle for atomic un/helpful changing (and elimination of an extra http request)
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
@@ -41,6 +41,7 @@
4242 $feedbackId = $params['feedbackid'];
4343 $flag = $params['flagtype'];
4444 $notes = $params['note'];
 45+ $toggle = $params['toggle'];
4546 $direction = isset( $params['direction'] ) ? $params['direction'] : 'increase';
4647 $where = array( 'af_id' => $feedbackId );
4748
@@ -208,7 +209,7 @@
209210 elseif($direction == 'decrease' && $record->af_abuse_count > 0 ) {
210211 $activity = 'unrequest';
211212 $filters['needsoversight'] = -1;
212 - $update[] = "af_oversight_count = GREATEST(af_oversight_count - 1, 0)";
 213+ $update[] = "af_oversight_count = GREATEST(CONVERT(af_oversight_count, SIGNED) - 1, 0)";
213214
214215 // Un-hide if we don't have oversight flags anymore
215216 if( $record->af_oversight_count == 1 && true == $record->af_is_hidden ) {
@@ -227,14 +228,50 @@
228229 // helpful and unhelpful flagging
229230 } elseif( 'unhelpful' === $flag || 'helpful' === $flag) {
230231
231 - if ( 'unhelpful' === $flag ) {
232 - $update[] = "af_unhelpful_count = af_unhelpful_count + 1";
233 - } elseif ( 'helpful' === $flag ) {
234 - $update[] = "af_helpful_count = af_helpful_count + 1";
 232+ $results['toggle'] = $toggle;
 233+ $helpful = $record->af_helpful_count;
 234+ $unhelpful = $record->af_unhelpful_count;
 235+
 236+ // if toggle is on, we are decreasing one and increasing the other atomically
 237+ // means one less http request and the counts don't mess up
 238+ if (true == $toggle) {
 239+
 240+ if( ( ($flag == 'helpful' && $direction == 'increase' )
 241+ || ($flag == 'unhelpful' && $direction == 'decrease' ) )
 242+ ) {
 243+ $update[] = "af_helpful_count = af_helpful_count + 1";
 244+ $update[] = "af_unhelpful_count = GREATEST(0, CONVERT(af_unhelpful_count, SIGNED) - 1)";
 245+ $helpful++;
 246+ $unhelpful--;
 247+
 248+ } elseif ( ( ($flag == 'unhelpful' && $direction == 'increase' )
 249+ || ($flag == 'helpful' && $direction == 'decrease' ) )
 250+ ) {
 251+ $update[] = "af_unhelpful_count = af_unhelpful_count + 1";
 252+ $update[] = "af_helpful_count = GREATEST(0, CONVERT(af_helpful_count, SIGNED) - 1)";
 253+ $helpful--;
 254+ $unhelpful++;
 255+ }
 256+
 257+ } else {
 258+
 259+ if ( 'unhelpful' === $flag && $direction == 'increase') {
 260+ $update[] = "af_unhelpful_count = af_unhelpful_count + 1";
 261+ $unhelpful++;
 262+ } elseif ( 'unhelpful' === $flag && $direction == 'decrease') {
 263+ $update[] = "af_unhelpful_count = GREATEST(0, CONVERT(af_unhelpful_count, SIGNED) - 1)";
 264+ $unhelpful--;
 265+ } elseif ( $flag == 'helpful' && $direction == 'increase' ) {
 266+ $update[] = "af_helpful_count = af_helpful_count + 1";
 267+ $helpful++;
 268+ } elseif ( $flag == 'helpful' && $direction == 'decrease' ) {
 269+ $update[] = "af_helpful_count = GREATEST(0, CONVERT(af_helpful_count, SIGNED) - 1)";
 270+ $helpful--;
 271+ }
 272+
235273 }
236274
237 - // note that a net helpfulness of 0 is neither helpful nor unhelpful
238 - $netHelpfulness = $record->af_net_helpfulness;
 275+ $netHelpfulness = $helpful - $unhelpful;
239276
240277 // increase helpful OR decrease unhelpful
241278 if( ( ($flag == 'helpful' && $direction == 'increase' )
@@ -294,18 +331,6 @@
295332
296333 // Update helpful/unhelpful display count after submission.
297334 if ( $flag == 'helpful' || $flag == 'unhelpful' ) {
298 - $helpful = $record->af_helpful_count;
299 - $unhelpful = $record->af_unhelpful_count;
300 -
301 - if( $flag == 'helpful' && $direction == 'increase' ) {
302 - $helpful++;
303 - } elseif ( $flag == 'helpful' && $direction == 'decrease' ) {
304 - $helpful--;
305 - } elseif ( $flag == 'unhelpful' && $direction == 'increase' ) {
306 - $unhelpful++;
307 - } elseif ( $flag == 'unhelpful' && $direction == 'decrease' ) {
308 - $unhelpful--;
309 - }
310335
311336 // no negative numbers please
312337 $helpful = max(0, $helpful);
@@ -460,6 +485,11 @@
461486 ApiBase::PARAM_REQUIRED => false,
462487 ApiBase::PARAM_ISMULTI => false,
463488 ApiBase::PARAM_TYPE => 'string'
 489+ ),
 490+ 'toggle' => array(
 491+ ApiBase::PARAM_REQUIRED => false,
 492+ ApiBase::PARAM_ISMULTI => false,
 493+ ApiBase::PARAM_TYPE => 'boolean'
464494 )
465495 );
466496 }
@@ -473,7 +503,8 @@
474504 return array(
475505 'feedbackid' => 'FeedbackID to flag',
476506 'type' => 'Type of flag to apply - hide or abuse',
477 - 'note' => 'Information on why the feedback activity occurred'
 507+ 'note' => 'Information on why the feedback activity occurred',
 508+ 'toggle' => 'The flag is being toggled atomically, only useful for (un)helpful'
478509 );
479510 }
480511

Follow-up revisions

RevisionCommit summaryAuthorDate
r112147bug 34090 - note to self, watch the copy and paste errors...emsmith21:01, 22 February 2012
r112149bug 34090 - no upper limit, only lower limit - we can't get any worse then 0emsmith21:21, 22 February 2012
r112154bug 34090 - quick and dirty helper script to get missing documentation keysemsmith21:57, 22 February 2012
r112156bug 34090 - only send the activity header if continue < 1, make the more div ...emsmith22:14, 22 February 2012
r112161bug 34090 - fix limit and use old continue to determine if we do the headeremsmith23:15, 22 February 2012
r112218bug 34090 - make sure the name are right for hidden/unhidden logging (argh)emsmith16:44, 23 February 2012
r112225bug 34090 - unhidden and unoversight logic adjustmentsemsmith18:06, 23 February 2012
r112228bug 34090 - fix filter - needsoversight are always autohiddenemsmith19:16, 23 February 2012
r112230bug 34090 - let's try this again - needsoversight and declined will have hidd...emsmith19:38, 23 February 2012
r112232bug 34090 - hide and show shouldn't fiddle with oversight counts or declined ...emsmith19:48, 23 February 2012
r112599bug 34090 - follow up to r111211 - rename things to make them "less confusin...emsmith14:43, 28 February 2012
r112603bug 34090 - Add the logging of automated hide/show errors by the "Article Fee...emsmith15:21, 28 February 2012
r112604bug 34090 - can't believe there were no permissions checks in this - only del...emsmith15:38, 28 February 2012
r112610bug 34090 - change all sql updates to use escaping except for explicitly comm...emsmith16:22, 28 February 2012
r112611bug 34090 - take out implicit show and add returning user that hid/oversighte...emsmith17:02, 28 February 2012
r112627bug 34090 - follow up to r112599 - change to use getText since it's going int...emsmith18:53, 28 February 2012
r112825bug 34090 - insert custom attributes (sigh) for the user and formatted timest...emsmith18:14, 1 March 2012
r112830bug 34090 - follow up to r111474 - use truncate for choppingemsmith19:42, 1 March 2012
r113052bug 34090 - remaining backend feature in requirements, oversight email genera...emsmith18:04, 5 March 2012
r113062bug 34090 - follow up to r110520 1. change index 2. default of null for conti...emsmith18:54, 5 March 2012
r113073bug 34090 - follow up to r111472 part 1 - change to use getDbKey, check for b...emsmith19:48, 5 March 2012
r113082bug 34090 - follow up to r111471 - changed to use text()emsmith20:42, 5 March 2012
r113083bug 34090 - follow up to rr111472 part 2 - only use log_id for orderingemsmith20:48, 5 March 2012
r113104bug 34090 - follow up to rr111472 part 3 - totally redo the continue function...emsmith23:10, 5 March 2012
r113159bug 34090 - follow up to rr111472 part 4 and follow up to r111596 (same issue...emsmith17:37, 6 March 2012
r113160bug 34090 - follow up to rr111472 part 5 plural and number format action countemsmith17:48, 6 March 2012
r113161bug 34090 - follow up to rr111472 part 6 last of lego messagesemsmith17:53, 6 March 2012
r113163bug 34090 - two additional configuration settings (help url and admin user ur...emsmith18:02, 6 March 2012
r113193bug 34090 - followup to r113104 - only sort by timestamp (sorting by log id w...emsmith22:56, 6 March 2012
r113228bug 34090 - followup to r113160emsmith14:05, 7 March 2012
r113247bug 34090 - db issue, remove one of the sorts from the query, use the ids arr...emsmith16:52, 7 March 2012
r113269bug 34090 - followup to r113247emsmith19:01, 7 March 2012
r113273bug 34090 - add javascript level hiding on request oversight IF autohidden is...emsmith19:22, 7 March 2012
r113287bug 34090 - usernames and formatted timestamps into red lines for hidden/over...emsmith20:22, 7 March 2012
r113311bug 34090 - fixing the username bugs - apparently using the data- stuff with ...emsmith22:34, 7 March 2012
r113317bug 34090 - js and css voodoo to make the element with the red lines appear a...emsmith23:01, 7 March 2012
r113370bug 34090 - make different titles for masking appear if it's been hidden or o...emsmith16:43, 8 March 2012
r113371bug 34090 - fixes for oversighter view for hide/oversight panelsemsmith17:51, 8 March 2012
r113383bug 34090 - not entirely necessary, but keeps $2 from showing up in hiders pa...emsmith19:25, 8 March 2012
r113384bug 34090 - fix for double red line issues when hiding an oversighted post ha...emsmith19:28, 8 March 2012
r113390bug 34090 - adding translation for "automatic hider" useremsmith19:44, 8 March 2012
r113392bug 34090 - followup to r113287 - adjusted localization documentationemsmith20:03, 8 March 2012
r113393bug 34090 - followup to r113370 - adjusted localization documentationemsmith20:05, 8 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111211bug 34090 - Added a log namespace and log types for the Article Feedback v5 e...emsmith22:53, 10 February 2012
r111472bug 34090 - Added an additional column in the main feedback table to keep a c...emsmith19:14, 14 February 2012
r111474bug 34090 - remove a todo - take the note from the flag submission and save i...emsmith19:57, 14 February 2012
r111552bug 34090 - split activity notes into their own config for maximum length (th...emsmith16:07, 15 February 2012
r111557bug 34090 - changed structure of the link classes and ids per the following f...emsmith16:47, 15 February 2012
r111570bug 34090 - request oversight is now a counter - so you can request/unrequest...emsmith19:53, 15 February 2012
r111573bug 34090 - removed the "header" portion of the html generation from the acti...emsmith20:18, 15 February 2012
r111645bug 34090 - updated the filter count update script to get requested oversight...emsmith15:45, 16 February 2012
r112038bug 34090 - added additional counts for filters including unhidden, undeleted...emsmith20:28, 21 February 2012
r112039bug 34090 - fixed issue noted : if $feedback is false return nothing - not th...emsmith20:50, 21 February 2012
r112041bug 34090 - kill the -1 issue by never letting it get below 0emsmith21:08, 21 February 2012
r112115bug 34090 - no code changes, just fixing/adding keyword svn propertiesemsmith16:31, 22 February 2012
r112119bug 34090 - cast the naughty column so it can be signed, the greatest still k...emsmith16:57, 22 February 2012

Status & tagging log