Made WatchlistCleanup and CapsCleanup extend TableCleanup rather than FiveUpgrade...
[lhc/web/wiklou.git] / maintenance / cleanupWatchlist.php
1 <?php
2 /*
3 * Script to remove broken, unparseable titles in the Watchlist.
4 *
5 * Usage: php cleanupWatchlist.php [--fix]
6 * Options:
7 * --fix Actually remove entries; without will only report.
8 *
9 * Copyright (C) 2005,2006 Brion Vibber <brion@pobox.com>
10 * http://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 require_once( 'commandLine.inc' );
33 require_once( 'CleanupTable.inc' );
34
35 /**
36 * @ingroup Maintenance
37 */
38 class WatchlistCleanup extends TableCleanup {
39 function __construct( $dryrun = false ) {
40 parent::__construct( 'watchlist', $dryrun );
41 }
42
43 function processPage( $row ) {
44 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
45 $display = $current->getPrefixedText();
46
47 $verified = UtfNormal::cleanUp( $display );
48
49 $title = Title::newFromText( $verified );
50
51 if( $row->wl_user == 0 || is_null( $title ) || !$title->equals( $current ) ) {
52 $this->log( "invalid watch by {$row->wl_user} for ({$row->wl_namespace}, \"{$row->wl_title}\")" );
53 $this->removeWatch( $row );
54 return $this->progress( 1 );
55 }
56
57 $this->progress( 0 );
58 }
59
60 function removeWatch( $row ) {
61 if( !$this->dryrun ) {
62 $dbw = wfGetDB( DB_MASTER );
63 $dbw->delete( 'watchlist', array(
64 'wl_user' => $row->wl_user,
65 'wl_namespace' => $row->wl_namespace,
66 'wl_title' => $row->wl_title ),
67 __METHOD__ );
68 $this->log( '- removed' );
69 }
70 }
71 }
72
73 $wgUser->setName( 'Conversion script' );
74 $caps = new WatchlistCleanup( !isset( $options['fix'] ) );
75 $caps->cleanup();
76
77