46 $server = $this->getConfig()->get( MainConfigNames::Server );
47 $bits = $this->getServiceContainer()->getUrlUtils()->parse( $server );
49 $this->fatalError(
'Could not parse $wgServer' );
52 $this->output(
"Deleting self externals from $server\n" );
53 $db = $this->getPrimaryDB();
57 $host = $bits[
'host'];
58 if ( isset( $bits[
'port'] ) ) {
59 $host .=
':' . $bits[
'port'];
61 if ( $bits[
'scheme'] !=
'' ) {
62 $conds = [ LinkFilter::getQueryConditions( $host, [
'protocol' => $bits[
'scheme'] .
'://' ] ) ];
65 LinkFilter::getQueryConditions( $host, [
'protocol' =>
'http://' ] ),
66 LinkFilter::getQueryConditions( $host, [
'protocol' =>
'https://' ] ),
73 $conds = array_map(
static function ( $cond ) use ( $db ) {
74 return $db->andExpr( $cond );
75 }, array_filter( $conds ) );
76 $domainExpr = $db->orExpr( $conds );
80 $batchEnd = $batchStart + $this->getBatchSize();
82 $this->output(
"Deleting self-externals with el_id $batchStart to $batchEnd\n" );
84 $db->newDeleteQueryBuilder()
85 ->deleteFrom(
'externallinks' )
86 ->where( $domainExpr )
87 ->andWhere( $db->expr(
'el_id',
'>', $batchStart ) )
88 ->andWhere( $db->expr(
'el_id',
'<=', $batchEnd ) )
89 ->caller( __METHOD__ )
91 $rowsDeletedInThisBatch = $db->affectedRows();
92 $totalRows += $rowsDeletedInThisBatch;
94 $batchStart += $this->getBatchSize();
95 $batchEnd += $this->getBatchSize();
96 $this->waitForReplication();
97 }
while ( $rowsDeletedInThisBatch );
99 $this->output(
"done; deleted $totalRows rows\n" );