Merge "Purge Squid variant pages based on page language (not $wgContLang)"
[lhc/web/wiklou.git] / maintenance / deleteDefaultMessages.php
1 <?php
2 /**
3 * Deletes all pages in the MediaWiki namespace which were last edited by
4 * "MediaWiki default".
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @ingroup Maintenance
22 */
23
24 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
25
26 class DeleteDefaultMessages extends Maintenance {
27 public function __construct() {
28 parent::__construct();
29 $this->mDescription = "Deletes all pages in the MediaWiki namespace" .
30 " which were last edited by \"MediaWiki default\"";
31 }
32
33 public function execute() {
34 global $wgUser;
35
36 $this->output( "Checking existence of old default messages..." );
37 $dbr = wfGetDB( DB_SLAVE );
38 $res = $dbr->select( array( 'page', 'revision' ),
39 array( 'page_namespace', 'page_title' ),
40 array(
41 'page_namespace' => NS_MEDIAWIKI,
42 'page_latest=rev_id',
43 'rev_user_text' => 'MediaWiki default',
44 )
45 );
46
47 if( $dbr->numRows( $res ) == 0 ) {
48 # No more messages left
49 $this->output( "done.\n" );
50 return;
51 }
52
53 # Deletions will be made by $user temporarly added to the bot group
54 # in order to hide it in RecentChanges.
55 $user = User::newFromName( 'MediaWiki default' );
56 if ( !$user ) {
57 $this->error( "Invalid username", true );
58 }
59 $user->addGroup( 'bot' );
60 $wgUser = $user;
61
62 # Handle deletion
63 $this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
64 $dbw = wfGetDB( DB_MASTER );
65
66 foreach ( $res as $row ) {
67 wfWaitForSlaves();
68 $dbw->ping();
69 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
70 $page = WikiPage::factory( $title );
71 $dbw->begin( __METHOD__ );
72 $error = ''; // Passed by ref
73 $page->doDeleteArticle( 'No longer required', false, 0, false, $error, $user );
74 $dbw->commit( __METHOD__ );
75 }
76
77 $this->output( "done!\n", 'msg' );
78 }
79 }
80
81 $maintClass = "DeleteDefaultMessages";
82 require_once( RUN_MAINTENANCE_IF_MAIN );