2020-09-08 13:22:01 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-02 13:49:41 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Maintenance;
|
|
|
|
|
|
|
|
use Maintenance;
|
|
|
|
|
2021-01-17 11:54:43 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2022-09-29 16:54:36 +00:00
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
2020-09-08 13:22:01 +00:00
|
|
|
$IP = __DIR__ . '/../../..';
|
|
|
|
}
|
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
2021-01-17 11:54:43 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2020-09-08 13:22:01 +00:00
|
|
|
|
|
|
|
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' ) {
|
2021-01-17 11:54:43 +00:00
|
|
|
// Code using exit() cannot be tested (T272241)
|
|
|
|
// @codeCoverageIgnoreStart
|
2020-09-08 13:22:01 +00:00
|
|
|
$this->fatalError( 'This maintenance script only works with MySQL databases' );
|
2021-01-17 11:54:43 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2020-09-08 13:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->output( "wiki\tfilter\n" );
|
|
|
|
if ( $this->getOption( 'pattern' ) === '' ) {
|
2021-01-17 11:54:43 +00:00
|
|
|
// Code using exit() cannot be tested (T272241)
|
|
|
|
// @codeCoverageIgnoreStart
|
2020-09-08 13:22:01 +00:00
|
|
|
$this->fatalError( 'Pattern cannot be empty' );
|
2021-01-17 11:54:43 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2020-09-08 13:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ) {
|
2023-03-03 17:32:00 +00:00
|
|
|
$dbr = $this->getDB( DB_REPLICA, [], $dbname );
|
2020-09-08 13:22:01 +00:00
|
|
|
$pattern = $dbr->addQuotes( $this->getOption( 'pattern' ) );
|
|
|
|
|
|
|
|
if ( $dbr->tableExists( 'abuse_filter' ) ) {
|
|
|
|
$rows = $dbr->select(
|
|
|
|
'abuse_filter',
|
2023-03-03 17:32:00 +00:00
|
|
|
[ 'dbname' => 'DATABASE()', 'af_id' ],
|
2020-09-08 13:22:01 +00:00
|
|
|
[
|
|
|
|
"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;
|