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