Merge "Make line breaks in <blockquote> behave like <div> (bug 6200)."
[mediawiki.git] / maintenance / cleanupWatchlist.php
blobf1a7b481ac161534d2392f5540bf8990e25e492a
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 * http://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 require_once __DIR__ . '/cleanupTable.inc';
34 /**
35 * Maintenance script to remove broken, unparseable titles in the watchlist table.
37 * @ingroup Maintenance
39 class WatchlistCleanup extends TableCleanup {
40 protected $defaultParams = array(
41 'table' => 'watchlist',
42 'index' => array( 'wl_user', 'wl_namespace', 'wl_title' ),
43 'conds' => array(),
44 'callback' => 'processRow'
47 public function __construct() {
48 parent::__construct();
49 $this->mDescription = "Script to remove broken, unparseable titles in the Watchlist";
50 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
53 function execute() {
54 if ( !$this->hasOption( 'fix' ) ) {
55 $this->output( "Dry run only: use --fix to enable updates\n" );
57 parent::execute();
60 protected function processRow( $row ) {
61 global $wgContLang;
62 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
63 $display = $current->getPrefixedText();
64 $verified = $wgContLang->normalize( $display );
65 $title = Title::newFromText( $verified );
67 if ( $row->wl_user == 0 || is_null( $title ) || !$title->equals( $current ) ) {
68 $this->output( "invalid watch by {$row->wl_user} for ({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
69 $updated = $this->removeWatch( $row );
70 $this->progress( $updated );
71 return;
73 $this->progress( 0 );
76 private function removeWatch( $row ) {
77 if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
78 $dbw = wfGetDB( DB_MASTER );
79 $dbw->delete( 'watchlist', array(
80 'wl_user' => $row->wl_user,
81 'wl_namespace' => $row->wl_namespace,
82 'wl_title' => $row->wl_title ),
83 __METHOD__ );
84 $this->output( "- removed\n" );
85 return 1;
86 } else {
87 return 0;
92 $maintClass = "WatchlistCleanup";
93 require_once RUN_MAINTENANCE_IF_MAIN;