2006-06-15 04:58:03 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2012-07-17 05:40:40 +00:00
|
|
|
* Deletes a batch of pages.
|
2024-03-20 06:20:51 +00:00
|
|
|
* Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] [--by-id] [listfile]
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* where
|
2014-04-23 18:08:42 +00:00
|
|
|
* [listfile] is a file where each line contains the title of a page to be
|
|
|
|
|
* deleted, standard input is used if listfile is not given.
|
|
|
|
|
* <user> is the username
|
|
|
|
|
* <reason> is the delete reason
|
|
|
|
|
* <interval> is the number of seconds to sleep for after each delete
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-07-08 20:47:27 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2022-10-25 16:58:49 +00:00
|
|
|
use MediaWiki\StubObject\StubGlobalUser;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2019-05-14 17:00:34 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2012-07-08 20:47:27 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to delete a batch of pages.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class DeleteBatch extends Maintenance {
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Deletes a batch of pages' );
|
2022-08-17 23:58:18 +00:00
|
|
|
$this->addOption( 'u', 'User to perform deletion', false, true );
|
|
|
|
|
$this->addOption( 'r', 'Reason to delete page', false, true );
|
|
|
|
|
$this->addOption( 'i', 'Interval to sleep (in seconds) between deletions' );
|
2024-03-20 06:20:51 +00:00
|
|
|
$this->addOption( 'by-id', 'Delete by page ID instead of by page name', false, false );
|
2010-11-20 11:11:20 +00:00
|
|
|
$this->addArg( 'listfile', 'File with titles to delete, separated by newlines. ' .
|
|
|
|
|
'If not given, stdin will be used.', false );
|
2009-06-24 02:49:24 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
|
|
|
|
# Change to current working directory
|
|
|
|
|
$oldCwd = getcwd();
|
|
|
|
|
chdir( $oldCwd );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Options processing
|
2015-09-04 16:17:42 +00:00
|
|
|
$username = $this->getOption( 'u', false );
|
2009-08-02 19:35:17 +00:00
|
|
|
$reason = $this->getOption( 'r', '' );
|
|
|
|
|
$interval = $this->getOption( 'i', 0 );
|
2024-03-20 06:20:51 +00:00
|
|
|
$byId = $this->hasOption( 'by-id' );
|
2011-12-27 15:56:35 +00:00
|
|
|
|
2015-09-04 16:17:42 +00:00
|
|
|
if ( $username === false ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$user = User::newSystemUser( 'Delete page script', [ 'steal' => true ] );
|
2015-09-04 16:17:42 +00:00
|
|
|
} else {
|
|
|
|
|
$user = User::newFromName( $username );
|
|
|
|
|
}
|
2011-12-27 15:56:35 +00:00
|
|
|
if ( !$user ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Invalid username" );
|
2011-12-27 15:56:35 +00:00
|
|
|
}
|
2021-09-04 19:19:47 +00:00
|
|
|
StubGlobalUser::setUser( $user );
|
2011-12-27 15:56:35 +00:00
|
|
|
|
2019-02-28 11:13:49 +00:00
|
|
|
if ( $this->hasArg( 0 ) ) {
|
|
|
|
|
$file = fopen( $this->getArg( 0 ), 'r' );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
|
|
|
|
$file = $this->getStdin();
|
2009-06-24 02:02:37 +00:00
|
|
|
}
|
2009-06-24 02:49:24 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Setup
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( !$file ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Unable to read file, exiting" );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2011-12-27 15:56:35 +00:00
|
|
|
|
2023-08-31 09:21:12 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2020-11-12 20:36:35 +00:00
|
|
|
$wikiPageFactory = $services->getWikiPageFactory();
|
|
|
|
|
$repoGroup = $services->getRepoGroup();
|
2021-11-08 13:39:28 +00:00
|
|
|
$delPageFactory = $services->getDeletePageFactory();
|
2020-05-01 00:36:46 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Handle each entry
|
|
|
|
|
for ( $linenum = 1; !feof( $file ); $linenum++ ) {
|
|
|
|
|
$line = trim( fgets( $file ) );
|
|
|
|
|
if ( $line == '' ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-03-20 06:20:51 +00:00
|
|
|
if ( $byId === false ) {
|
|
|
|
|
$target = Title::newFromText( $line );
|
|
|
|
|
if ( $target === null ) {
|
|
|
|
|
$this->output( "Invalid title '$line' on line $linenum\n" );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( !$target->exists() ) {
|
|
|
|
|
$this->output( "Skipping nonexistent page '$line'\n" );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$target = Title::newFromID( (int)$line );
|
|
|
|
|
if ( $target === null ) {
|
|
|
|
|
$this->output( "Invalid page ID '$line' on line $linenum\n" );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( !$target->exists() ) {
|
|
|
|
|
$this->output( "Skipping nonexistent page ID '$line'\n" );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2024-03-20 06:20:51 +00:00
|
|
|
if ( $target->getNamespace() === NS_FILE ) {
|
2020-11-12 20:36:35 +00:00
|
|
|
$img = $repoGroup->findFile(
|
2024-03-20 06:20:51 +00:00
|
|
|
$target, [ 'ignoreRedirect' => true ]
|
2019-05-14 17:00:34 +00:00
|
|
|
);
|
2020-03-21 02:47:50 +00:00
|
|
|
if ( $img && $img->isLocal() && !$img->deleteFile( $reason, $user ) ) {
|
2021-07-21 16:34:05 +00:00
|
|
|
$this->output( " FAILED to delete associated file..." );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-20 06:20:51 +00:00
|
|
|
$page = $wikiPageFactory->newFromTitle( $target );
|
2021-11-08 13:39:28 +00:00
|
|
|
$delPage = $delPageFactory->newDeletePage( $page, $user );
|
|
|
|
|
$status = $delPage
|
|
|
|
|
->forceImmediate( true )
|
|
|
|
|
->deleteUnsafe( $reason );
|
|
|
|
|
|
2020-03-25 17:21:15 +00:00
|
|
|
if ( $status->isOK() ) {
|
2011-09-19 20:20:41 +00:00
|
|
|
$this->output( " Deleted!\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
|
|
|
|
$this->output( " FAILED to delete article\n" );
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
if ( $interval ) {
|
|
|
|
|
sleep( $interval );
|
|
|
|
|
}
|
2022-10-24 18:31:49 +00:00
|
|
|
$this->waitForReplication();
|
2011-09-16 11:35:56 +00:00
|
|
|
}
|
2006-06-15 04:58:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = DeleteBatch::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|