Filenames with quotes fail here.
[lhc/web/wiklou.git] / maintenance / deleteSelfExternals.php
1 <?php
2 /**
3 * We want to make this whole thing as seamless as possible to the
4 * end-user. Unfortunately, we can't do _all_ of the work in the class
5 * because A) included files are not in global scope, but in the scope
6 * of their caller, and B) MediaWiki has way too many globals. So instead
7 * we'll kinda fake it, and do the requires() inline. <3 PHP
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @ingroup Maintenance
25 */
26
27 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
28
29
30 class DeleteSelfExternals extends Maintenance {
31 public function __construct() {
32 parent::__construct();
33 $this->mDescription = 'Delete self-references to $wgServer from externallinks';
34 $this->mBatchSize = 1000;
35 }
36
37 public function execute() {
38 global $wgServer;
39 $this->output( "Deleting self externals from $wgServer\n" );
40 $db = wfGetDB( DB_MASTER );
41 while ( 1 ) {
42 wfWaitForSlaves( 2 );
43 $db->commit();
44 $q = $db->limitResult( "DELETE /* deleteSelfExternals */ FROM externallinks WHERE el_to"
45 . $db->buildLike( $wgServer . '/', $db->anyString() ), $this->mBatchSize );
46 $this->output( "Deleting a batch\n" );
47 $db->query( $q );
48 if ( !$db->affectedRows() ) return;
49 }
50 }
51 }
52
53 $maintClass = "DeleteSelfExternals";
54 require_once( DO_MAINTENANCE );