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