Allow cleanupSpam.php optionally delete offending pages
[lhc/web/wiklou.git] / maintenance / fixExtLinksProtocolRelative.php
1 <?php
2 /**
3 * Fixes any entries for protocol-relative URLs in the externallinks table,
4 * replacing each protocol-relative entry with two entries, one for http
5 * and one for https.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @ingroup Maintenance
23 */
24
25 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
26
27 class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance {
28 public function __construct() {
29 parent::__construct();
30 $this->mDescription = "Fixes any entries in the externallinks table containing protocol-relative URLs";
31 }
32
33 protected function getUpdateKey() {
34 return 'fix protocol-relative URLs in externallinks';
35 }
36
37 protected function updateSkippedMessage() {
38 return 'protocol-relative URLs in externallinks table already fixed.';
39 }
40
41 protected function doDBUpdates() {
42 $db = wfGetDB( DB_MASTER );
43 if ( !$db->tableExists( 'externallinks' ) ) {
44 $this->error( "externallinks table does not exist" );
45 return false;
46 }
47 $this->output( "Fixing protocol-relative entries in the externallinks table...\n" );
48 $res = $db->select( 'externallinks', array( 'el_from', 'el_to', 'el_index' ),
49 array( 'el_index' . $db->buildLike( '//', $db->anyString() ) ),
50 __METHOD__
51 );
52 $count = 0;
53 foreach ( $res as $row ) {
54 $count++;
55 if ( $count % 100 == 0 ) {
56 $this->output( $count . "\n" );
57 wfWaitForSlaves();
58 }
59 $db->insert( 'externallinks',
60 array(
61 array(
62 'el_from' => $row->el_from,
63 'el_to' => $row->el_to,
64 'el_index' => "http:{$row->el_index}",
65 ),
66 array(
67 'el_from' => $row->el_from,
68 'el_to' => $row->el_to,
69 'el_index' => "https:{$row->el_index}",
70 )
71 ), __METHOD__, array( 'IGNORE' )
72 );
73 $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ );
74 }
75 $this->output( "Done, $count rows updated.\n" );
76 return true;
77 }
78 }
79
80 $maintClass = "FixExtLinksProtocolRelative";
81 require_once( RUN_MAINTENANCE_IF_MAIN );