MediaWiki REL1_40
cleanupWatchlist.php
Go to the documentation of this file.
1<?php
35
36require_once __DIR__ . '/TableCleanup.php';
37
44 protected $defaultParams = [
45 'table' => 'watchlist',
46 'index' => [ 'wl_id' ],
47 'conds' => [],
48 'callback' => 'processRow'
49 ];
50
51 public function __construct() {
52 parent::__construct();
53 $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
54 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
55 }
56
57 public function execute() {
58 if ( !$this->hasOption( 'fix' ) ) {
59 $this->output( "Dry run only: use --fix to enable updates\n" );
60 }
61 parent::execute();
62 }
63
64 protected function processRow( $row ) {
65 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
66 $display = $current->getPrefixedText();
67 $verified = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $display );
68 $title = Title::newFromText( $verified );
69
70 if ( $row->wl_user == 0 || $title === null || !$title->equals( $current ) ) {
71 $this->output( "invalid watch by {$row->wl_user} for "
72 . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
73 $updated = $this->removeWatch( $row );
74 $this->progress( $updated );
75
76 return;
77 }
78 $this->progress( 0 );
79 }
80
81 private function removeWatch( $row ) {
82 if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
83 $dbw = $this->getDB( DB_PRIMARY );
84 $dbw->delete(
85 'watchlist',
86 [ 'wl_id' => $row->wl_id ],
87 __METHOD__
88 );
89 if ( $this->getConfig()->get( MainConfigNames::WatchlistExpiry ) ) {
90 $dbw->delete(
91 'watchlist_expiry',
92 [ 'we_item' => $row->wl_id ],
93 __METHOD__
94 );
95 }
96
97 $this->output( "- removed\n" );
98
99 return 1;
100 } else {
101 return 0;
102 }
103 }
104}
105
106$maintClass = CleanupWatchlist::class;
107require_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.
Represents a title within MediaWiki.
Definition Title.php:82
Generic class to cleanup a database table.
progress( $updated)
const DB_PRIMARY
Definition defines.php:28