58 # Change to current working directory
63 $username = $this->getOption(
'u',
false );
64 $reason = $this->getOption(
'r',
'' );
65 $interval = $this->getOption(
'i', 0 );
66 $byId = $this->hasOption(
'by-id' );
68 if ( $username ===
false ) {
69 $user = User::newSystemUser(
'Delete page script', [
'steal' =>
true ] );
71 $user = User::newFromName( $username );
74 $this->fatalError(
"Invalid username" );
76 StubGlobalUser::setUser( $user );
78 if ( $this->hasArg( 0 ) ) {
79 $file = fopen( $this->getArg( 0 ),
'r' );
81 $file = $this->getStdin();
86 $this->fatalError(
"Unable to read file, exiting" );
89 $services = $this->getServiceContainer();
90 $wikiPageFactory = $services->getWikiPageFactory();
91 $repoGroup = $services->getRepoGroup();
92 $delPageFactory = $services->getDeletePageFactory();
95 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
96 $line = trim( fgets( $file ) );
100 if ( $byId ===
false ) {
101 $target = Title::newFromText( $line );
102 if ( $target ===
null ) {
103 $this->output(
"Invalid title '$line' on line $linenum\n" );
106 if ( !$target->exists() ) {
107 $this->output(
"Skipping nonexistent page '$line'\n" );
111 $target = Title::newFromID( (
int)$line );
112 if ( $target ===
null ) {
113 $this->output(
"Invalid page ID '$line' on line $linenum\n" );
116 if ( !$target->exists() ) {
117 $this->output(
"Skipping nonexistent page ID '$line'\n" );
121 if ( $target->getNamespace() ===
NS_FILE ) {
122 $img = $repoGroup->findFile(
123 $target, [
'ignoreRedirect' =>
true ]
125 if ( $img && $img->isLocal() && !$img->deleteFile( $reason, $user ) ) {
126 $this->output(
" FAILED to delete associated file..." );
129 $page = $wikiPageFactory->newFromTitle( $target );
130 $delPage = $delPageFactory->newDeletePage( $page, $user );
132 ->forceImmediate(
true )
133 ->deleteUnsafe( $reason );
135 if ( $status->isOK() ) {
136 $this->output(
" Deleted!\n" );
138 $this->output(
" FAILED to delete article\n" );
144 $this->waitForReplication();