Legoktm has uploaded a new change for review.

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

Change subject: Move logging inside of RenameuserSQL
......................................................................

Move logging inside of RenameuserSQL

Bug: T89681
Bug: T72851
Change-Id: I6845716ca0b565fca65dc78a254970e403ffe31d
---
M RenameuserSQL.php
M specials/SpecialRenameuser.php
2 files changed, 46 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Renameuser 
refs/changes/81/197681/1

diff --git a/RenameuserSQL.php b/RenameuserSQL.php
index 2840fd0..e399c99 100644
--- a/RenameuserSQL.php
+++ b/RenameuserSQL.php
@@ -46,6 +46,20 @@
        public $checkIfUserExists;
 
        /**
+        * User object of the user performing the rename, for logging purposes
+        *
+        * @var User
+        */
+       private $renamer;
+
+       /**
+        * Reason to be used in the log entry
+        *
+        * @var string
+        */
+       private $reason = '';
+
+       /**
         * A prefix to use in all debug log messages
         *
         * @var string
@@ -58,13 +72,15 @@
         * @param $old string The old username
         * @param $new string The new username
         * @param $uid
+        * @param User $renamer
         * @param $options Array of options
         *      'checkIfUserExists' - bool, whether to update the user table
         */
-       function __construct( $old, $new, $uid, $options = array() ) {
+       function __construct( $old, $new, $uid, User $renamer, $options = 
array() ) {
                $this->old = $old;
                $this->new = $new;
                $this->uid = $uid;
+               $this->renamer = $renamer;
                $this->checkIfUserExists = true;
 
                if ( isset ( $options['checkIfUserExists'] ) ) {
@@ -73,6 +89,10 @@
 
                if ( isset( $options['debugPrefix'] ) ) {
                        $this->debugPrefix = $options['debugPrefix'];
+               }
+
+               if ( isset( $options['reason'] ) ) {
+                       $this->reason = $options['reason'];
                }
 
                $this->tables = array(); // Immediate updates
@@ -112,6 +132,9 @@
         */
        function rename() {
                global $wgMemc, $wgAuth, $wgUpdateRowsPerJob;
+
+               // Grab the user's edit count first, used in log entry
+               $contribs = User::newfromId( $this->uid )->getEditCount();
 
                $dbw = wfGetDB( DB_MASTER );
                $dbw->begin();
@@ -255,6 +278,21 @@
                $user = User::newFromId( $this->uid );
                $wgAuth->updateExternalDB( $user );
                Hooks::run( 'RenameUserComplete', array( $this->uid, 
$this->old, $this->new ) );
+
+               // Log it!
+               $logEntry = new ManualLogEntry( 'renameuser', 'renameuser' );
+               $logEntry->setPerformer( $this->renamer );
+               $logEntry->setTarget( $oldTitle );
+               $logEntry->setComment( $this->reason );
+               $logEntry->setParameters( array(
+                       '4::olduser' => $this->old,
+                       '5::newuser' => $this->new,
+                       '6::edits' => $contribs
+               ) );
+               $logid = $logEntry->insert();
+               $logEntry->publish( $logid );
+
+
                $this->debug( "Finished rename for {$this->old} to 
{$this->new}" );
 
                return true;
diff --git a/specials/SpecialRenameuser.php b/specials/SpecialRenameuser.php
index d7ada76..70946e3 100644
--- a/specials/SpecialRenameuser.php
+++ b/specials/SpecialRenameuser.php
@@ -259,16 +259,19 @@
                        return;
                }
 
-               // Always get the edits count, it will be used for the log 
message
-               $contribs = $olduser->getEditCount();
-
                // Give other affected extensions a chance to validate or abort
                if ( !Hooks::run( 'RenameUserAbort', array( $uid, 
$oldusername->getText(), $newusername->getText() ) ) ) {
                        return;
                }
 
                // Do the heavy lifting...
-               $rename = new RenameuserSQL( $oldusername->getText(), 
$newusername->getText(), $uid );
+               $rename = new RenameuserSQL(
+                       $oldusername->getText(),
+                       $newusername->getText(),
+                       $uid,
+                       $this->getUser(),
+                       array( 'reason' => $reason )
+               );
                if ( !$rename->rename() ) {
                        return;
                }
@@ -278,20 +281,6 @@
                if ( $user->getId() == $uid ) {
                        $user->setName( $newusername->getText() );
                }
-
-               // Log this rename, updated to 1.19+ Log form.
-               //      https://www.mediawiki.org/wiki/Logging_to_Special:Log
-               $logEntry = new ManualLogEntry( 'renameuser', 'renameuser' );
-               $logEntry->setPerformer( $this->getUser() );
-               $logEntry->setTarget( $oldusername );
-               $logEntry->setComment( $reason );
-               $logEntry->setParameters( array(
-                       '4::olduser' => $oldusername->getText(),
-                       '5::newuser' => $newusername->getText(),
-                       '6::edits' => $contribs
-               ) );
-               $logid = $logEntry->insert();
-               $logEntry->publish( $logid );
 
                // Move any user pages
                if ( $request->getCheck( 'movepages' ) && $user->isAllowed( 
'move' ) ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6845716ca0b565fca65dc78a254970e403ffe31d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Renameuser
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

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

Reply via email to