https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112610
Revision: 112610
Author: emsmith
Date: 2012-02-28 16:22:18 +0000 (Tue, 28 Feb 2012)
Log Message:
-----------
bug 34090 - change all sql updates to use escaping except for explicitly
commented items, add logging of id of doer and timestamp for last
hide/delete(oversight) of a feedback item, note this is not yet hooked into the
front end js
Modified Paths:
--------------
trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
trunk/extensions/ArticleFeedbackv5/sql/alter.sql
Modified:
trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
2012-02-28 16:14:31 UTC (rev 112609)
+++ trunk/extensions/ArticleFeedbackv5/api/ApiFlagFeedbackArticleFeedbackv5.php
2012-02-28 16:22:18 UTC (rev 112610)
@@ -51,6 +51,7 @@
// we use ONE db connection that talks to master
$dbw = wfGetDB( DB_MASTER );
$dbw->begin();
+ $timestamp = $dbw->timestamp();
// load feedback record, bail if we don't have one
$record = $this->fetchRecord( $dbw, $feedbackId );
@@ -69,8 +70,11 @@
$activity = 'oversight';
// delete
- $update[] = "af_is_deleted = TRUE";
- $update[] = "af_is_undeleted = FALSE";
+ $update['af_is_deleted'] = true;
+ $update['af_is_undeleted'] = false;
+ // only store the oversighter on
delete/oversight
+ $update['af_oversight_user_id'] =
$wgUser->getId();
+ $update['af_oversight_timestamp'] = $timestamp;
// delete specific filters
$filters['deleted'] = 1;
$filters['notdeleted'] = -1;
@@ -80,17 +84,20 @@
// autohide if not hidden
if (false == $record->af_is_hidden ) {
- $update[] = "af_is_hidden = TRUE";
- $update[] = "af_is_unhidden = FALSE";
+ $update['af_is_hidden'] = true;
+ $update['af_is_unhidden'] = false;
$filters = $this->changeFilterCounts(
$record, $filters, 'hide' );
+ // 0 is used for "autohidden" purposes,
we'll explicitly set it to overwrite last hider
+ $update['af_hide_user_id'] = 0;
+ $update['af_hide_timestamp'] =
$timestamp;
$implicit_hide = true; // for logging
}
} else {
// decrease means "unoversight this" but does NOT
auto-unhide
$activity = 'unoversight';
- $update[] = "af_is_deleted = FALSE";
- $update[] = "af_is_undeleted = TRUE";
+ $update['af_is_deleted'] = false;
+ $update['af_is_undeleted'] = true;
// increment "undeleted", decrement "deleted"
// NOTE: we do not touch visible, since hidden
controls visiblity
$filters['deleted'] = -1;
@@ -106,17 +113,19 @@
$activity = 'hidden';
// hide
- $update[] = "af_is_hidden = TRUE";
- $update[] = "af_is_unhidden = FALSE";
-
+ $update['af_is_hidden'] = true;
+ $update['af_is_unhidden'] = false;
+ // only store the hider on hide not show
+ $update['af_hide_user_id'] = $wgUser->getId();
+ $update['af_hide_timestamp'] = $timestamp;
$filters = $this->changeFilterCounts( $record,
$filters, 'hide' );
} else {
// decrease means "unhide this"
$activity = 'unhidden';
- $update[] = "af_is_hidden = FALSE";
- $update[] = "af_is_unhidden = TRUE";
+ $update['af_is_hidden'] = false;
+ $update['af_is_unhidden'] = true;
$filters = $this->changeFilterCounts( $record,
$filters, 'show' );
}
@@ -125,9 +134,9 @@
$activity = 'decline';
// oversight request count becomes 0
- $update[] = "af_oversight_count = 0";
+ $update['af_oversight_count'] = 0;
// declined oversight is flagged
- $update[] = "af_is_declined = TRUE";
+ $update['af_is_declined'] = true;
$filters['declined'] = 1;
// if the oversight count was greater then 1
if(0 < $record->af_oversight_count) {
@@ -160,14 +169,18 @@
if($direction == 'increase') {
$activity = 'flag';
$filters['abusive'] = 1;
+ // NOTE: we are bypassing traditional sql
escaping here
$update[] = "af_abuse_count = af_abuse_count +
1";
// Auto-hide after threshold flags
if( $record->af_abuse_count >
$wgArticleFeedbackv5HideAbuseThreshold
&& false == $record->af_is_hidden ) {
// hide
- $update[] = "af_is_hidden = TRUE";
- $update[] = "af_is_unhidden = FALSE";
+ $update['af_is_hidden'] = true;
+ $update['af_is_unhidden'] = false;
+ // 0 is used for "autohidden" purposes,
we'll explicitly set it to overwrite last hider
+ $update['af_hide_user_id'] = 0;
+ $update['af_hide_timestamp'] =
$timestamp;
$filters = $this->changeFilterCounts(
$record, $filters, 'hide' );
$results['abuse-hidden'] = 1;
@@ -179,12 +192,13 @@
elseif($direction == 'decrease') {
$activity = 'unflag';
$filters['abusive'] = -1;
+ // NOTE: we are bypassing traditional sql
escaping here
$update[] = "af_abuse_count =
GREATEST(CONVERT(af_abuse_count, SIGNED) -1, 0)";
// Un-hide if we don't have 5 flags anymore
if( $record->af_abuse_count == 5 && true ==
$record->af_is_hidden ) {
- $update[] = "af_is_hidden = FALSE";
- $update[] = "af_is_unhidden = TRUE";
+ $update['af_is_hidden'] = false;
+ $update['af_is_unhidden'] = true;
$filters = $this->changeFilterCounts(
$record, $filters, 'show' );
@@ -201,24 +215,28 @@
if($direction == 'increase') {
$activity = 'request';
$filters['needsoversight'] = 1;
+ // NOTE: we are bypassing traditional sql
escaping here
$update[] = "af_oversight_count =
af_oversight_count + 1";
// autohide if not hidden
if (false == $record->af_is_hidden ) {
- $update[] = "af_is_hidden = TRUE";
- $update[] = "af_is_unhidden = FALSE";
+ $update['af_is_hidden'] = true;
+ $update['af_is_unhidden'] = false;
+ // 0 is used for "autohidden" purposes,
we'll explicitly set it to overwrite last hider
+ $update['af_hide_user_id'] = 0;
$filters = $this->changeFilterCounts(
$record, $filters, 'hide' );
$implicit_hide = true; // for logging
}
} elseif($direction == 'decrease') {
$activity = 'unrequest';
$filters['needsoversight'] = -1;
+ // NOTE: we are bypassing traditional sql
escaping here
$update[] = "af_oversight_count =
GREATEST(CONVERT(af_oversight_count, SIGNED) - 1, 0)";
// Un-hide if we don't have oversight flags
anymore
if( $record->af_oversight_count == 1 && true ==
$record->af_is_hidden ) {
- $update[] = "af_is_hidden = FALSE";
- $update[] = "af_is_unhidden = TRUE";
+ $update['af_is_hidden'] = false;
+ $update['af_is_unhidden'] = true;
$filters = $this->changeFilterCounts(
$record, $filters, 'show' );
@@ -243,6 +261,7 @@
if( ( ($flag == 'helpful' && $direction ==
'increase' )
|| ($flag == 'unhelpful' && $direction ==
'decrease' ) )
) {
+ // NOTE: we are bypassing traditional
sql escaping here
$update[] = "af_helpful_count =
af_helpful_count + 1";
$update[] = "af_unhelpful_count =
GREATEST(0, CONVERT(af_unhelpful_count, SIGNED) - 1)";
$helpful++;
@@ -251,6 +270,7 @@
} elseif ( ( ($flag == 'unhelpful' &&
$direction == 'increase' )
|| ($flag == 'helpful' && $direction ==
'decrease' ) )
) {
+ // NOTE: we are bypassing traditional
sql escaping here
$update[] = "af_unhelpful_count =
af_unhelpful_count + 1";
$update[] = "af_helpful_count =
GREATEST(0, CONVERT(af_helpful_count, SIGNED) - 1)";
$helpful--;
@@ -260,15 +280,19 @@
} else {
if ( 'unhelpful' === $flag && $direction ==
'increase') {
+ // NOTE: we are bypassing traditional
sql escaping here
$update[] = "af_unhelpful_count =
af_unhelpful_count + 1";
$unhelpful++;
} elseif ( 'unhelpful' === $flag && $direction
== 'decrease') {
+ // NOTE: we are bypassing traditional
sql escaping here
$update[] = "af_unhelpful_count =
GREATEST(0, CONVERT(af_unhelpful_count, SIGNED) - 1)";
$unhelpful--;
} elseif ( $flag == 'helpful' && $direction ==
'increase' ) {
+ // NOTE: we are bypassing traditional
sql escaping here
$update[] = "af_helpful_count =
af_helpful_count + 1";
$helpful++;
} elseif ( $flag == 'helpful' && $direction ==
'decrease' ) {
+ // NOTE: we are bypassing traditional
sql escaping here
$update[] = "af_helpful_count =
GREATEST(0, CONVERT(af_helpful_count, SIGNED) - 1)";
$helpful--;
}
Modified: trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
===================================================================
--- trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
2012-02-28 16:14:31 UTC (rev 112609)
+++ trunk/extensions/ArticleFeedbackv5/sql/ArticleFeedbackv5.sql
2012-02-28 16:22:18 UTC (rev 112610)
@@ -56,11 +56,14 @@
af_has_comment boolean NOT NULL DEFAULT FALSE,
-- Keep track of number of activities (hide/show/flag/unflag)
-- should be equivalent to counting rows in logging table
- af_activity_count integer unsigned NOT NULL DEFAULT 0
- -- for some of the filtering, we need to know "unhidden"
- -- to do this we have to keep track of "has ever been hidden
- -- same with "has ever been oversighted, has ever had oversight requested"
- -- these go on and never go back off, really
+ af_activity_count integer unsigned NOT NULL DEFAULT 0,
+ -- keep the user id of the last hider and/or oversighter of the feedback
+ -- only registered users can do this, which is why no ips
+ -- data used on the overlay of hidden/oversighted items
+ af_hide_user_id integer unsigned NOT NULL DEFAULT 0,
+ af_hide_timestamp binary(14) NOT NULL DEFAULT '',
+ af_oversight_user_id integer unsigned NOT NULL DEFAULT 0,
+ af_oversight_timestamp binary(14) NOT NULL DEFAULT '',
) /*$wgDBTableOptions*/;
CREATE INDEX /*i*/af_page_user_token_id ON /*_*/aft_article_feedback
(af_page_id, af_user_id, af_user_anon_token, af_id);
CREATE INDEX /*i*/af_revision_id ON /*_*/aft_article_feedback (af_revision_id);
Modified: trunk/extensions/ArticleFeedbackv5/sql/alter.sql
===================================================================
--- trunk/extensions/ArticleFeedbackv5/sql/alter.sql 2012-02-28 16:14:31 UTC
(rev 112609)
+++ trunk/extensions/ArticleFeedbackv5/sql/alter.sql 2012-02-28 16:22:18 UTC
(rev 112610)
@@ -133,6 +133,10 @@
ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_is_undeleted BOOLEAN NOT
NULL DEFAULT FALSE;
ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_is_declined BOOLEAN NOT
NULL DEFAULT FALSE;
ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_activity_count integer
unsigned NOT NULL DEFAULT 0;
+ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_hide_user_id integer
unsigned NOT NULL DEFAULT 0;
+ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_oversight_user_id integer
unsigned NOT NULL DEFAULT 0;
+ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_hide_timestamp binary(14)
NOT NULL DEFAULT '';
+ALTER TABLE /*_*/aft_article_feedback ADD COLUMN af_oversight_timestamp
binary(14) NOT NULL DEFAULT '';
--- set has_comment appropriately
+-- set has_comment appropriately from current values
UPDATE aft_article_feedback, aft_article_answer SET af_has_comment = TRUE
WHERE af_bucket_id = 1 AND af_id = aa_feedback_id AND aa_response_text IS NOT
NULL;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs