jenkins-bot has submitted this change and it was merged.

Change subject: Claim anon feedback after sign up
......................................................................


Claim anon feedback after sign up

After posting feedback, one of the CTA's (CTA4) encourages users to
create an account of login. This addition will, after having created an
account or having logged in, update the feedback they had just submitted
to reflect their id in the af_claimed_by column.

Change-Id: I388a2534875d86f08c7f505d927285a62f2ba7ae
---
M ArticleFeedbackv5.hooks.php
M ArticleFeedbackv5.model.php
M ArticleFeedbackv5.php
M api/ApiArticleFeedbackv5.php
M sql/ArticleFeedbackv5.sql
A sql/claimed_user.sql
6 files changed, 68 insertions(+), 0 deletions(-)

Approvals:
  Bsitu: Looks good to me, but someone else must approve
  Matthias Mullie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ArticleFeedbackv5.hooks.php b/ArticleFeedbackv5.hooks.php
index 9f2d623..26dc50c 100644
--- a/ArticleFeedbackv5.hooks.php
+++ b/ArticleFeedbackv5.hooks.php
@@ -91,6 +91,12 @@
                        dirname( __FILE__ ) . '/sql/discuss.sql'
                );
 
+               $updater->addExtensionField(
+                       'aft_feedback',
+                       'aft_claimed_user',
+                       dirname( __FILE__ ) . '/sql/claimed_user.sql'
+               );
+
                return true;
        }
 
@@ -796,4 +802,60 @@
 
                return $success;
        }
+
+       /**
+        * Post-login update new user's last feedback with his new id
+        *
+        * @param User $currentUser
+        * @param string $injected_html
+        * @return bool
+        */
+       public static function userLoginComplete( $currentUser, $injected_html 
) {
+               global $wgRequest;
+
+               $id = 0;
+
+               // feedback id is c-parameter in the referrer, extract it
+               $referrer = ( $wgRequest->getVal( 'referrer' ) ) ? 
$wgRequest->getVal( 'referrer' ) : $wgRequest->getHeader( 'referer' );
+               $url = parse_url( $referrer );
+               $values = array();
+               if ( isset( $url['query'] ) ) {
+                       parse_str( $url['query'], $values );
+               }
+               if ( isset( $values['c'] ) ) {
+                       $id = $values['c'];
+
+               // if c-parameter is no longer in url (e.g. account creation 
didn't work at first attempts), try cookie data
+               } else {
+                       $cookie = json_decode( $wgRequest->getCookie( 
ArticleFeedbackv5Utils::getCookieName( 'feedback-ids' ) ), true );
+                       if ( is_array( $cookie ) ) {
+                               $id = array_shift( $cookie );
+                       }
+               }
+
+               // the page that feedback was added to is the one we'll be 
returned to
+               $title = Title::newFromDBkey( $wgRequest->getVal( 'returnto' ) 
);
+               if ( $title !== null && $id ) {
+                       $pageId = $title->getArticleID();
+
+                       /*
+                        * If we find this feedback and it is not yet "claimed" 
(and the feedback was
+                        * not submitted by a registered user), "claim" it to 
the current user.
+                        * Make sure the current request's IP actually still 
matches the one saved for
+                        * the original submission.
+                        */
+                       $feedback = ArticleFeedbackv5Model::get( $id, $pageId );
+                       if (
+                               $feedback &&
+                               !$feedback->aft_user &&
+                               $feedback->aft_user_text == IP::sanitizeIP( 
$wgRequest->getIP() ) &&
+                               !$feedback->aft_claimed_user
+                        ) {
+                               $feedback->aft_claimed_user = 
$currentUser->getId();
+                               $feedback->update();
+                       }
+               }
+
+               return true;
+       }
 }
diff --git a/ArticleFeedbackv5.model.php b/ArticleFeedbackv5.model.php
index 80a09ae..3aecd8e 100644
--- a/ArticleFeedbackv5.model.php
+++ b/ArticleFeedbackv5.model.php
@@ -21,6 +21,7 @@
                $aft_user,
                $aft_user_text,
                $aft_user_token,
+               $aft_claimed_user,
                $aft_form,
                $aft_cta,
                $aft_link,
diff --git a/ArticleFeedbackv5.php b/ArticleFeedbackv5.php
index 79a8737..b08b199 100644
--- a/ArticleFeedbackv5.php
+++ b/ArticleFeedbackv5.php
@@ -427,6 +427,7 @@
 $wgHooks['ContributionsLineEnding'][] = 
'ArticleFeedbackv5Hooks::contributionsLineEnding';
 $wgHooks['ProtectionForm::buildForm'][] = 
'ArticleFeedbackv5Hooks::onProtectionForm';
 $wgHooks['ProtectionForm::save'][] = 
'ArticleFeedbackv5Hooks::onProtectionSave';
+$wgHooks['UserLoginComplete'][] = 'ArticleFeedbackv5Hooks::userLoginComplete';
 
 // API Registration
 $wgAPIListModules['articlefeedbackv5-view-feedback'] = 
'ApiViewFeedbackArticleFeedbackv5';
diff --git a/api/ApiArticleFeedbackv5.php b/api/ApiArticleFeedbackv5.php
index 6350904..091713b 100644
--- a/api/ApiArticleFeedbackv5.php
+++ b/api/ApiArticleFeedbackv5.php
@@ -62,6 +62,7 @@
                $feedback->aft_user = $user->getId();
                $feedback->aft_user_text = $user->getName();
                $feedback->aft_user_token = $params['anontoken'];
+               $feedback->aft_claimed_user = $user->getId();
                $feedback->aft_form = $params['bucket'];
                $feedback->aft_cta = $params['cta'];
                $feedback->aft_link = $params['link'];
diff --git a/sql/ArticleFeedbackv5.sql b/sql/ArticleFeedbackv5.sql
index 7b7e0d7..aa60eb2 100644
--- a/sql/ArticleFeedbackv5.sql
+++ b/sql/ArticleFeedbackv5.sql
@@ -6,6 +6,7 @@
   aft_user integer unsigned NOT NULL,
   aft_user_text varchar(255) binary NOT NULL DEFAULT '',
   aft_user_token varbinary(32) NOT NULL DEFAULT '',
+  aft_claimed_user integer unsigned NOT NULL DEFAULT 0,
   aft_form binary(1) NOT NULL DEFAULT '',
   aft_cta binary(1) NOT NULL DEFAULT '',
   aft_link binary(1) NOT NULL DEFAULT '',
diff --git a/sql/claimed_user.sql b/sql/claimed_user.sql
new file mode 100644
index 0000000..3e4e1e9
--- /dev/null
+++ b/sql/claimed_user.sql
@@ -0,0 +1,2 @@
+ALTER TABLE /*_*/aft_feedback
+  ADD COLUMN aft_claimed_user integer unsigned NOT NULL DEFAULT 0;

-- 
To view, visit https://gerrit.wikimedia.org/r/33383
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I388a2534875d86f08c7f505d927285a62f2ba7ae
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to