resources: Collapse all jQuery UI modules into one deprecated mega-module
[lhc/web/wiklou.git] / maintenance / cleanupWatchlist.php
1 <?php
2 /**
3 * Remove broken, unparseable titles in the watchlist table.
4 *
5 * Usage: php cleanupWatchlist.php [--fix]
6 * Options:
7 * --fix Actually remove entries; without will only report.
8 *
9 * Copyright © 2005,2006 Brion Vibber <brion@pobox.com>
10 * https://www.mediawiki.org/
11 *
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.
16 *
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.
21 *
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
26 *
27 * @file
28 * @author Brion Vibber <brion at pobox.com>
29 * @ingroup Maintenance
30 */
31
32 use MediaWiki\MediaWikiServices;
33
34 require_once __DIR__ . '/cleanupTable.inc';
35
36 /**
37 * Maintenance script to remove broken, unparseable titles in the watchlist table.
38 *
39 * @ingroup Maintenance
40 */
41 class CleanupWatchlist extends TableCleanup {
42 protected $defaultParams = [
43 'table' => 'watchlist',
44 'index' => [ 'wl_user', 'wl_namespace', 'wl_title' ],
45 'conds' => [],
46 'callback' => 'processRow'
47 ];
48
49 public function __construct() {
50 parent::__construct();
51 $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
52 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
53 }
54
55 function execute() {
56 if ( !$this->hasOption( 'fix' ) ) {
57 $this->output( "Dry run only: use --fix to enable updates\n" );
58 }
59 parent::execute();
60 }
61
62 protected function processRow( $row ) {
63 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
64 $display = $current->getPrefixedText();
65 $verified = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $display );
66 $title = Title::newFromText( $verified );
67
68 if ( $row->wl_user == 0 || is_null( $title ) || !$title->equals( $current ) ) {
69 $this->output( "invalid watch by {$row->wl_user} for "
70 . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
71 $updated = $this->removeWatch( $row );
72 $this->progress( $updated );
73
74 return;
75 }
76 $this->progress( 0 );
77 }
78
79 private function removeWatch( $row ) {
80 if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
81 $dbw = $this->getDB( DB_MASTER );
82 $dbw->delete(
83 'watchlist', [
84 'wl_user' => $row->wl_user,
85 'wl_namespace' => $row->wl_namespace,
86 'wl_title' => $row->wl_title ],
87 __METHOD__
88 );
89
90 $this->output( "- removed\n" );
91
92 return 1;
93 } else {
94 return 0;
95 }
96 }
97 }
98
99 $maintClass = CleanupWatchlist::class;
100 require_once RUN_MAINTENANCE_IF_MAIN;