MediaWiki  1.33.0
cleanupWatchlist.php
Go to the documentation of this file.
1 <?php
33 
34 require_once __DIR__ . '/cleanupTable.inc';
35 
42  protected $defaultParams = [
43  'table' => 'watchlist',
44  'index' => [ 'wl_user', 'wl_namespace', 'wl_title' ],
45  'conds' => [],
46  'callback' => 'processRow'
47  ];
48 
49  public function __construct() {
50  parent::__construct();
51  $this->addDescription( 'Script to remove broken, unparseable titles in the Watchlist' );
52  $this->addOption( 'fix', 'Actually remove entries; without will only report.' );
53  }
54 
55  function execute() {
56  if ( !$this->hasOption( 'fix' ) ) {
57  $this->output( "Dry run only: use --fix to enable updates\n" );
58  }
60  }
61 
62  protected function processRow( $row ) {
63  $current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
64  $display = $current->getPrefixedText();
65  $verified = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $display );
66  $title = Title::newFromText( $verified );
67 
68  if ( $row->wl_user == 0 || is_null( $title ) || !$title->equals( $current ) ) {
69  $this->output( "invalid watch by {$row->wl_user} for "
70  . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" );
71  $updated = $this->removeWatch( $row );
72  $this->progress( $updated );
73 
74  return;
75  }
76  $this->progress( 0 );
77  }
78 
79  private function removeWatch( $row ) {
80  if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
81  $dbw = $this->getDB( DB_MASTER );
82  $dbw->delete(
83  'watchlist', [
84  'wl_user' => $row->wl_user,
85  'wl_namespace' => $row->wl_namespace,
86  'wl_title' => $row->wl_title ],
87  __METHOD__
88  );
89 
90  $this->output( "- removed\n" );
91 
92  return 1;
93  } else {
94  return 0;
95  }
96  }
97 }
98 
100 require_once RUN_MAINTENANCE_IF_MAIN;
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:306
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
CleanupWatchlist\processRow
processRow( $row)
Definition: cleanupWatchlist.php:62
CleanupWatchlist\__construct
__construct()
Default constructor.
Definition: cleanupWatchlist.php:49
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
CleanupWatchlist\removeWatch
removeWatch( $row)
Definition: cleanupWatchlist.php:79
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:248
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$maintClass
$maintClass
Definition: cleanupWatchlist.php:99
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
DB_MASTER
const DB_MASTER
Definition: defines.php:26
TableCleanup\progress
progress( $updated)
Definition: cleanupTable.inc:74
execute
$batch execute()
TableCleanup
Generic class to cleanup a database table.
Definition: cleanupTable.inc:31
CleanupWatchlist\execute
execute()
Do the actual work.
Definition: cleanupWatchlist.php:55
CleanupWatchlist\$defaultParams
$defaultParams
Definition: cleanupWatchlist.php:42
CleanupWatchlist
Maintenance script to remove broken, unparseable titles in the watchlist table.
Definition: cleanupWatchlist.php:41
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1373
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:269
TableCleanup\$updated
$updated
Definition: cleanupTable.inc:43