Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 35
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 / 34
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 / 31
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                ->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;