MediaWiki
REL1_22
|
00001 <?php 00032 require_once __DIR__ . '/cleanupTable.inc'; 00033 00039 class WatchlistCleanup extends TableCleanup { 00040 protected $defaultParams = array( 00041 'table' => 'watchlist', 00042 'index' => array( 'wl_user', 'wl_namespace', 'wl_title' ), 00043 'conds' => array(), 00044 'callback' => 'processRow' 00045 ); 00046 00047 public function __construct() { 00048 parent::__construct(); 00049 $this->mDescription = "Script to remove broken, unparseable titles in the Watchlist"; 00050 $this->addOption( 'fix', 'Actually remove entries; without will only report.' ); 00051 } 00052 00053 function execute() { 00054 if ( !$this->hasOption( 'fix' ) ) { 00055 $this->output( "Dry run only: use --fix to enable updates\n" ); 00056 } 00057 parent::execute(); 00058 } 00059 00060 protected function processRow( $row ) { 00061 global $wgContLang; 00062 $current = Title::makeTitle( $row->wl_namespace, $row->wl_title ); 00063 $display = $current->getPrefixedText(); 00064 $verified = $wgContLang->normalize( $display ); 00065 $title = Title::newFromText( $verified ); 00066 00067 if ( $row->wl_user == 0 || is_null( $title ) || !$title->equals( $current ) ) { 00068 $this->output( "invalid watch by {$row->wl_user} for ({$row->wl_namespace}, \"{$row->wl_title}\")\n" ); 00069 $updated = $this->removeWatch( $row ); 00070 $this->progress( $updated ); 00071 return; 00072 } 00073 $this->progress( 0 ); 00074 } 00075 00076 private function removeWatch( $row ) { 00077 if ( !$this->dryrun && $this->hasOption( 'fix' ) ) { 00078 $dbw = wfGetDB( DB_MASTER ); 00079 $dbw->delete( 'watchlist', array( 00080 'wl_user' => $row->wl_user, 00081 'wl_namespace' => $row->wl_namespace, 00082 'wl_title' => $row->wl_title ), 00083 __METHOD__ ); 00084 $this->output( "- removed\n" ); 00085 return 1; 00086 } else { 00087 return 0; 00088 } 00089 } 00090 } 00091 00092 $maintClass = "WatchlistCleanup"; 00093 require_once RUN_MAINTENANCE_IF_MAIN;