33require_once __DIR__ .
'/Maintenance.php';
43 parent::__construct();
45 $this->
addOption(
'u',
"User to perform deletion",
false,
true );
46 $this->
addOption(
'r',
"Reason to delete page",
false,
true );
47 $this->
addOption(
'i',
"Interval to sleep between deletions" );
48 $this->
addArg(
'listfile',
'File with titles to delete, separated by newlines. ' .
49 'If not given, stdin will be used.',
false );
53 # Change to current working directory
58 $username = $this->
getOption(
'u',
false );
62 if ( $username ===
false ) {
72 if ( $this->
hasArg( 0 ) ) {
80 $this->
fatalError(
"Unable to read file, exiting" );
83 $services = MediaWikiServices::getInstance();
84 $lbFactory = $services->getDBLoadBalancerFactory();
85 $wikiPageFactory = $services->getWikiPageFactory();
86 $repoGroup = $services->getRepoGroup();
89 for ( $linenum = 1; !feof(
$file ); $linenum++ ) {
96 $this->
output(
"Invalid title '$line' on line $linenum\n" );
100 $this->
output(
"Skipping nonexistent page '$line'\n" );
106 $img = $repoGroup->findFile(
107 $title, [
'ignoreRedirect' =>
true ]
109 if ( $img && $img->isLocal() && !$img->deleteFile( $reason, $user ) ) {
110 $this->
output(
" FAILED to delete associated file..." );
113 $page = $wikiPageFactory->newFromTitle(
$title );
115 $status = $page->doDeleteArticleReal(
126 if ( $status->isOK() ) {
127 $this->
output(
" Deleted!\n" );
129 $this->
output(
" FAILED to delete article\n" );
135 $lbFactory->waitForReplication();
141require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to delete a batch of pages.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getStdin( $len=null)
Return input from stdin.
hasArg( $argId=0)
Does a given argument exist?
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static setUser( $user)
Reset the stub global user to a different "real" user object, while ensuring that any method calls on...
static newFromName( $name, $validate='valid')
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.