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

Change subject: Migrate block logging to new system and clean up 
doMassUserBlockInternal()
......................................................................


Migrate block logging to new system and clean up doMassUserBlockInternal()

* Migrate block logging to the new system - this is the only one still
    inserting old style block logs on Wikimedia wikis
* Skip at the beginning if the user is already blocked instead of initializing
    the block settings and then checking whether the user is already blocked
* Remove unused $counter variable
* Fix documentation
* Do not tag the user page is the user is already blocked.

Bug: T92546
Change-Id: I8d9d2840ecdf06ed80465444aef4cd880e3301e7
---
M specials/SpecialCheckUser.php
1 file changed, 25 insertions(+), 22 deletions(-)

Approvals:
  Alex Monk: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/specials/SpecialCheckUser.php b/specials/SpecialCheckUser.php
index 624c3ad..6493be1 100644
--- a/specials/SpecialCheckUser.php
+++ b/specials/SpecialCheckUser.php
@@ -275,21 +275,19 @@
        /**
         * Block a list of selected users
         *
-        * @param $users Array
+        * @param string[] $users
         * @param array $blockParams
-        * @param $tag String: replaces user pages
-        * @param $talkTag String: replaces user talk pages
-        * @return Array: list of html-safe usernames
+        * @param string $tag replaces user pages
+        * @param string $talkTag replaces user talk pages
+        * @return string[] List of html-safe usernames which were actually 
were blocked
         */
        public static function doMassUserBlockInternal( $users, $blockParams, 
$tag = '', $talkTag = '' ) {
                global $wgBlockAllowsUTEdit, $wgUser;
 
-               $counter = $blockSize = 0;
+               $blockSize = 0;
                $safeUsers = array();
-               $log = new LogPage( 'block' );
                foreach ( $users as $name ) {
                        # Enforce limits
-                       $counter++;
                        $blockSize++;
                        # Lets not go *too* fast
                        if ( $blockSize >= 20 ) {
@@ -301,6 +299,13 @@
                        if ( is_null( $u ) || ( !$u->getId() && 
!IP::isIPAddress( $u->getName() ) ) ) {
                                continue;
                        }
+
+                       $oldBlock = Block::newFromTarget( $u->getName() );
+                       if ( $oldBlock ) {
+                               // If the user is already blocked, just leave 
it as is
+                               continue;
+                       }
+
                        $userTitle = $u->getUserPage();
                        $userTalkTitle = $u->getTalkPage();
                        $userpage = WikiPage::factory( $userTitle );
@@ -321,23 +326,21 @@
                        $block->prevents( 'createaccount', true );
                        $block->prevents( 'sendemail', ( 
SpecialBlock::canBlockEmail( $wgUser ) && $blockParams['email'] ) );
                        $block->prevents( 'editownusertalk', ( 
!$wgBlockAllowsUTEdit || $blockParams['talk'] ) );
+                       $status = $block->insert();
 
-                       $oldblock = Block::newFromTarget( $u->getName() );
-                       if ( !$oldblock ) {
-                               $block->insert();
-                               # Prepare log parameters
-                               $logParams = array();
-                               $logParams[] = $expirestr;
-                               $logParams[] = self::userBlockLogFlags( 
$anonOnly, $blockParams );
+                       // Prepare log parameters for the block
+                       $logParams = array();
+                       $logParams['5::duration'] = $expirestr;
+                       $logParams['6::flags'] = self::userBlockLogFlags( 
$anonOnly, $blockParams );
 
-                               # Add log entry
-                               $log->addEntry(
-                                       'block',
-                                       $userTitle,
-                                       $blockParams['reason'],
-                                       $logParams
-                               );
-                       }
+                       $logEntry = new ManualLogEntry( 'block', 'block' );
+                       $logEntry->setTarget( $userTitle );
+                       $logEntry->setComment( $blockParams['reason'] );
+                       $logEntry->setPerformer( $wgUser );
+                       $logEntry->setParameters( $logParams );
+                       $blockIds = array_merge( array( $status['id'] ), 
$status['autoIds'] );
+                       $logEntry->setRelations( array( 'ipb_id' => $blockIds ) 
);
+                       $logEntry->publish( $logEntry->insert() );
 
                        # Tag userpage! (check length to avoid mistakes)
                        if ( strlen( $tag ) > 2 ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8d9d2840ecdf06ed80465444aef4cd880e3301e7
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/CheckUser
Gerrit-Branch: master
Gerrit-Owner: Glaisher <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Glaisher <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to