Merge "(bug 37090) Remove Spanish gender aliases."
[mediawiki.git] / maintenance / fixExtLinksProtocolRelative.php
blob0cabe8160eb95a7e21e6c5c8be96c93343e73273
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 * @ingroup Maintenance
25 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
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";
33 protected function getUpdateKey() {
34 return 'fix protocol-relative URLs in externallinks';
37 protected function updateSkippedMessage() {
38 return 'protocol-relative URLs in externallinks table already fixed.';
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;
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__
52 $count = 0;
53 foreach ( $res as $row ) {
54 $count++;
55 if ( $count % 100 == 0 ) {
56 $this->output( $count . "\n" );
57 wfWaitForSlaves();
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}",
66 array(
67 'el_from' => $row->el_from,
68 'el_to' => $row->el_to,
69 'el_index' => "https:{$row->el_index}",
71 ), __METHOD__, array( 'IGNORE' )
73 $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ );
75 $this->output( "Done, $count rows updated.\n" );
76 return true;
80 $maintClass = "FixExtLinksProtocolRelative";
81 require_once( RUN_MAINTENANCE_IF_MAIN );