MediaWiki  REL1_24
cleanupWatchlist.php
Go to the documentation of this file.
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 "
00069                 . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
00070             $updated = $this->removeWatch( $row );
00071             $this->progress( $updated );
00072 
00073             return;
00074         }
00075         $this->progress( 0 );
00076     }
00077 
00078     private function removeWatch( $row ) {
00079         if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
00080             $dbw = wfGetDB( DB_MASTER );
00081             $dbw->delete(
00082                 'watchlist', array(
00083                 'wl_user' => $row->wl_user,
00084                 'wl_namespace' => $row->wl_namespace,
00085                 'wl_title' => $row->wl_title ),
00086                 __METHOD__
00087             );
00088 
00089             $this->output( "- removed\n" );
00090 
00091             return 1;
00092         } else {
00093             return 0;
00094         }
00095     }
00096 }
00097 
00098 $maintClass = "WatchlistCleanup";
00099 require_once RUN_MAINTENANCE_IF_MAIN;