MediaWiki REL1_39
cleanupWatchlist.php
Go to the documentation of this file.
1<?php
34
35require_once __DIR__ . '/TableCleanup.php';
36
43 protected $defaultParams = [
44 'table' => 'watchlist',
45 'index' => [ 'wl_id' ],
46 'conds' => [],
47 'callback' => 'processRow'
48 ];
49
50 public function __construct() {
51 parent::__construct();
52 $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
53 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
54 }
55
56 public function execute() {
57 if ( !$this->hasOption( 'fix' ) ) {
58 $this->output( "Dry run only: use --fix to enable updates\n" );
59 }
60 parent::execute();
61 }
62
63 protected function processRow( $row ) {
64 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
65 $display = $current->getPrefixedText();
66 $verified = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $display );
67 $title = Title::newFromText( $verified );
68
69 if ( $row->wl_user == 0 || $title === null || !$title->equals( $current ) ) {
70 $this->output( "invalid watch by {$row->wl_user} for "
71 . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
72 $updated = $this->removeWatch( $row );
73 $this->progress( $updated );
74
75 return;
76 }
77 $this->progress( 0 );
78 }
79
80 private function removeWatch( $row ) {
81 if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
82 $dbw = $this->getDB( DB_PRIMARY );
83 $dbw->delete(
84 'watchlist',
85 [ 'wl_id' => $row->wl_id ],
86 __METHOD__
87 );
88 if ( $this->getConfig()->get( MainConfigNames::WatchlistExpiry ) ) {
89 $dbw->delete(
90 'watchlist_expiry',
91 [ 'we_item' => $row->wl_id ],
92 __METHOD__
93 );
94 }
95
96 $this->output( "- removed\n" );
97
98 return 1;
99 } else {
100 return 0;
101 }
102 }
103}
104
105$maintClass = CleanupWatchlist::class;
106require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
Maintenance script to remove broken, unparseable titles in the watchlist table.
execute()
Do the actual work.
__construct()
Default constructor.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
Generic class to cleanup a database table.
progress( $updated)
const DB_PRIMARY
Definition defines.php:28