3 * Remove broken, unparseable titles in the watchlist table.
5 * Usage: php cleanupWatchlist.php [--fix]
7 * --fix Actually remove entries; without will only report.
9 * Copyright © 2005,2006 Brooke Vibber <bvibber@wikimedia.org>
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
28 * @author Brooke Vibber <bvibber@wikimedia.org>
29 * @ingroup Maintenance
32 use MediaWiki\MainConfigNames
;
33 use MediaWiki\Title\Title
;
35 // @codeCoverageIgnoreStart
36 require_once __DIR__
. '/TableCleanup.php';
37 // @codeCoverageIgnoreEnd
40 * Maintenance script to remove broken, unparseable titles in the watchlist table.
42 * @ingroup Maintenance
44 class CleanupWatchlist
extends TableCleanup
{
45 protected $defaultParams = [
46 'table' => 'watchlist',
47 'index' => [ 'wl_id' ],
49 'callback' => 'processRow'
52 public function __construct() {
53 parent
::__construct();
54 $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
55 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
58 public function execute() {
59 if ( !$this->hasOption( 'fix' ) ) {
60 $this->output( "Dry run only: use --fix to enable updates\n" );
65 protected function processRow( $row ) {
66 $current = Title
::makeTitle( $row->wl_namespace
, $row->wl_title
);
67 $display = $current->getPrefixedText();
68 $verified = $this->getServiceContainer()->getContentLanguage()->normalize( $display );
69 $title = Title
::newFromText( $verified );
71 if ( $row->wl_user
== 0 ||
$title === null ||
!$title->equals( $current ) ) {
72 $this->output( "invalid watch by {$row->wl_user} for "
73 . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
74 $updated = $this->removeWatch( $row );
75 $this->progress( $updated );
82 private function removeWatch( $row ) {
83 if ( !$this->dryrun
&& $this->hasOption( 'fix' ) ) {
84 $dbw = $this->getPrimaryDB();
85 $dbw->newDeleteQueryBuilder()
86 ->deleteFrom( 'watchlist' )
87 ->where( [ 'wl_id' => $row->wl_id
] )
88 ->caller( __METHOD__
)
90 if ( $this->getConfig()->get( MainConfigNames
::WatchlistExpiry
) ) {
91 $dbw->newDeleteQueryBuilder()
92 ->deleteFrom( 'watchlist_expiry' )
93 ->where( [ 'we_item' => $row->wl_id
] )
94 ->caller( __METHOD__
)
98 $this->output( "- removed\n" );
107 // @codeCoverageIgnoreStart
108 $maintClass = CleanupWatchlist
::class;
109 require_once RUN_MAINTENANCE_IF_MAIN
;
110 // @codeCoverageIgnoreEnd