37require_once __DIR__ .
'/Maintenance.php';
48 parent::__construct();
50 $this->
addOption(
'u',
'User to perform deletion',
false,
true );
51 $this->
addOption(
'r',
'Reason to delete page',
false,
true );
52 $this->
addOption(
'i',
'Interval to sleep (in seconds) between deletions' );
53 $this->
addOption(
'by-id',
'Delete by page ID instead of by page name',
false,
false );
54 $this->
addArg(
'listfile',
'File with titles to delete, separated by newlines. ' .
55 'If not given, stdin will be used.',
false );
59 # Change to current working directory
64 $username = $this->
getOption(
'u',
false );
69 if ( $username ===
false ) {
70 $user = User::newSystemUser(
'Delete page script', [
'steal' =>
true ] );
72 $user = User::newFromName( $username );
77 StubGlobalUser::setUser( $user );
79 if ( $this->
hasArg( 0 ) ) {
80 $file = fopen( $this->
getArg( 0 ),
'r' );
87 $this->
fatalError(
"Unable to read file, exiting" );
91 $wikiPageFactory = $services->getWikiPageFactory();
92 $repoGroup = $services->getRepoGroup();
93 $delPageFactory = $services->getDeletePageFactory();
96 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
97 $line = trim( fgets( $file ) );
101 if ( $byId ===
false ) {
102 $target = Title::newFromText( $line );
103 if ( $target ===
null ) {
104 $this->
output(
"Invalid title '$line' on line $linenum\n" );
107 if ( !$target->exists() ) {
108 $this->
output(
"Skipping nonexistent page '$line'\n" );
112 $target = Title::newFromID( (
int)$line );
113 if ( $target ===
null ) {
114 $this->
output(
"Invalid page ID '$line' on line $linenum\n" );
117 if ( !$target->exists() ) {
118 $this->
output(
"Skipping nonexistent page ID '$line'\n" );
122 if ( $target->getNamespace() ===
NS_FILE ) {
123 $img = $repoGroup->findFile(
124 $target, [
'ignoreRedirect' =>
true ]
126 if ( $img && $img->isLocal() && !$img->deleteFile( $reason, $user ) ) {
127 $this->
output(
" FAILED to delete associated file..." );
130 $page = $wikiPageFactory->newFromTitle( $target );
131 $delPage = $delPageFactory->newDeletePage( $page, $user );
133 ->forceImmediate(
true )
134 ->deleteUnsafe( $reason );
136 if ( $status->isOK() ) {
137 $this->
output(
" Deleted!\n" );
139 $this->
output(
" FAILED to delete article\n" );
152require_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?
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.