Update git submodules
[mediawiki.git] / maintenance / cleanupWatchlist.php
blob0c7ae1112b909138166d6b06b0081bde539d642d
1 <?php
2 /**
3 * Remove broken, unparseable titles in the watchlist table.
5 * Usage: php cleanupWatchlist.php [--fix]
6 * Options:
7 * --fix Actually remove entries; without will only report.
9 * Copyright © 2005,2006 Brion Vibber <brion@pobox.com>
10 * https://www.mediawiki.org/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * http://www.gnu.org/copyleft/gpl.html
27 * @file
28 * @author Brion Vibber <brion at pobox.com>
29 * @ingroup Maintenance
32 use MediaWiki\MainConfigNames;
33 use MediaWiki\Title\Title;
35 require_once __DIR__ . '/TableCleanup.php';
37 /**
38 * Maintenance script to remove broken, unparseable titles in the watchlist table.
40 * @ingroup Maintenance
42 class CleanupWatchlist extends TableCleanup {
43 protected $defaultParams = [
44 'table' => 'watchlist',
45 'index' => [ 'wl_id' ],
46 'conds' => [],
47 'callback' => 'processRow'
50 public function __construct() {
51 parent::__construct();
52 $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
53 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
56 public function execute() {
57 if ( !$this->hasOption( 'fix' ) ) {
58 $this->output( "Dry run only: use --fix to enable updates\n" );
60 parent::execute();
63 protected function processRow( $row ) {
64 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
65 $display = $current->getPrefixedText();
66 $verified = $this->getServiceContainer()->getContentLanguage()->normalize( $display );
67 $title = Title::newFromText( $verified );
69 if ( $row->wl_user == 0 || $title === null || !$title->equals( $current ) ) {
70 $this->output( "invalid watch by {$row->wl_user} for "
71 . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
72 $updated = $this->removeWatch( $row );
73 $this->progress( $updated );
75 return;
77 $this->progress( 0 );
80 private function removeWatch( $row ) {
81 if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
82 $dbw = $this->getDB( DB_PRIMARY );
83 $dbw->delete(
84 'watchlist',
85 [ 'wl_id' => $row->wl_id ],
86 __METHOD__
88 if ( $this->getConfig()->get( MainConfigNames::WatchlistExpiry ) ) {
89 $dbw->delete(
90 'watchlist_expiry',
91 [ 'we_item' => $row->wl_id ],
92 __METHOD__
96 $this->output( "- removed\n" );
98 return 1;
99 } else {
100 return 0;
105 $maintClass = CleanupWatchlist::class;
106 require_once RUN_MAINTENANCE_IF_MAIN;