| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
use MediaWiki\Parser\ParserOptions; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
class CheckSignatures extends Maintenance { |
| 30 |
|
| 31 |
public function __construct() { |
| 32 |
parent::__construct(); |
| 33 |
$this->addDescription( 'List users with invalid signatures' ); |
| 34 |
$this->setBatchSize( 1000 ); |
| 35 |
} |
| 36 |
|
| 37 |
public function execute() { |
| 38 |
$dbr = $this->getReplicaDB(); |
| 39 |
$userFactory = $this->getServiceContainer()->getUserIdentityLookup(); |
| 40 |
$userOptions = $this->getServiceContainer()->getUserOptionsLookup(); |
| 41 |
$signatureValidatorFactory = $this->getServiceContainer()->getSignatureValidatorFactory(); |
| 42 |
$contentLanguage = $this->getServiceContainer()->getContentLanguage(); |
| 43 |
|
| 44 |
$count = 0; |
| 45 |
$maxUserId = 0; |
| 46 |
do { |
| 47 |
|
| 48 |
$res = $dbr->newSelectQueryBuilder() |
| 49 |
->from( 'user_properties' ) |
| 50 |
->select( 'up_user' ) |
| 51 |
->where( [ 'up_property' => 'fancysig' ] ) |
| 52 |
->andWhere( $dbr->expr( 'up_user', '>', $maxUserId ) ) |
| 53 |
->orderBy( [ 'up_property', 'up_user' ] ) |
| 54 |
->limit( $this->getBatchSize() ) |
| 55 |
->caller( __METHOD__ ) |
| 56 |
->fetchResultSet(); |
| 57 |
|
| 58 |
foreach ( $res as $row ) { |
| 59 |
|
| 60 |
$user = $userFactory->getUserIdentityByUserId( $row->up_user ); |
| 61 |
if ( !$user ) { |
| 62 |
continue; |
| 63 |
} |
| 64 |
$signature = $userOptions->getOption( $user, 'nickname' ); |
| 65 |
$useFancySig = $userOptions->getBoolOption( $user, 'fancysig' ); |
| 66 |
if ( $useFancySig && $signature !== '' ) { |
| 67 |
$parserOpts = new ParserOptions( $user, $contentLanguage ); |
| 68 |
$validator = $signatureValidatorFactory->newSignatureValidator( $user, null, $parserOpts ); |
| 69 |
$signatureErrors = $validator->validateSignature( $signature ); |
| 70 |
if ( $signatureErrors ) { |
| 71 |
$count++; |
| 72 |
$this->output( $user->getName() . "\n" ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
$maxUserId = $row->up_user; |
| 77 |
} |
| 78 |
} while ( $res->numRows() ); |
| 79 |
|
| 80 |
$this->output( "-- $count invalid signatures --\n" ); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
$maintClass = CheckSignatures::class; |
| 86 |
|