MediaWiki master
cleanupWatchlist.php
Go to the documentation of this file.
1<?php
20
21// @codeCoverageIgnoreStart
22require_once __DIR__ . '/TableCleanup.php';
23// @codeCoverageIgnoreEnd
24
32 protected $defaultParams = [
33 'table' => 'watchlist',
34 'index' => [ 'wl_id' ],
35 'conds' => [],
36 'callback' => 'processRow'
37 ];
38
39 public function __construct() {
40 parent::__construct();
41 $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
42 $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
43 }
44
45 public function execute() {
46 if ( !$this->hasOption( 'fix' ) ) {
47 $this->output( "Dry run only: use --fix to enable updates\n" );
48 }
49 parent::execute();
50 }
51
52 protected function processRow( \stdClass $row ) {
53 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
54 $display = $current->getPrefixedText();
55 $verified = $this->getServiceContainer()->getContentLanguage()->normalize( $display );
56 $title = Title::newFromText( $verified );
57
58 if ( $row->wl_user == 0 || $title === null || !$title->equals( $current ) ) {
59 $this->output( "invalid watch by {$row->wl_user} for "
60 . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
61 $updated = $this->removeWatch( $row );
62 $this->progress( $updated );
63
64 return;
65 }
66 $this->progress( 0 );
67 }
68
69 private function removeWatch( \stdClass $row ): int {
70 if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
71 $dbw = $this->getPrimaryDB();
72 $dbw->newDeleteQueryBuilder()
73 ->deleteFrom( 'watchlist' )
74 ->where( [ 'wl_id' => $row->wl_id ] )
75 ->caller( __METHOD__ )
76 ->execute();
77 if ( $this->getConfig()->get( MainConfigNames::WatchlistExpiry ) ) {
78 $dbw->newDeleteQueryBuilder()
79 ->deleteFrom( 'watchlist_expiry' )
80 ->where( [ 'we_item' => $row->wl_id ] )
81 ->caller( __METHOD__ )
82 ->execute();
83 }
84
85 $this->output( "- removed\n" );
86
87 return 1;
88 } else {
89 return 0;
90 }
91 }
92}
93
94// @codeCoverageIgnoreStart
95$maintClass = CleanupWatchlist::class;
96require_once RUN_MAINTENANCE_IF_MAIN;
97// @codeCoverageIgnoreEnd
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
Maintenance script to remove broken, unparseable titles in the watchlist table.
execute()
Do the actual work.
processRow(\stdClass $row)
__construct()
Default constructor.
A class containing constants representing the names of configuration variables.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
Represents a title within MediaWiki.
Definition Title.php:69
Generic class to cleanup a database table.
progress( $updated)