Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/249350

Change subject: LinksUpdate: Keep track of the triggering User
......................................................................

LinksUpdate: Keep track of the triggering User

So extensions like Echo are able to attribute post-edit link updates to
specific the users who triggered them.

Bug: T116485
Change-Id: I083736a174b6bc15e3ce60b2b107c697d0ac13da
(cherry picked from commit c52e5a21f6e6d98524960bd63a294504c65153e3)
---
M includes/deferred/LinksUpdate.php
M includes/jobqueue/jobs/RefreshLinksJob.php
M includes/page/WikiPage.php
3 files changed, 48 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/50/249350/1

diff --git a/includes/deferred/LinksUpdate.php 
b/includes/deferred/LinksUpdate.php
index 93c75ee..9a24b96 100644
--- a/includes/deferred/LinksUpdate.php
+++ b/includes/deferred/LinksUpdate.php
@@ -78,6 +78,11 @@
        private $linkDeletions = null;
 
        /**
+        * @var User|null
+        */
+       private $user;
+
+       /**
         * Constructor
         *
         * @param Title $title Title of the page we're updating
@@ -908,6 +913,24 @@
        }
 
        /**
+        * Set the User who triggered this LinksUpdate
+        *
+        * @since 1.27
+        * @param User $user
+        */
+       public function setTriggeringUser( User $user ) {
+               $this->user = $user;
+       }
+
+       /**
+        * @since 1.27
+        * @return null|User
+        */
+       public function getTriggeringUser() {
+               return $this->user;
+       }
+
+       /**
         * Invalidate any necessary link lists related to page property changes
         * @param array $changed
         */
@@ -980,6 +1003,14 @@
        }
 
        public function getAsJobSpecification() {
+               if ( $this->user ) {
+                       $userInfo = array(
+                               'userId' => $this->user->getId(),
+                               'userName' => $this->user->getName(),
+                       );
+               } else {
+                       $userInfo = false;
+               }
                return array(
                        'wiki' => $this->mDb->getWikiID(),
                        'job'  => new JobSpecification(
@@ -987,7 +1018,8 @@
                                array(
                                        // Reuse the parser cache if it was 
saved
                                        'rootJobTimestamp' => 
$this->mParserOutput->getCacheTime(),
-                                       'useRecursiveLinksUpdate' => 
$this->mRecursive
+                                       'useRecursiveLinksUpdate' => 
$this->mRecursive,
+                                       'triggeringUser' => $userInfo,
                                ),
                                array( 'removeDuplicates' => true ),
                                $this->getTitle()
diff --git a/includes/jobqueue/jobs/RefreshLinksJob.php 
b/includes/jobqueue/jobs/RefreshLinksJob.php
index 915ee23..26f4520 100644
--- a/includes/jobqueue/jobs/RefreshLinksJob.php
+++ b/includes/jobqueue/jobs/RefreshLinksJob.php
@@ -215,8 +215,20 @@
                $updates = $content->getSecondaryDataUpdates(
                        $title, null, !empty( 
$this->params['useRecursiveLinksUpdate'] ), $parserOutput );
                foreach ( $updates as $key => $update ) {
-                       if ( $update instanceof LinksUpdate && isset( 
$this->params['triggeredRecursive'] ) ) {
-                               $update->setTriggeredRecursive();
+                       if ( $update instanceof LinksUpdate ) {
+                               if ( isset( $this->params['triggeredRecursive'] 
) ) {
+                                       $update->setTriggeredRecursive();
+                               }
+                               if ( isset( $this->params['triggeringUser'] ) 
&& $this->params['triggeringUser'] ) {
+                                       $userInfo = 
$this->params['triggeringUser'];
+                                       if ( $userInfo['userId'] ) {
+                                               $user = User::newFromId( 
$userInfo['userId'] );
+                                       } else {
+                                               // Anonymous, use the username
+                                               $user = User::newFromName( 
$userInfo['userName'], false );
+                                       }
+                                       $update->setTriggeringUser( $user );
+                               }
                        }
                }
 
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 8b4980a..acf772e 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -2186,6 +2186,7 @@
                        foreach ( $updates as $update ) {
                                if ( $update instanceof LinksUpdate ) {
                                        $update->setRevision( $revision );
+                                       $update->setTriggeringUser( $user );
                                }
                                DeferredUpdates::addUpdate( $update );
                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I083736a174b6bc15e3ce60b2b107c697d0ac13da
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.27.0-wmf.4
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to