mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-12-18 16:41:08 +00:00
d2fc2ff8bb
Follows-up Iaa1b4683c5c856. * Match $IP pattern verbatim from most other WMF extensions. * Improve descriptions a bit, and move/merge any meaningful information from file docblock into class docblock. The file blocks are visually ignored and identical in each file, and often out of date or duplicated when given text separately from the class block. See also similar changes in core: https://gerrit.wikimedia.org/r/q/message:ingroup+owner:Krinkle * Use `@internal` instead of `@private` as per Stable interface policy. Change-Id: I8bed9a625af003446c7e25f6b794931164767b5a
79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Maintenance;
|
|
|
|
use Maintenance;
|
|
|
|
// @codeCoverageIgnoreStart
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
if ( $IP === false ) {
|
|
$IP = __DIR__ . '/../../..';
|
|
}
|
|
require_once "$IP/maintenance/Maintenance.php";
|
|
// @codeCoverageIgnoreEnd
|
|
|
|
class SearchFilters extends Maintenance {
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->addDescription( 'Find all filters matching a regular expression pattern' );
|
|
$this->addOption( 'pattern', 'Regular expression pattern', true, true );
|
|
|
|
$this->requireExtension( 'Abuse Filter' );
|
|
}
|
|
|
|
/**
|
|
* @see Maintenance:execute()
|
|
*/
|
|
public function execute() {
|
|
global $wgConf, $wgDBtype;
|
|
|
|
if ( $wgDBtype !== 'mysql' ) {
|
|
// Code using exit() cannot be tested (T272241)
|
|
// @codeCoverageIgnoreStart
|
|
$this->fatalError( 'This maintenance script only works with MySQL databases' );
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
|
|
$this->output( "wiki\tfilter\n" );
|
|
if ( $this->getOption( 'pattern' ) === '' ) {
|
|
// Code using exit() cannot be tested (T272241)
|
|
// @codeCoverageIgnoreStart
|
|
$this->fatalError( 'Pattern cannot be empty' );
|
|
// @codeCoverageIgnoreEnd
|
|
}
|
|
|
|
if ( count( $wgConf->wikis ) > 0 ) {
|
|
foreach ( $wgConf->wikis as $dbname ) {
|
|
$this->getMatchingFilters( $dbname );
|
|
}
|
|
} else {
|
|
$this->getMatchingFilters();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param string|false $dbname Name of database, or false if the wiki is not part of a wikifarm
|
|
*/
|
|
public function getMatchingFilters( $dbname = false ) {
|
|
$dbr = wfGetDB( DB_REPLICA, [], $dbname );
|
|
$pattern = $dbr->addQuotes( $this->getOption( 'pattern' ) );
|
|
|
|
if ( $dbr->tableExists( 'abuse_filter' ) ) {
|
|
$rows = $dbr->select(
|
|
'abuse_filter',
|
|
'DATABASE() AS dbname, af_id',
|
|
[
|
|
"af_pattern RLIKE $pattern"
|
|
]
|
|
);
|
|
|
|
foreach ( $rows as $row ) {
|
|
$this->output( $row->dbname . "\t" . $row->af_id . "\n" );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$maintClass = SearchFilters::class;
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|