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 (in seconds) between deletions' );
48 $this->
addOption(
'by-id',
'Delete by page ID instead of by page name',
false,
false );
49 $this->
addArg(
'listfile',
'File with titles to delete, separated by newlines. ' .
50 'If not given, stdin will be used.',
false );
54 # Change to current working directory
59 $username = $this->
getOption(
'u',
false );
64 if ( $username ===
false ) {
74 if ( $this->
hasArg( 0 ) ) {
82 $this->
fatalError(
"Unable to read file, exiting" );
85 $services = MediaWikiServices::getInstance();
86 $lbFactory = $services->getDBLoadBalancerFactory();
87 $wikiPageFactory = $services->getWikiPageFactory();
88 $repoGroup = $services->getRepoGroup();
91 for ( $linenum = 1; !feof(
$file ); $linenum++ ) {
96 if ( $byId ===
false ) {
97 $target = Title::newFromText(
$line );
98 if ( $target ===
null ) {
99 $this->
output(
"Invalid title '$line' on line $linenum\n" );
102 if ( !$target->exists() ) {
103 $this->
output(
"Skipping nonexistent page '$line'\n" );
107 $target = Title::newFromID( (
int)
$line );
108 if ( $target ===
null ) {
109 $this->
output(
"Invalid page ID '$line' on line $linenum\n" );
112 if ( !$target->exists() ) {
113 $this->
output(
"Skipping nonexistent page ID '$line'\n" );
117 if ( $target->getNamespace() ===
NS_FILE ) {
118 $img = $repoGroup->findFile(
119 $target, [
'ignoreRedirect' =>
true ]
121 if ( $img && $img->isLocal() && !$img->deleteFile( $reason, $user ) ) {
122 $this->
output(
" FAILED to delete associated file..." );
125 $page = $wikiPageFactory->newFromTitle( $target );
127 $status = $page->doDeleteArticleReal(
138 if ( $status->isOK() ) {
139 $this->
output(
" Deleted!\n" );
141 $this->
output(
" FAILED to delete article\n" );
147 $lbFactory->waitForReplication();
153require_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?
hasOption( $name)
Checks to see if a particular option was set.
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.