mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 23:40:19 +00:00
Expand AbuseFilter::getFilter to select all fields and fix caching
This partly reverts If72b18bedac5e580487406e696aea1fd172ae45b. While it's true that we don't need every filter, that method is public and other code may need fields that we don't need. This way we can encourage the use of this function (which caches the result) instead of direct DB access. Also, the method can currently accept global filters passed as "global-<integer>", but saves them to cache with the same key as local filters (i.e. local filter 15 and external global filter "global-15" are both saved in AbuseFilter::$filterCache[15], which could lead to subtle bug). Change-Id: Ieb04f019453033c275e211cfc9fd68d5d7c392ef
This commit is contained in:
parent
d7629efb7c
commit
3fa6e2d31c
|
@ -16,7 +16,10 @@ class AbuseFilter {
|
|||
public static $statsStoragePeriod = 86400;
|
||||
public static $condLimitEnabled = true;
|
||||
|
||||
/** @var array Map of (filter ID => stdClass) */
|
||||
/**
|
||||
* @var array [filter ID => stdClass|null] as retrieved from self::getFilter. ID could be either
|
||||
* an integer or "global-<integer>"
|
||||
*/
|
||||
private static $filterCache = [];
|
||||
|
||||
public static $condCount = 0;
|
||||
|
@ -1219,12 +1222,13 @@ class AbuseFilter {
|
|||
|
||||
/**
|
||||
* @param string $id Filter ID (integer or "global-<integer>")
|
||||
* @return stdClass|null DB row
|
||||
* @return stdClass|null DB row on success, null on failure
|
||||
*/
|
||||
public static function getFilter( $id ) {
|
||||
global $wgAbuseFilterCentralDB;
|
||||
|
||||
if ( !isset( self::$filterCache[$id] ) ) {
|
||||
$filterID = $id;
|
||||
$globalIndex = self::decodeGlobalName( $id );
|
||||
if ( $globalIndex ) {
|
||||
// Global wiki filter
|
||||
|
@ -1232,7 +1236,7 @@ class AbuseFilter {
|
|||
return null;
|
||||
}
|
||||
|
||||
$id = $globalIndex;
|
||||
$filterID = $globalIndex;
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
$lb = $lbFactory->getMainLB( $wgAbuseFilterCentralDB );
|
||||
$dbr = $lb->getConnectionRef( DB_REPLICA, [], $wgAbuseFilterCentralDB );
|
||||
|
@ -1241,17 +1245,10 @@ class AbuseFilter {
|
|||
$dbr = wfGetDB( DB_REPLICA );
|
||||
}
|
||||
|
||||
$fields = [
|
||||
'af_id',
|
||||
'af_pattern',
|
||||
'af_public_comments',
|
||||
'af_timestamp'
|
||||
];
|
||||
|
||||
$row = $dbr->selectRow(
|
||||
'abuse_filter',
|
||||
$fields,
|
||||
[ 'af_id' => $id ],
|
||||
'*',
|
||||
[ 'af_id' => $filterID ],
|
||||
__METHOD__
|
||||
);
|
||||
self::$filterCache[$id] = $row ?: null;
|
||||
|
|
Loading…
Reference in a new issue