"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "maintenance/cleanupSpam.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

cleanupSpam.php  (mediawiki-1.31.1):cleanupSpam.php  (mediawiki-1.32.0)
skipping to change at line 56 skipping to change at line 56
$username = wfMessage( 'spambot_username' )->text(); $username = wfMessage( 'spambot_username' )->text();
$wgUser = User::newSystemUser( $username ); $wgUser = User::newSystemUser( $username );
if ( !$wgUser ) { if ( !$wgUser ) {
$this->fatalError( "Invalid username specified in 'spambo t_username' message: $username" ); $this->fatalError( "Invalid username specified in 'spambo t_username' message: $username" );
} }
// Hack: Grant bot rights so we don't flood RecentChanges // Hack: Grant bot rights so we don't flood RecentChanges
$wgUser->addGroup( 'bot' ); $wgUser->addGroup( 'bot' );
$spec = $this->getArg(); $spec = $this->getArg();
$like = LinkFilter::makeLikeArray( $spec );
if ( !$like ) { $likes = [];
$this->fatalError( "Not a valid hostname specification: $ foreach ( [ 'http://', 'https://' ] as $prot ) {
spec" ); $like = LinkFilter::makeLikeArray( $spec, $prot );
if ( !$like ) {
$this->fatalError( "Not a valid hostname specific
ation: $spec" );
}
$likes[$prot] = $like;
} }
if ( $this->hasOption( 'all' ) ) { if ( $this->hasOption( 'all' ) ) {
// Clean up spam on all wikis // Clean up spam on all wikis
$this->output( "Finding spam on " . count( $wgLocalDataba ses ) . " wikis\n" ); $this->output( "Finding spam on " . count( $wgLocalDataba ses ) . " wikis\n" );
$found = false; $found = false;
foreach ( $wgLocalDatabases as $wikiID ) { foreach ( $wgLocalDatabases as $wikiID ) {
/** @var $dbr Database */
$dbr = $this->getDB( DB_REPLICA, [], $wikiID ); $dbr = $this->getDB( DB_REPLICA, [], $wikiID );
$count = $dbr->selectField( 'externallinks', 'COU foreach ( $likes as $like ) {
NT(*)', $count = $dbr->selectField(
[ 'el_index' . $dbr->buildLike( $like ) ] 'externallinks',
, __METHOD__ ); 'COUNT(*)',
if ( $count ) { [ 'el_index' . $dbr->buildLike( $
$found = true; like ) ],
$cmd = wfShellWikiCmd( "$IP/maintenance/c __METHOD__
leanupSpam.php", );
[ '--wiki', $wikiID, $spec ] ); if ( $count ) {
passthru( "$cmd | sed 's/^/$wikiID: /'" $found = true;
); $cmd = wfShellWikiCmd(
"$IP/maintenance/cleanupS
pam.php",
[ '--wiki', $wikiID, $spe
c ]
);
passthru( "$cmd | sed 's/^/$wikiI
D: /'" );
}
} }
} }
if ( $found ) { if ( $found ) {
$this->output( "All done\n" ); $this->output( "All done\n" );
} else { } else {
$this->output( "None found\n" ); $this->output( "None found\n" );
} }
} else { } else {
// Clean up spam on this wiki // Clean up spam on this wiki
$count = 0;
/** @var $dbr Database */
$dbr = $this->getDB( DB_REPLICA ); $dbr = $this->getDB( DB_REPLICA );
$res = $dbr->select( 'externallinks', [ 'DISTINCT el_from foreach ( $likes as $prot => $like ) {
' ], $res = $dbr->select(
[ 'el_index' . $dbr->buildLike( $like ) ], __METH 'externallinks',
OD__ ); [ 'DISTINCT el_from' ],
$count = $dbr->numRows( $res ); [ 'el_index' . $dbr->buildLike( $like ) ]
$this->output( "Found $count articles containing $spec\n" ,
); __METHOD__
foreach ( $res as $row ) { );
$this->cleanupArticle( $row->el_from, $spec ); $count = $dbr->numRows( $res );
$this->output( "Found $count articles containing
$spec\n" );
foreach ( $res as $row ) {
$this->cleanupArticle( $row->el_from, $sp
ec, $prot );
}
} }
if ( $count ) { if ( $count ) {
$this->output( "Done\n" ); $this->output( "Done\n" );
} }
} }
} }
private function cleanupArticle( $id, $domain ) { /**
* @param int $id
* @param string $domain
* @param string $protocol
* @throws MWException
*/
private function cleanupArticle( $id, $domain, $protocol ) {
$title = Title::newFromID( $id ); $title = Title::newFromID( $id );
if ( !$title ) { if ( !$title ) {
$this->error( "Internal error: no page for ID $id" ); $this->error( "Internal error: no page for ID $id" );
return; return;
} }
$this->output( $title->getPrefixedDBkey() . " ..." ); $this->output( $title->getPrefixedDBkey() . " ..." );
$rev = Revision::newFromTitle( $title ); $rev = Revision::newFromTitle( $title );
$currentRevId = $rev->getId(); $currentRevId = $rev->getId();
while ( $rev && ( $rev->isDeleted( Revision::DELETED_TEXT ) while ( $rev && ( $rev->isDeleted( Revision::DELETED_TEXT )
|| LinkFilter::matchEntry( $rev->getContent( Revision::RA W ), $domain ) ) || LinkFilter::matchEntry( $rev->getContent( Revision::RA W ), $domain, $protocol ) )
) { ) {
$rev = $rev->getPrevious(); $rev = $rev->getPrevious();
} }
if ( $rev && $rev->getId() == $currentRevId ) { if ( $rev && $rev->getId() == $currentRevId ) {
// The regex didn't match the current article text // The regex didn't match the current article text
// This happens e.g. when a link comes from a template ra ther than the page itself // This happens e.g. when a link comes from a template ra ther than the page itself
$this->output( "False match\n" ); $this->output( "False match\n" );
} else { } else {
$dbw = $this->getDB( DB_MASTER ); $dbw = $this->getDB( DB_MASTER );
 End of changes. 7 change blocks. 
26 lines changed or deleted 54 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)