MediaWiki master
cleanupWatchlist.php
Go to the documentation of this file.
1<?php
34
35// @codeCoverageIgnoreStart
36require_once __DIR__ . '/TableCleanup.php';
37// @codeCoverageIgnoreEnd
38
46 protected $defaultParams = [
47 'table' => 'watchlist',
48 'index' => [ 'wl_id' ],
49 'conds' => [],
50 'callback' => 'processRow'
51 ];
52
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.' );
57 }
58
59 public function execute() {
60 if ( !$this->hasOption( 'fix' ) ) {
61 $this->output( "Dry run only: use --fix to enable updates\n" );
62 }
63 parent::execute();
64 }
65
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 );
71
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 );
77
78 return;
79 }
80 $this->progress( 0 );
81 }
82
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__ )
90 ->execute();
91 if ( $this->getConfig()->get( MainConfigNames::WatchlistExpiry ) ) {
92 $dbw->newDeleteQueryBuilder()
93 ->deleteFrom( 'watchlist_expiry' )
94 ->where( [ 'we_item' => $row->wl_id ] )
95 ->caller( __METHOD__ )
96 ->execute();
97 }
98
99 $this->output( "- removed\n" );
100
101 return 1;
102 } else {
103 return 0;
104 }
105 }
106}
107
108// @codeCoverageIgnoreStart
109$maintClass = CleanupWatchlist::class;
110require_once RUN_MAINTENANCE_IF_MAIN;
111// @codeCoverageIgnoreEnd
Maintenance script to remove broken, unparseable titles in the watchlist table.
execute()
Do the actual work.
__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.
addDescription( $text)
Set the description text.
Represents a title within MediaWiki.
Definition Title.php:78
Generic class to cleanup a database table.
progress( $updated)