MediaWiki  1.23.2
cleanupWatchlist.php
Go to the documentation of this file.
1 <?php
32 require_once __DIR__ . '/cleanupTable.inc';
33 
40  protected $defaultParams = array(
41  'table' => 'watchlist',
42  'index' => array( 'wl_user', 'wl_namespace', 'wl_title' ),
43  'conds' => array(),
44  'callback' => 'processRow'
45  );
46 
47  public function __construct() {
48  parent::__construct();
49  $this->mDescription = "Script to remove broken, unparseable titles in the Watchlist";
50  $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
51  }
52 
53  function execute() {
54  if ( !$this->hasOption( 'fix' ) ) {
55  $this->output( "Dry run only: use --fix to enable updates\n" );
56  }
58  }
59 
60  protected function processRow( $row ) {
62  $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
63  $display = $current->getPrefixedText();
64  $verified = $wgContLang->normalize( $display );
65  $title = Title::newFromText( $verified );
66 
67  if ( $row->wl_user == 0 || is_null( $title ) || !$title->equals( $current ) ) {
68  $this->output( "invalid watch by {$row->wl_user} for ({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
69  $updated = $this->removeWatch( $row );
70  $this->progress( $updated );
71  return;
72  }
73  $this->progress( 0 );
74  }
75 
76  private function removeWatch( $row ) {
77  if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
78  $dbw = wfGetDB( DB_MASTER );
79  $dbw->delete( 'watchlist', array(
80  'wl_user' => $row->wl_user,
81  'wl_namespace' => $row->wl_namespace,
82  'wl_title' => $row->wl_title ),
83  __METHOD__ );
84  $this->output( "- removed\n" );
85  return 1;
86  } else {
87  return 0;
88  }
89  }
90 }
91 
92 $maintClass = "WatchlistCleanup";
93 require_once RUN_MAINTENANCE_IF_MAIN;
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
WatchlistCleanup\removeWatch
removeWatch( $row)
Definition: cleanupWatchlist.php:76
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$maintClass
$maintClass
Definition: cleanupWatchlist.php:92
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
TableCleanup\progress
progress( $updated)
Definition: cleanupTable.inc:74
execute
$batch execute()
TableCleanup
Generic class to cleanup a database table.
Definition: cleanupTable.inc:31
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
WatchlistCleanup\execute
execute()
Do the actual work.
Definition: cleanupWatchlist.php:53
WatchlistCleanup
Maintenance script to remove broken, unparseable titles in the watchlist table.
Definition: cleanupWatchlist.php:39
WatchlistCleanup\$defaultParams
$defaultParams
Definition: cleanupWatchlist.php:40
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
WatchlistCleanup\processRow
processRow( $row)
Definition: cleanupWatchlist.php:60
WatchlistCleanup\__construct
__construct()
Default constructor.
Definition: cleanupWatchlist.php:47
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
TableCleanup\$updated
$updated
Definition: cleanupTable.inc:44