3 * Purge expired watchlist items, looping through 500 at a time.
6 use MediaWiki\MediaWikiServices
;
8 require_once __DIR__
. '/Maintenance.php';
10 class PurgeExpiredWatchlistItems
extends Maintenance
{
12 public function __construct() {
13 parent
::__construct();
14 $this->addDescription( 'Removes expired items from the watchlist and watchlist_expiry tables.' );
15 $this->setBatchSize( 500 );
21 public function execute() {
22 // Make sure watchlist expiring is enabled.
23 if ( !MediaWikiServices
::getInstance()->getMainConfig()->get( 'WatchlistExpiry' ) ) {
24 $this->error( "Watchlist expiry is not enabled. Set `\$wgWatchlistExpiry = true;` to enable." );
28 // Loop through 500 entries at a time and delete them.
29 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
30 $count = $watchedItemStore->countExpired();
31 $this->output( $count . " expired watchlist entries found.\n" );
33 // None found to delete.
36 while ( $watchedItemStore->countExpired() > 0 ) {
37 $watchedItemStore->removeExpired( $this->getBatchSize(), true );
41 $this->output( "All expired entries purged.\n" );
46 $maintClass = PurgeExpiredWatchlistItems
::class;
47 require_once RUN_MAINTENANCE_IF_MAIN
;