| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
> |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
use MediaWiki\MainConfigNames; |
| 33 |
use MediaWiki\Title\Title; |
| 34 |
|
| 35 |
|
| 36 |
require_once __DIR__ . '/TableCleanup.php'; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
class CleanupWatchlist extends TableCleanup { |
| 45 |
|
| 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 |
|
| 109 |
$maintClass = CleanupWatchlist::class; |
| 110 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 111 |
|