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 ->fetchResultSet();
54
55 foreach ( $res as $row ) {
56 // Double-check effective preferences and check validation
57 $user = $userFactory->getUserIdentityByUserId( $row->up_user );
58 if ( !$user ) {
59 continue;
60 }
61 $signature = $userOptions->getOption( $user, 'nickname' );
62 $useFancySig = $userOptions->getBoolOption( $user, 'fancysig' );
63 if ( $useFancySig && $signature !== '' ) {
64 $parserOpts = new ParserOptions( $user, $contentLanguage );
65 $validator = $signatureValidatorFactory->newSignatureValidator( $user, null, $parserOpts );
66 $signatureErrors = $validator->validateSignature( $signature );
67 if ( $signatureErrors ) {
68 $count++;
69 $this->output( $user->getName() . "\n" );
70 }
71 }
72
73 $maxUserId = $row->up_user;
74 }
75 } while ( $res->numRows() );
76
77 $this->output( "-- $count invalid signatures --\n" );
78 }
79}
80
81$maintClass = CheckSignatures::class;
$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.