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
{
46 protected $defaultParams = [
47 'table' => 'watchlist',
48 'index' => [ 'wl_id' ],
50 'callback' => 'processRow'
53 public function __construct() {
54 parent
::__construct();
55 $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
56 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
59 public function execute() {
60 if ( !$this->hasOption( 'fix' ) ) {
61 $this->output( "Dry run only: use --fix to enable updates\n" );
66 protected function processRow( $row ) {
67 $current = Title
::makeTitle( $row->wl_namespace
, $row->wl_title
);
68 $display = $current->getPrefixedText();
69 $verified = $this->getServiceContainer()->getContentLanguage()->normalize( $display );
70 $title = Title
::newFromText( $verified );
72 if ( $row->wl_user
== 0 ||
$title === null ||
!$title->equals( $current ) ) {
73 $this->output( "invalid watch by {$row->wl_user} for "
74 . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
75 $updated = $this->removeWatch( $row );
76 $this->progress( $updated );
83 private function removeWatch( $row ) {
84 if ( !$this->dryrun
&& $this->hasOption( 'fix' ) ) {
85 $dbw = $this->getPrimaryDB();
86 $dbw->newDeleteQueryBuilder()
87 ->deleteFrom( 'watchlist' )
88 ->where( [ 'wl_id' => $row->wl_id
] )
89 ->caller( __METHOD__
)
91 if ( $this->getConfig()->get( MainConfigNames
::WatchlistExpiry
) ) {
92 $dbw->newDeleteQueryBuilder()
93 ->deleteFrom( 'watchlist_expiry' )
94 ->where( [ 'we_item' => $row->wl_id
] )
95 ->caller( __METHOD__
)
99 $this->output( "- removed\n" );
108 // @codeCoverageIgnoreStart
109 $maintClass = CleanupWatchlist
::class;
110 require_once RUN_MAINTENANCE_IF_MAIN
;
111 // @codeCoverageIgnoreEnd