X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FdeleteSelfExternals.php;h=76a6a1f2d7e514b3faed0986fe7f864a1d651e64;hb=72bec61d7ca4bc24731389f30c790662458c12c7;hp=20d5c2f0a9864460ab304a2b0b243d773c61599d;hpb=b610a3b617f7616b2f1db12498cbad5aeae12576;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/deleteSelfExternals.php b/maintenance/deleteSelfExternals.php index 20d5c2f0a9..76a6a1f2d7 100644 --- a/maintenance/deleteSelfExternals.php +++ b/maintenance/deleteSelfExternals.php @@ -38,18 +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 ) { - wfWaitForSlaves(); - $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() ); } } }