MediaWiki  master
cleanupWatchlist.php
Go to the documentation of this file.
1 <?php
33 
34 require_once __DIR__ . '/cleanupTable.inc';
35 
42  protected $defaultParams = [
43  'table' => 'watchlist',
44  'index' => [ 'wl_id' ],
45  'conds' => [],
46  'callback' => 'processRow'
47  ];
48 
49  public function __construct() {
50  parent::__construct();
51  $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
52  $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
53  }
54 
55  public function execute() {
56  if ( !$this->hasOption( 'fix' ) ) {
57  $this->output( "Dry run only: use --fix to enable updates\n" );
58  }
59  parent::execute();
60  }
61 
62  protected function processRow( $row ) {
63  $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
64  $display = $current->getPrefixedText();
65  $verified = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $display );
66  $title = Title::newFromText( $verified );
67 
68  if ( $row->wl_user == 0 || $title === null || !$title->equals( $current ) ) {
69  $this->output( "invalid watch by {$row->wl_user} for "
70  . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
71  $updated = $this->removeWatch( $row );
72  $this->progress( $updated );
73 
74  return;
75  }
76  $this->progress( 0 );
77  }
78 
79  private function removeWatch( $row ) {
80  if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
81  $dbw = $this->getDB( DB_MASTER );
82  $dbw->delete(
83  'watchlist',
84  [ 'wl_id' => $row->wl_id ],
85  __METHOD__
86  );
87  if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
88  $dbw->delete(
89  'watchlist_expiry',
90  [ 'we_item' => $row->wl_id ],
91  __METHOD__
92  );
93  }
94 
95  $this->output( "- removed\n" );
96 
97  return 1;
98  } else {
99  return 0;
100  }
101  }
102 }
103 
104 $maintClass = CleanupWatchlist::class;
105 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:329
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:327
CleanupWatchlist\processRow
processRow( $row)
Definition: cleanupWatchlist.php:62
CleanupWatchlist\__construct
__construct()
Default constructor.
Definition: cleanupWatchlist.php:49
Maintenance\getConfig
getConfig()
Definition: Maintenance.php:596
CleanupWatchlist\removeWatch
removeWatch( $row)
Definition: cleanupWatchlist.php:79
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:245
$title
$title
Definition: testCompression.php:38
$maintClass
$maintClass
Definition: cleanupWatchlist.php:104
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
DB_MASTER
const DB_MASTER
Definition: defines.php:26
TableCleanup\progress
progress( $updated)
Definition: cleanupTable.inc:78
TableCleanup
Generic class to cleanup a database table.
Definition: cleanupTable.inc:31
CleanupWatchlist\execute
execute()
Do the actual work.
Definition: cleanupWatchlist.php:55
CleanupWatchlist\$defaultParams
$defaultParams
Definition: cleanupWatchlist.php:42
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1366
CleanupWatchlist
Maintenance script to remove broken, unparseable titles in the watchlist table.
Definition: cleanupWatchlist.php:41
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:266
TableCleanup\$updated
$updated
Definition: cleanupTable.inc:42