MediaWiki
REL1_22
|
00001 <?php 00026 require_once __DIR__ . '/Maintenance.php'; 00027 00034 class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance { 00035 public function __construct() { 00036 parent::__construct(); 00037 $this->mDescription = "Fixes any entries in the externallinks table containing protocol-relative URLs"; 00038 } 00039 00040 protected function getUpdateKey() { 00041 return 'fix protocol-relative URLs in externallinks'; 00042 } 00043 00044 protected function updateSkippedMessage() { 00045 return 'protocol-relative URLs in externallinks table already fixed.'; 00046 } 00047 00048 protected function doDBUpdates() { 00049 $db = wfGetDB( DB_MASTER ); 00050 if ( !$db->tableExists( 'externallinks' ) ) { 00051 $this->error( "externallinks table does not exist" ); 00052 return false; 00053 } 00054 $this->output( "Fixing protocol-relative entries in the externallinks table...\n" ); 00055 $res = $db->select( 'externallinks', array( 'el_from', 'el_to', 'el_index' ), 00056 array( 'el_index' . $db->buildLike( '//', $db->anyString() ) ), 00057 __METHOD__ 00058 ); 00059 $count = 0; 00060 foreach ( $res as $row ) { 00061 $count++; 00062 if ( $count % 100 == 0 ) { 00063 $this->output( $count . "\n" ); 00064 wfWaitForSlaves(); 00065 } 00066 $db->insert( 'externallinks', 00067 array( 00068 array( 00069 'el_id' => $db->nextSequenceValue( 'externallinks_el_id_seq' ), 00070 'el_from' => $row->el_from, 00071 'el_to' => $row->el_to, 00072 'el_index' => "http:{$row->el_index}", 00073 ), 00074 array( 00075 'el_id' => $db->nextSequenceValue( 'externallinks_el_id_seq' ), 00076 'el_from' => $row->el_from, 00077 'el_to' => $row->el_to, 00078 'el_index' => "https:{$row->el_index}", 00079 ) 00080 ), __METHOD__, array( 'IGNORE' ) 00081 ); 00082 $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ ); 00083 } 00084 $this->output( "Done, $count rows updated.\n" ); 00085 return true; 00086 } 00087 } 00088 00089 $maintClass = "FixExtLinksProtocolRelative"; 00090 require_once RUN_MAINTENANCE_IF_MAIN;