MediaWiki master
CheckSignatures.php
Go to the documentation of this file.
1<?php
10
11// @codeCoverageIgnoreStart
12require_once __DIR__ . '/Maintenance.php';
13// @codeCoverageIgnoreEnd
14
21
22 public function __construct() {
23 parent::__construct();
24 $this->addDescription( 'List users with invalid signatures' );
25 $this->setBatchSize( 1000 );
26 }
27
28 public function execute() {
29 $dbr = $this->getReplicaDB();
30 $userFactory = $this->getServiceContainer()->getUserIdentityLookup();
31 $userOptions = $this->getServiceContainer()->getUserOptionsLookup();
32 $signatureValidatorFactory = $this->getServiceContainer()->getSignatureValidatorFactory();
33 $contentLanguage = $this->getServiceContainer()->getContentLanguage();
34
35 $count = 0;
36 $maxUserId = 0;
37 do {
38 // List users who may have a signature that needs validation
39 $res = $dbr->newSelectQueryBuilder()
40 ->from( 'user_properties' )
41 ->select( 'up_user' )
42 ->where( [ 'up_property' => 'fancysig' ] )
43 ->andWhere( $dbr->expr( 'up_user', '>', $maxUserId ) )
44 ->orderBy( [ 'up_property', 'up_user' ] )
45 ->limit( $this->getBatchSize() )
46 ->caller( __METHOD__ )
47 ->fetchResultSet();
48
49 foreach ( $res as $row ) {
50 // Double-check effective preferences and check validation
51 $user = $userFactory->getUserIdentityByUserId( $row->up_user );
52 if ( !$user ) {
53 continue;
54 }
55 $signature = $userOptions->getOption( $user, 'nickname' );
56 $useFancySig = $userOptions->getBoolOption( $user, 'fancysig' );
57 if ( $useFancySig && $signature !== '' ) {
58 $parserOpts = new ParserOptions( $user, $contentLanguage );
59 $validator = $signatureValidatorFactory->newSignatureValidator( $user, null, $parserOpts );
60 $signatureErrors = $validator->validateSignature( $signature );
61 if ( $signatureErrors ) {
62 $count++;
63 $this->output( $user->getName() . "\n" );
64 }
65 }
66
67 $maxUserId = $row->up_user;
68 }
69 } while ( $res->numRows() );
70
71 $this->output( "-- $count invalid signatures --\n" );
72 }
73}
74
75// @codeCoverageIgnoreStart
76$maintClass = CheckSignatures::class;
77require_once RUN_MAINTENANCE_IF_MAIN;
78// @codeCoverageIgnoreEnd
$maintClass
Maintenance script to list users with invalid signatures.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
getReplicaDB(string|false $virtualDomain=false)
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Set options of the Parser.