Aaron Schulz has submitted this change and it was merged.

Change subject: Change AbuseFilter to use UserCache instead of user_text fields
......................................................................


Change AbuseFilter to use UserCache instead of user_text fields

Change-Id: I51210ff91366a3a1610d34ca20e8966aaded89a0
---
M AbuseFilter.class.php
M Views/AbuseFilterViewDiff.php
M Views/AbuseFilterViewEdit.php
M Views/AbuseFilterViewHistory.php
M Views/AbuseFilterViewList.php
M Views/AbuseFilterViewRevert.php
M api/ApiQueryAbuseFilters.php
M api/ApiQueryAbuseLog.php
M special/SpecialAbuseLog.php
9 files changed, 95 insertions(+), 32 deletions(-)

Approvals:
  Aaron Schulz: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php
index cb4daa8..4a57d46 100644
--- a/AbuseFilter.class.php
+++ b/AbuseFilter.class.php
@@ -945,6 +945,13 @@
 
                $local_log_ids = array();
                global $wgAbuseFilterNotifications, 
$wgAbuseFilterNotificationsPrivate;
+
+               $userIds = array();
+               foreach ( $log_rows as $index => $data ) {
+                       $userIds[] = $data['afl_user'];
+               }
+               UserCache::singleton()->doQuery( $userIds, array(), __METHOD__ 
);
+
                foreach ( $log_rows as $index => $data ) {
                        $data['afl_var_dump'] = $var_dump;
                        $data['afl_id'] = $dbw->nextSequenceValue( 
'abuse_filter_log_afl_id_seq' );
@@ -959,7 +966,7 @@
                                // Construct a user object
                                $user = new User();
                                $user->setId( $data['afl_user'] );
-                               $user->setName( $data['afl_user_text'] );
+                               $user->setName( 
UserCache::singleton()->getUserName( $data['afl_user'], $data['afl_user_text'] 
) );
                                $entry->setPerformer( $user );
                                // Set action target
                                $entry->setTarget( Title::makeTitle( 
$data['afl_namespace'], $data['afl_title'] ) );
diff --git a/Views/AbuseFilterViewDiff.php b/Views/AbuseFilterViewDiff.php
index 6382dba..af530d0 100644
--- a/Views/AbuseFilterViewDiff.php
+++ b/Views/AbuseFilterViewDiff.php
@@ -185,7 +185,7 @@
                        'meta' => array(
                                'history_id' => $row->afh_id,
                                'modified_by' => $row->afh_user,
-                               'modified_by_text' => $row->afh_user_text,
+                               'modified_by_text' => 
UserCache::singleton()->getUserName( $row->afh_user, $row->afh_user_text ),
                                'modified' => $row->afh_timestamp,
                        ),
                        'info' => array(
diff --git a/Views/AbuseFilterViewEdit.php b/Views/AbuseFilterViewEdit.php
index 41c0ab1..7efcb33 100644
--- a/Views/AbuseFilterViewEdit.php
+++ b/Views/AbuseFilterViewEdit.php
@@ -477,10 +477,11 @@
                                )
                        );
                        // Last modification details
+                       $userName = UserCache::singleton()->getUserName( 
$row->af_user, $row->af_user_text );
+
                        $userLink =
-                               Linker::userLink( $row->af_user, 
$row->af_user_text ) .
-                               Linker::userToolLinks( $row->af_user, 
$row->af_user_text );
-                       $userName = $row->af_user_text;
+                               Linker::userLink( $row->af_user, $userName ) .
+                               Linker::userToolLinks( $row->af_user, $userName 
);
                        $fields['abusefilter-edit-lastmod'] =
                                $this->msg( 'abusefilter-edit-lastmod-text' )
                                ->rawParams(
diff --git a/Views/AbuseFilterViewHistory.php b/Views/AbuseFilterViewHistory.php
index 5ab50eb..bdeb222 100644
--- a/Views/AbuseFilterViewHistory.php
+++ b/Views/AbuseFilterViewHistory.php
@@ -115,6 +115,15 @@
                return $headers;
        }
 
+       function doBatchLookups() {
+               $userIds = array();
+               foreach ( $this->mResult as $row ) {
+                       $userIds[] = $row->afh_user;
+               }
+
+               UserCache::singleton()->doQuery( $userIds, array( 'userpage', 
'usertalk' ), __METHOD__ );
+       }
+
        function formatValue( $name, $value ) {
                $lang = $this->getLanguage();
 
@@ -130,9 +139,10 @@
                                $formatted = Linker::link( $title, 
$lang->timeanddate( $row->afh_timestamp, true ) );
                                break;
                        case 'afh_user_text':
+                               $name = UserCache::singleton()->getUserName( 
$row->afh_user, $row->afh_user_text );
                                $formatted =
-                                       Linker::userLink( $row->afh_user, 
$row->afh_user_text ) . ' ' .
-                                       Linker::userToolLinks( $row->afh_user, 
$row->afh_user_text );
+                                       Linker::userLink( $row->afh_user, $name 
) . ' ' .
+                                       Linker::userToolLinks( $row->afh_user, 
$name );
                                break;
                        case 'afh_public_comments':
                                $formatted = htmlspecialchars( $value, 
ENT_QUOTES, 'UTF-8', false );
diff --git a/Views/AbuseFilterViewList.php b/Views/AbuseFilterViewList.php
index f294e72..07a0ff9 100644
--- a/Views/AbuseFilterViewList.php
+++ b/Views/AbuseFilterViewList.php
@@ -225,6 +225,17 @@
                return $headers;
        }
 
+       function doBatchLookups() {
+               $this->mResult->seek( 0 );
+
+               $userIds = array();
+               foreach ( $this->mResult as $row ) {
+                       $userIds[] = $row->af_user;
+               }
+
+               UserCache::singleton()->doQuery( $userIds, array( 'userpage', 
'usertalk' ), __METHOD__ );
+       }
+
        function formatValue( $name, $value ) {
                $lang = $this->getLanguage();
                $row = $this->mCurrentRow;
@@ -278,22 +289,22 @@
                                }
                                return $link;
                        case 'af_timestamp':
+                               $name = UserCache::singleton()->getUserName( 
$row->af_user, $row->af_user_text );
                                $userLink =
                                        Linker::userLink(
                                                $row->af_user,
-                                               $row->af_user_text
+                                               $name
                                        ) .
                                        Linker::userToolLinks(
                                                $row->af_user,
-                                               $row->af_user_text
+                                               $name
                                        );
-                               $user = $row->af_user_text;
                                return $this->msg( 
'abusefilter-edit-lastmod-text' )
                                        ->rawParams( $lang->timeanddate( 
$value, true ),
                                                $userLink,
                                                $lang->date( $value, true ),
                                                $lang->time( $value, true ),
-                                               $user
+                                               $name
                                )->parse();
                        case 'af_group':
                                return AbuseFilter::nameGroup( $value );
@@ -377,10 +388,9 @@
                                }
                                return $this->msg( 'abusefilter-hitcount' 
)->numParams( $value )->parse();
                        case 'af_timestamp':
-                               $user = $row->af_user_text;
                                return $this->msg(
                                        'abusefilter-edit-lastmod-text',
-                                       $lang->timeanddate( $value, true ), 
$user
+                                       $lang->timeanddate( $value, true ), 
UserCache::singleton()->getUserName( $row->af_user, $row->af_user_text )
                                )->parse();
                        case 'af_group':
                                // If this is global, local name probably 
doesn't exist, but try
diff --git a/Views/AbuseFilterViewRevert.php b/Views/AbuseFilterViewRevert.php
index 9d5791e..a0e6045 100644
--- a/Views/AbuseFilterViewRevert.php
+++ b/Views/AbuseFilterViewRevert.php
@@ -120,8 +120,9 @@
                // Database query.
                $res = $dbr->select( 'abuse_filter_log', '*', $conds, 
__METHOD__ );
 
-               $results = array();
-               foreach( $res as $row ) {
+               $userIds = array();
+               $resultRows = array();
+               foreach ( $res as $row ) {
                        // Don't revert if there was no action, or the action 
was global
                        if ( !$row->afl_actions || $row->afl_wiki != null ) {
                                continue;
@@ -131,18 +132,25 @@
                        $reversibleActions = array( 'block', 
'blockautopromote', 'degroup' );
                        $currentReversibleActions = array_intersect( $actions, 
$reversibleActions );
                        if ( count( $currentReversibleActions ) ) {
-                               $results[] = array(
-                                       'id' => $row->afl_id,
-                                       'actions' => $currentReversibleActions,
-                                       'user' => $row->afl_user_text,
-                                       'userid' => $row->afl_user,
-                                       'vars' => AbuseFilter::loadVarDump( 
$row->afl_var_dump ),
-                                       'title' => Title::makeTitle( 
$row->afl_namespace, $row->afl_title ),
-                                       'action' => $row->afl_action,
-                                       'timestamp' => $row->afl_timestamp
-                               );
+                               $resultRows[] = $row;
+                               $userIds[] = $row->afl_user;
                        }
                }
+               UserCache::singleton()->doQuery( $userIds, array(), __METHOD__ 
);
+
+               $results = array();
+               foreach ( $resultRows as $row ) {
+                       $results[] = array(
+                               'id' => $row->afl_id,
+                               'actions' => $currentReversibleActions,
+                               'user' => UserCache::singleton()->getUserName( 
$row->afl_user, $row->afl_user_text ),
+                               'userid' => $row->afl_user,
+                               'vars' => AbuseFilter::loadVarDump( 
$row->afl_var_dump ),
+                               'title' => Title::makeTitle( 
$row->afl_namespace, $row->afl_title ),
+                               'action' => $row->afl_action,
+                               'timestamp' => $row->afl_timestamp
+                       );
+               }
 
                return $results;
        }
diff --git a/api/ApiQueryAbuseFilters.php b/api/ApiQueryAbuseFilters.php
index 76c8792..f2206eb 100644
--- a/api/ApiQueryAbuseFilters.php
+++ b/api/ApiQueryAbuseFilters.php
@@ -67,7 +67,7 @@
                $this->addFieldsIf( 'af_pattern', $fld_pattern );
                $this->addFieldsIf( 'af_actions', $fld_actions );
                $this->addFieldsIf( 'af_comments', $fld_comments );
-               $this->addFieldsIf( 'af_user_text', $fld_user );
+               $this->addFieldsIf( array( 'af_user', 'af_user_text' ), 
$fld_user );
                $this->addFieldsIf( 'af_timestamp', $fld_time );
 
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
@@ -96,6 +96,14 @@
 
                $showhidden = $user->isAllowed( 'abusefilter-modify' );
 
+               if ( $fld_user ) {
+                       $userIds = array();
+                       foreach ( $res as $row ) {
+                               $userIds[] = $row->af_user;
+                       }
+                       UserCache::singleton()->doQuery( $userIds, array(), 
__METHOD__ );
+               }
+
                $count = 0;
                foreach ( $res as $row ) {
                        if ( ++$count > $params['limit'] ) {
@@ -123,7 +131,7 @@
                                $entry['comments'] = $row->af_comments;
                        }
                        if ( $fld_user ) {
-                               $entry['lasteditor'] = $row->af_user_text;
+                               $entry['lasteditor'] = 
UserCache::singleton()->getUserName( $row->af_user, $row->af_user_text );
                        }
                        if ( $fld_time ) {
                                $ts = new MWTimestamp( $row->af_timestamp );
diff --git a/api/ApiQueryAbuseLog.php b/api/ApiQueryAbuseLog.php
index ada0564..63d8295 100644
--- a/api/ApiQueryAbuseLog.php
+++ b/api/ApiQueryAbuseLog.php
@@ -84,7 +84,7 @@
                $this->addFields( 'afl_deleted' );
                $this->addFields( 'afl_filter' );
                $this->addFieldsIf( 'afl_id', $fld_ids );
-               $this->addFieldsIf( 'afl_user_text', $fld_user );
+               $this->addFieldsIf( array( 'afl_user', 'afl_user_text' ), 
$fld_user );
                $this->addFieldsIf( 'afl_ip', $fld_ip );
                $this->addFieldsIf( array( 'afl_namespace', 'afl_title' ), 
$fld_title );
                $this->addFieldsIf( 'afl_action', $fld_action );
@@ -120,6 +120,12 @@
                }
                $res = $this->select( __METHOD__ );
 
+               $userIds = array();
+               foreach ( $res as $row ) {
+                       $userIds[] = $row->afl_user;
+               }
+               UserCache::singleton()->doQuery( $userIds, array(), __METHOD__ 
);
+
                $count = 0;
                foreach ( $res as $row ) {
                        if ( ++$count > $params['limit'] ) {
@@ -145,7 +151,7 @@
                                $entry['filter'] = $row->af_public_comments;
                        }
                        if ( $fld_user ) {
-                               $entry['user'] = $row->afl_user_text;
+                               $entry['user'] = 
UserCache::singleton()->getUserName( $row->afl_user, $row->afl_user_text );
                        }
                        if ( $fld_ip ) {
                                $entry['ip'] = $row->afl_ip;
diff --git a/special/SpecialAbuseLog.php b/special/SpecialAbuseLog.php
index 1de7254..555e5ea 100644
--- a/special/SpecialAbuseLog.php
+++ b/special/SpecialAbuseLog.php
@@ -403,6 +403,17 @@
                return $wgUser->isAllowed( 'abusefilter-hidden-log' );
        }
 
+       function doBatchLookups() {
+               $this->mResult->seek( 0 );
+
+               $userIds = array();
+               foreach ( $this->mResult as $row ) {
+                       $userIds[] = $row->afl_user;
+               }
+
+               UserCache::singleton()->doQuery( $userIds, array( 'userpage', 
'usertalk' ), __METHOD__ );
+       }
+
        /**
         * @param $row
         * @param $li bool
@@ -442,12 +453,14 @@
                        }
                }
 
+               $name = UserCache::singleton()->getUserName( $row->afl_user, 
$row->afl_user_text );
+
                if ( !$row->afl_wiki ) {
                        // Local user
-                       $userLink = Linker::userLink( $row->afl_user, 
$row->afl_user_text ) .
-                                       Linker::userToolLinks( $row->afl_user, 
$row->afl_user_text, true );
+                       $userLink = Linker::userLink( $row->afl_user, $name ) .
+                                       Linker::userToolLinks( $row->afl_user, 
$name, true );
                } else {
-                       $userLink = WikiMap::foreignUserLink( $row->afl_wiki, 
$row->afl_user_text );
+                       $userLink = WikiMap::foreignUserLink( $row->afl_wiki, 
$name );
                        $userLink .= ' (' . WikiMap::getWikiName( 
$row->afl_wiki ) . ')';
                }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I51210ff91366a3a1610d34ca20e8966aaded89a0
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <kren...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Alex Monk <kren...@gmail.com>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to