X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FcleanupSpam.php;h=4cc52a40342b41800596e341e6f4ca691368b2c6;hb=f9bb20657c6776a7543fbf33ead1c1e6fbad33de;hp=24ca86d60f2c6e68c92314462f76e0678508d638;hpb=e9ed100496b388a31ac2af0deabcc9754984d09d;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/cleanupSpam.php b/maintenance/cleanupSpam.php index 24ca86d60f..4cc52a4034 100644 --- a/maintenance/cleanupSpam.php +++ b/maintenance/cleanupSpam.php @@ -21,6 +21,8 @@ * @ingroup Maintenance */ +use MediaWiki\Storage\RevisionRecord; + require_once __DIR__ . '/Maintenance.php'; /** @@ -52,39 +54,39 @@ class CleanupSpam extends Maintenance { // Hack: Grant bot rights so we don't flood RecentChanges $wgUser->addGroup( 'bot' ); - $spec = $this->getArg(); + $spec = $this->getArg( 0 ); - $likes = []; + $protConds = []; foreach ( [ 'http://', 'https://' ] as $prot ) { - $like = LinkFilter::makeLikeArray( $spec, $prot ); - if ( !$like ) { + $conds = LinkFilter::getQueryConditions( $spec, [ 'protocol' => $prot ] ); + if ( !$conds ) { $this->fatalError( "Not a valid hostname specification: $spec" ); } - $likes[$prot] = $like; + $protConds[$prot] = $conds; } if ( $this->hasOption( 'all' ) ) { // Clean up spam on all wikis $this->output( "Finding spam on " . count( $wgLocalDatabases ) . " wikis\n" ); $found = false; - foreach ( $wgLocalDatabases as $wikiID ) { - /** @var $dbr Database */ - $dbr = $this->getDB( DB_REPLICA, [], $wikiID ); + foreach ( $wgLocalDatabases as $wikiId ) { + /** @var Database $dbr */ + $dbr = $this->getDB( DB_REPLICA, [], $wikiId ); - foreach ( $likes as $like ) { + foreach ( $protConds as $conds ) { $count = $dbr->selectField( 'externallinks', 'COUNT(*)', - [ 'el_index' . $dbr->buildLike( $like ) ], + $conds, __METHOD__ ); if ( $count ) { $found = true; $cmd = wfShellWikiCmd( "$IP/maintenance/cleanupSpam.php", - [ '--wiki', $wikiID, $spec ] + [ '--wiki', $wikiId, $spec ] ); - passthru( "$cmd | sed 's/^/$wikiID: /'" ); + passthru( "$cmd | sed 's/^/$wikiId: /'" ); } } } @@ -97,13 +99,13 @@ class CleanupSpam extends Maintenance { // Clean up spam on this wiki $count = 0; - /** @var $dbr Database */ + /** @var Database $dbr */ $dbr = $this->getDB( DB_REPLICA ); - foreach ( $likes as $prot => $like ) { + foreach ( $protConds as $prot => $conds ) { $res = $dbr->select( 'externallinks', [ 'DISTINCT el_from' ], - [ 'el_index' . $dbr->buildLike( $like ) ], + $conds, __METHOD__ ); $count = $dbr->numRows( $res ); @@ -136,8 +138,8 @@ class CleanupSpam extends Maintenance { $rev = Revision::newFromTitle( $title ); $currentRevId = $rev->getId(); - while ( $rev && ( $rev->isDeleted( Revision::DELETED_TEXT ) - || LinkFilter::matchEntry( $rev->getContent( Revision::RAW ), $domain, $protocol ) ) + while ( $rev && ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) + || LinkFilter::matchEntry( $rev->getContent( RevisionRecord::RAW ), $domain, $protocol ) ) ) { $rev = $rev->getPrevious(); } @@ -152,7 +154,7 @@ class CleanupSpam extends Maintenance { $page = WikiPage::factory( $title ); if ( $rev ) { // Revert to this revision - $content = $rev->getContent( Revision::RAW ); + $content = $rev->getContent( RevisionRecord::RAW ); $this->output( "reverting\n" ); $page->doEditContent(