MediaWiki  REL1_20
fixExtLinksProtocolRelative.php
Go to the documentation of this file.
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_from' => $row->el_from,
00070                                                 'el_to' => $row->el_to,
00071                                                 'el_index' => "http:{$row->el_index}",
00072                                         ),
00073                                         array(
00074                                                 'el_from' => $row->el_from,
00075                                                 'el_to' => $row->el_to,
00076                                                 'el_index' => "https:{$row->el_index}",
00077                                         )
00078                                 ), __METHOD__, array( 'IGNORE' )
00079                         );
00080                         $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ );
00081                 }
00082                 $this->output( "Done, $count rows updated.\n" );
00083                 return true;
00084         }
00085 }
00086 
00087 $maintClass = "FixExtLinksProtocolRelative";
00088 require_once( RUN_MAINTENANCE_IF_MAIN );