22require_once __DIR__ .
'/Maintenance.php';
33 parent::__construct();
35 $this->
addOption(
'all',
'Check all wikis in $wgLocalDatabases' );
36 $this->
addOption(
'delete',
'Delete pages containing only spam instead of blanking them' );
39 'Hostname that was spamming, single * wildcard in the beginning allowed'
46 $username =
wfMessage(
'spambot_username' )->text();
47 $user = User::newSystemUser( $username );
49 $this->
fatalError(
"Invalid username specified in 'spambot_username' message: $username" );
53 StubGlobalUser::setUser( $user );
55 $spec = $this->
getArg( 0 );
58 foreach ( [
'http://',
'https://' ] as $prot ) {
59 $conds = LinkFilter::getQueryConditions( $spec, [
'protocol' => $prot ] );
61 $this->
fatalError(
"Not a valid hostname specification: $spec" );
63 $protConds[$prot] = $conds;
74 foreach ( $protConds as $conds ) {
75 $count = $dbr->newSelectQueryBuilder()
76 ->select(
'COUNT(*)' )
77 ->from(
'externallinks' )
79 ->caller( __METHOD__ )
84 "$IP/maintenance/cleanupSpam.php",
85 [
'--wiki', $wikiId, $spec ]
88 passthru(
"$cmd | sed 's/^/$wikiId: /'" );
93 $this->
output(
"All done\n" );
95 $this->
output(
"None found\n" );
102 ExternalLinksTable::VIRTUAL_DOMAIN
104 foreach ( $protConds as $prot => $conds ) {
105 $res = $dbr->newSelectQueryBuilder()
106 ->select(
'el_from' )
108 ->from(
'externallinks' )
110 ->caller( __METHOD__ )
112 $count += $res->numRows();
113 $this->
output(
"Found $count articles containing $spec so far...\n" );
114 foreach ( $res as $row ) {
116 $this->cleanupArticle(
126 $this->
output(
"Done\n" );
137 private function cleanupArticle( $id, $domain, $protocol,
Authority $performer ) {
138 $title = Title::newFromID( $id );
140 $this->
error(
"Internal error: no page for ID $id" );
145 $this->
output( $title->getPrefixedDBkey() .
" ..." );
148 $revLookup = $services->getRevisionLookup();
149 $rev = $revLookup->getRevisionByTitle( $title );
150 $currentRevId = $rev->getId();
152 while ( $rev && ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
153 LinkFilter::matchEntry(
155 $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW ),
160 $rev = $revLookup->getPreviousRevision( $rev );
163 if ( $rev && $rev->getId() == $currentRevId ) {
166 $this->
output(
"False match\n" );
168 $page = $services->getWikiPageFactory()->newFromTitle( $title );
171 $content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
173 $this->
output(
"reverting\n" );
174 $page->doUserEditContent(
178 wfMessage(
'spam_reverting', $domain )->inContentLanguage()->text(),
182 } elseif ( $this->
hasOption(
'delete' ) ) {
184 $this->
output(
"deleting\n" );
185 $deletePage = $services->getDeletePageFactory()->newDeletePage( $page, $performer );
186 $deletePage->deleteUnsafe(
wfMessage(
'spam_deleting', $domain )->inContentLanguage()->text() );
189 $handler = $services->getContentHandlerFactory()
190 ->getContentHandler( $title->getContentModel() );
191 $content = $handler->makeEmptyContent();
193 $this->
output(
"blanking\n" );
194 $page->doUserEditContent(
197 wfMessage(
'spam_blanking', $domain )->inContentLanguage()->text(),
207require_once RUN_MAINTENANCE_IF_MAIN;
const EDIT_FORCE_BOT
Mark the edit a "bot" edit regardless of user rights.
const EDIT_UPDATE
Article is assumed to be pre-existing, fail if it doesn't exist.
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MEDIAWIKI')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Maintenance script to cleanup all spam from a given hostname.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option was set.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
$wgLocalDatabases
Config variable stub for the LocalDatabases setting, for use by phpdoc and IDEs.