23require_once __DIR__ .
'/Maintenance.php';
34 parent::__construct();
36 $this->
addOption(
'u',
'User to perform deletion',
false,
true );
37 $this->
addOption(
'r',
'Reason to delete page',
false,
true );
38 $this->
addOption(
'i',
'Interval to sleep (in seconds) between deletions' );
39 $this->
addOption(
'by-id',
'Delete by page ID instead of by page name',
false,
false );
40 $this->
addArg(
'listfile',
'File with titles to delete, separated by newlines. ' .
41 'If not given, stdin will be used.',
false );
45 # Change to current working directory
50 $username = $this->
getOption(
'u',
false );
55 if ( $username ===
false ) {
56 $user = User::newSystemUser(
'Delete page script', [
'steal' =>
true ] );
58 $user = User::newFromName( $username );
63 StubGlobalUser::setUser( $user );
65 if ( $this->
hasArg( 0 ) ) {
66 $file = fopen( $this->
getArg( 0 ),
'r' );
73 $this->
fatalError(
"Unable to read file, exiting" );
77 $wikiPageFactory = $services->getWikiPageFactory();
78 $repoGroup = $services->getRepoGroup();
79 $delPageFactory = $services->getDeletePageFactory();
82 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
83 $line = trim( fgets( $file ) );
87 if ( $byId ===
false ) {
88 $target = Title::newFromText( $line );
89 if ( $target ===
null ) {
90 $this->
output(
"Invalid title '$line' on line $linenum\n" );
93 if ( !$target->exists() ) {
94 $this->
output(
"Skipping nonexistent page '$line'\n" );
98 $target = Title::newFromID( (
int)$line );
99 if ( $target ===
null ) {
100 $this->
output(
"Invalid page ID '$line' on line $linenum\n" );
103 if ( !$target->exists() ) {
104 $this->
output(
"Skipping nonexistent page ID '$line'\n" );
108 if ( $target->getNamespace() ===
NS_FILE ) {
109 $img = $repoGroup->findFile(
110 $target, [
'ignoreRedirect' =>
true ]
112 if ( $img && $img->isLocal() && !$img->deleteFile( $reason, $user ) ) {
113 $this->
output(
" FAILED to delete associated file..." );
116 $page = $wikiPageFactory->newFromTitle( $target );
117 $delPage = $delPageFactory->newDeletePage( $page, $user );
119 ->forceImmediate(
true )
120 ->deleteUnsafe( $reason );
122 if ( $status->isOK() ) {
123 $this->
output(
" Deleted $line!\n" );
125 $this->
output(
" FAILED to delete page $line\n" );
126 $this->
error( $status );
139require_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, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
hasArg( $argId=0)
Does a given argument exist?
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.