ApiParse: don't reparse language link titles
[mediawiki.git] / maintenance / CheckSignatures.php
blob3e66da5749567e6876eedd36eafe133a4ab2f7a0
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.
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.
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
18 * @file
19 * @ingroup Maintenance
22 /**
23 * Maintenance script to list users with invalid signatures.
25 * @ingroup Maintenance
27 class CheckSignatures extends Maintenance {
29 public function __construct() {
30 parent::__construct();
31 $this->addDescription( 'List users with invalid signatures' );
32 $this->setBatchSize( 1000 );
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();
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();
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;
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" );
74 $maxUserId = $row->up_user;
76 } while ( $res->numRows() );
78 $this->output( "-- $count invalid signatures --\n" );
82 // @codeCoverageIgnoreStart
83 $maintClass = CheckSignatures::class;
84 // @codeCoverageIgnoreEnd