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