Localisation updates from http://translatewiki.net.
[mediawiki.git] / maintenance / fixExtLinksProtocolRelative.php
blob2403ec68b47be2260c429fa17173c282579a2864
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.
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.
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.
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
22 * @file
23 * @ingroup Maintenance
26 require_once( __DIR__ . '/Maintenance.php' );
28 /**
29 * Maintenance script that fixes any entriy for protocol-relative URLs
30 * in the externallinks table.
32 * @ingroup Maintenance
34 class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance {
35 public function __construct() {
36 parent::__construct();
37 $this->mDescription = "Fixes any entries in the externallinks table containing protocol-relative URLs";
40 protected function getUpdateKey() {
41 return 'fix protocol-relative URLs in externallinks';
44 protected function updateSkippedMessage() {
45 return 'protocol-relative URLs in externallinks table already fixed.';
48 protected function doDBUpdates() {
49 $db = wfGetDB( DB_MASTER );
50 if ( !$db->tableExists( 'externallinks' ) ) {
51 $this->error( "externallinks table does not exist" );
52 return false;
54 $this->output( "Fixing protocol-relative entries in the externallinks table...\n" );
55 $res = $db->select( 'externallinks', array( 'el_from', 'el_to', 'el_index' ),
56 array( 'el_index' . $db->buildLike( '//', $db->anyString() ) ),
57 __METHOD__
59 $count = 0;
60 foreach ( $res as $row ) {
61 $count++;
62 if ( $count % 100 == 0 ) {
63 $this->output( $count . "\n" );
64 wfWaitForSlaves();
66 $db->insert( 'externallinks',
67 array(
68 array(
69 'el_from' => $row->el_from,
70 'el_to' => $row->el_to,
71 'el_index' => "http:{$row->el_index}",
73 array(
74 'el_from' => $row->el_from,
75 'el_to' => $row->el_to,
76 'el_index' => "https:{$row->el_index}",
78 ), __METHOD__, array( 'IGNORE' )
80 $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ );
82 $this->output( "Done, $count rows updated.\n" );
83 return true;
87 $maintClass = "FixExtLinksProtocolRelative";
88 require_once( RUN_MAINTENANCE_IF_MAIN );