22require_once __DIR__ .
'/Maintenance.php';
33 parent::__construct();
35 $this->
addOption(
'u',
'User to perform deletion',
false,
true );
36 $this->
addOption(
'r',
'Reason to delete page',
false,
true );
37 $this->
addOption(
'i',
'Interval to sleep (in seconds) between deletions' );
38 $this->
addOption(
'by-id',
'Delete by page ID instead of by page name',
false,
false );
39 $this->
addArg(
'listfile',
'File with titles to delete, separated by newlines. ' .
40 'If not given, stdin will be used.',
false );
44 # Change to current working directory
49 $username = $this->
getOption(
'u',
false );
54 if ( $username ===
false ) {
55 $user = User::newSystemUser(
'Delete page script', [
'steal' =>
true ] );
57 $user = User::newFromName( $username );
63 if ( $this->
hasArg( 0 ) ) {
64 $file = fopen( $this->
getArg( 0 ),
'r' );
71 $this->
fatalError(
"Unable to read file, exiting" );
75 $wikiPageFactory = $services->getWikiPageFactory();
76 $repoGroup = $services->getRepoGroup();
77 $delPageFactory = $services->getDeletePageFactory();
80 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
81 $line = trim( fgets( $file ) );
85 if ( $byId ===
false ) {
86 $target = Title::newFromText( $line );
87 if ( $target ===
null ) {
88 $this->
output(
"Invalid title '$line' on line $linenum\n" );
91 if ( !$target->exists() ) {
92 $this->
output(
"Skipping nonexistent page '$line'\n" );
96 $target = Title::newFromID( (
int)$line );
97 if ( $target ===
null ) {
98 $this->
output(
"Invalid page ID '$line' on line $linenum\n" );
101 if ( !$target->exists() ) {
102 $this->
output(
"Skipping nonexistent page ID '$line'\n" );
106 if ( $target->getNamespace() ===
NS_FILE ) {
107 $img = $repoGroup->findFile(
108 $target, [
'ignoreRedirect' =>
true ]
110 if ( $img && $img->isLocal() && !$img->deleteFile( $reason, $user ) ) {
111 $this->
output(
" FAILED to delete associated file..." );
114 $page = $wikiPageFactory->newFromTitle( $target );
115 $delPage = $delPageFactory->newDeletePage( $page, $user );
117 ->forceImmediate(
true )
118 ->deleteUnsafe( $reason );
120 if ( $status->isOK() ) {
121 $this->
output(
" Deleted $line!\n" );
123 $this->
output(
" FAILED to delete page $line\n" );
124 $this->
error( $status );
137require_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.