Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CheckSignatures
0.00% covered (danger)
0.00%
0 / 35
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Maintenance
20 */
21
22/**
23 * Maintenance script to list users with invalid signatures.
24 *
25 * @ingroup Maintenance
26 */
27class CheckSignatures extends Maintenance {
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$maintClass = CheckSignatures::class;