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