X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FdeleteSelfExternals.php;h=76a6a1f2d7e514b3faed0986fe7f864a1d651e64;hb=62991fcb7a5027b1eceb5656829c1c65bf9f98cb;hp=9849dc500badc4e3a4ac705cbfa85fd6cf1fc3ab;hpb=a6abe2ad7a1ed2c8dd29f35a9f6c40f85e12b7ab;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/deleteSelfExternals.php b/maintenance/deleteSelfExternals.php index 9849dc500b..76a6a1f2d7 100644 --- a/maintenance/deleteSelfExternals.php +++ b/maintenance/deleteSelfExternals.php @@ -38,17 +38,44 @@ class DeleteSelfExternals extends Maintenance { public function execute() { global $wgServer; + + // Extract the host and scheme from $wgServer + $bits = wfParseUrl( $wgServer ); + if ( !$bits ) { + $this->error( 'Could not parse $wgServer' ); + exit( 1 ); + } + $this->output( "Deleting self externals from $wgServer\n" ); $db = $this->getDB( DB_MASTER ); - while ( 1 ) { - $this->commitTransaction( $db, __METHOD__ ); - $q = $db->limitResult( "DELETE /* deleteSelfExternals */ FROM externallinks WHERE el_to" - . $db->buildLike( $wgServer . '/', $db->anyString() ), $this->getBatchSize() ); - $this->output( "Deleting a batch\n" ); - $db->query( $q ); - if ( !$db->affectedRows() ) { - return; + + // If it's protocol-relative, we need to do both http and https. + // Otherwise, just do the specified scheme. + $host = $bits['host']; + if ( isset( $bits['port'] ) ) { + $host .= ':' . $bits['port']; + } + if ( $bits['scheme'] != '' ) { + $conds = [ LinkFilter::getQueryConditions( $host, [ 'protocol' => $bits['scheme'] . '://' ] ) ]; + } else { + $conds = [ + LinkFilter::getQueryConditions( $host, [ 'protocol' => 'http://' ] ), + LinkFilter::getQueryConditions( $host, [ 'protocol' => 'https://' ] ), + ]; + } + + foreach ( $conds as $cond ) { + if ( !$cond ) { + continue; } + $cond = $db->makeList( $cond, LIST_AND ); + do { + $this->commitTransaction( $db, __METHOD__ ); + $q = $db->limitResult( "DELETE /* deleteSelfExternals */ FROM externallinks WHERE $cond", + $this->mBatchSize ); + $this->output( "Deleting a batch\n" ); + $db->query( $q ); + } while ( $db->affectedRows() ); } } }