3 * Deletes a batch of pages
4 * Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] [listfile]
6 * [listfile] is a file where each line contains the title of a page to be
7 * deleted, standard input is used if listfile is not given.
8 * <user> is the username
9 * <reason> is the delete reason
10 * <interval> is the number of seconds to sleep for after each delete
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * http://www.gnu.org/copyleft/gpl.html
27 * @ingroup Maintenance
30 require_once( dirname( __FILE__
) . '/Maintenance.php' );
32 class DeleteBatch
extends Maintenance
{
34 public function __construct() {
35 parent
::__construct();
36 $this->mDescription
= "Deletes a batch of pages";
37 $this->addOption( 'u', "User to perform deletion", false, true );
38 $this->addOption( 'r', "Reason to delete page", false, true );
39 $this->addOption( 'i', "Interval to sleep between deletions" );
40 $this->addArg( 'listfile', 'File with titles to delete, separated by newlines. ' .
41 'If not given, stdin will be used.', false );
44 public function execute() {
47 # Change to current working directory
52 $username = $this->getOption( 'u', 'Delete page script' );
53 $reason = $this->getOption( 'r', '' );
54 $interval = $this->getOption( 'i', 0 );
56 $user = User
::newFromName( $username );
58 $this->error( "Invalid username", true );
62 if ( $this->hasArg() ) {
63 $file = fopen( $this->getArg(), 'r' );
65 $file = $this->getStdin();
70 $this->error( "Unable to read file, exiting", true );
73 $dbw = wfGetDB( DB_MASTER
);
76 for ( $linenum = 1; !feof( $file ); $linenum++
) {
77 $line = trim( fgets( $file ) );
81 $title = Title
::newFromText( $line );
82 if ( is_null( $title ) ) {
83 $this->output( "Invalid title '$line' on line $linenum\n" );
86 if ( !$title->exists() ) {
87 $this->output( "Skipping nonexistent page '$line'\n" );
91 $this->output( $title->getPrefixedText() );
92 $dbw->begin( __METHOD__
);
93 if ( $title->getNamespace() == NS_FILE
) {
94 $img = wfFindFile( $title );
95 if ( $img && $img->isLocal() && !$img->delete( $reason ) ) {
96 $this->output( " FAILED to delete associated file... " );
99 $page = WikiPage
::factory( $title );
101 $success = $page->doDeleteArticle( $reason, false, 0, false, $error, $user );
102 $dbw->commit( __METHOD__
);
104 $this->output( " Deleted!\n" );
106 $this->output( " FAILED to delete article\n" );
117 $maintClass = "DeleteBatch";
118 require_once( RUN_MAINTENANCE_IF_MAIN
);