Fixing bug 20524: Hideuser: Nicer error when trying to block hidden user without...
[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 * @author Brion Vibber <brion at pobox.com>
28 * @ingroup Maintenance
29 */
30
31 require_once( dirname(__FILE__) . '/cleanupTable.inc' );
32
33 class WatchlistCleanup extends TableCleanup {
34 protected $defaultParams = array(
35 'table' => 'watchlist',
36 'index' => array( 'wl_user', 'wl_namespace', 'wl_title' ),
37 'conds' => array(),
38 'callback' => 'processRow'
39 );
40
41 public function __construct() {
42 parent::__construct();
43 $this->mDescription = "Script to remove broken, unparseable titles in the Watchlist";
44 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
45 }
46
47 function execute() {
48 if ( !$this->hasOption( 'fix' ) ) {
49 $this->output( "Dry run only: use --fix to enable updates\n" );
50 }
51 parent::execute();
52 }
53
54 protected function processRow( $row ) {
55 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
56 $display = $current->getPrefixedText();
57 $verified = UtfNormal::cleanUp( $display );
58 $title = Title::newFromText( $verified );
59
60 if( $row->wl_user == 0 || is_null( $title ) || !$title->equals( $current ) ) {
61 $this->output( "invalid watch by {$row->wl_user} for ({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
62 $updated = $this->removeWatch( $row );
63 $this->progress( $updated );
64 return;
65 }
66 $this->progress( 0 );
67 }
68
69 private function removeWatch( $row ) {
70 if( !$this->dryrun && $this->hasOption( 'fix' ) ) {
71 $dbw = wfGetDB( DB_MASTER );
72 $dbw->delete( 'watchlist', array(
73 'wl_user' => $row->wl_user,
74 'wl_namespace' => $row->wl_namespace,
75 'wl_title' => $row->wl_title ),
76 __METHOD__ );
77 $this->output( "- removed\n" );
78 return 1;
79 } else {
80 return 0;
81 }
82 }
83 }
84
85 $maintClass = "WatchlistCleanup";
86 require_once( DO_MAINTENANCE );