35require_once __DIR__ .
'/Maintenance.php';
46 parent::__construct();
48 $this->
addOption(
'all',
'Check all wikis in $wgLocalDatabases' );
49 $this->
addOption(
'delete',
'Delete pages containing only spam instead of blanking them' );
52 'Hostname that was spamming, single * wildcard in the beginning allowed'
59 $username =
wfMessage(
'spambot_username' )->text();
60 $user = User::newSystemUser( $username );
62 $this->
fatalError(
"Invalid username specified in 'spambot_username' message: $username" );
66 StubGlobalUser::setUser( $user );
68 $spec = $this->
getArg( 0 );
71 foreach ( [
'http://',
'https://' ] as $prot ) {
72 $conds = LinkFilter::getQueryConditions( $spec, [
'protocol' => $prot ] );
74 $this->
fatalError(
"Not a valid hostname specification: $spec" );
76 $protConds[$prot] = $conds;
87 foreach ( $protConds as $conds ) {
88 $count = $dbr->newSelectQueryBuilder()
89 ->select(
'COUNT(*)' )
90 ->from(
'externallinks' )
92 ->caller( __METHOD__ )
97 "$IP/maintenance/cleanupSpam.php",
98 [
'--wiki', $wikiId, $spec ]
101 passthru(
"$cmd | sed 's/^/$wikiId: /'" );
106 $this->
output(
"All done\n" );
108 $this->
output(
"None found\n" );
116 foreach ( $protConds as $prot => $conds ) {
117 $res = $dbr->newSelectQueryBuilder()
118 ->select(
'el_from' )
120 ->from(
'externallinks' )
122 ->caller( __METHOD__ )
124 $count += $res->numRows();
125 $this->
output(
"Found $count articles containing $spec so far...\n" );
126 foreach ( $res as $row ) {
128 $this->cleanupArticle(
138 $this->
output(
"Done\n" );
149 private function cleanupArticle( $id, $domain, $protocol,
Authority $performer ) {
150 $title = Title::newFromID( $id );
152 $this->
error(
"Internal error: no page for ID $id" );
157 $this->
output( $title->getPrefixedDBkey() .
" ..." );
160 $revLookup = $services->getRevisionLookup();
161 $rev = $revLookup->getRevisionByTitle( $title );
162 $currentRevId = $rev->getId();
164 while ( $rev && ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
165 LinkFilter::matchEntry(
167 $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW ),
172 $rev = $revLookup->getPreviousRevision( $rev );
175 if ( $rev && $rev->getId() == $currentRevId ) {
178 $this->
output(
"False match\n" );
180 $page = $services->getWikiPageFactory()->newFromTitle( $title );
183 $content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
185 $this->
output(
"reverting\n" );
186 $page->doUserEditContent(
190 wfMessage(
'spam_reverting', $domain )->inContentLanguage()->text(),
194 } elseif ( $this->
hasOption(
'delete' ) ) {
196 $this->
output(
"deleting\n" );
197 $deletePage = $services->getDeletePageFactory()->newDeletePage( $page, $performer );
198 $deletePage->deleteUnsafe(
wfMessage(
'spam_deleting', $domain )->inContentLanguage()->text() );
201 $handler = $services->getContentHandlerFactory()
202 ->getContentHandler( $title->getContentModel() );
203 $content = $handler->makeEmptyContent();
205 $this->
output(
"blanking\n" );
206 $page->doUserEditContent(
209 wfMessage(
'spam_blanking', $domain )->inContentLanguage()->text(),
219require_once RUN_MAINTENANCE_IF_MAIN;
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(ini_get('mbstring.func_overload')) 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.