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