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