29require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
41 $this->
addOption(
'all',
'Check all wikis in $wgLocalDatabases' );
42 $this->
addOption(
'delete',
'Delete pages containing only spam instead of blanking them' );
45 'Hostname that was spamming, single * wildcard in the beginning allowed'
52 $username =
wfMessage(
'spambot_username' )->text();
55 $this->
fatalError(
"Invalid username specified in 'spambot_username' message: $username" );
58 MediaWikiServices::getInstance()->getUserGroupManager()->addUserToGroup( $user,
'bot' );
61 $spec = $this->
getArg( 0 );
64 foreach ( [
'http://',
'https://' ] as $prot ) {
67 $this->
fatalError(
"Not a valid hostname specification: $spec" );
69 $protConds[$prot] = $conds;
80 foreach ( $protConds as $conds ) {
81 $count =
$dbr->selectField(
90 "$IP/maintenance/cleanupSpam.php",
91 [
'--wiki', $wikiId, $spec ]
93 passthru(
"$cmd | sed 's/^/$wikiId: /'" );
98 $this->
output(
"All done\n" );
100 $this->
output(
"None found\n" );
108 foreach ( $protConds as $prot => $conds ) {
111 [
'DISTINCT el_from' ],
116 $this->
output(
"Found $count articles containing $spec\n" );
117 foreach (
$res as $row ) {
127 $this->
output(
"Done\n" );
140 $title = Title::newFromID( $id );
142 $this->
error(
"Internal error: no page for ID $id" );
149 $services = MediaWikiServices::getInstance();
150 $revLookup = $services->getRevisionLookup();
151 $rev = $revLookup->getRevisionByTitle(
$title );
152 $currentRevId = $rev->getId();
154 while ( $rev && ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
156 $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW ),
161 $rev = $revLookup->getPreviousRevision( $rev );
164 if ( $rev && $rev->getId() == $currentRevId ) {
167 $this->
output(
"False match\n" );
171 $page = $services->getWikiPageFactory()->newFromTitle(
$title );
174 $content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
176 $this->
output(
"reverting\n" );
177 $page->doUserEditContent(
180 wfMessage(
'spam_reverting', $domain )->inContentLanguage()->text(),
184 } elseif ( $this->
hasOption(
'delete' ) ) {
186 $this->
output(
"deleting\n" );
187 $page->doDeleteArticleReal(
188 wfMessage(
'spam_deleting', $domain )->inContentLanguage()->text(),
193 $handler = $services->getContentHandlerFactory()
194 ->getContentHandler(
$title->getContentModel() );
195 $content = $handler->makeEmptyContent();
197 $this->
output(
"blanking\n" );
198 $page->doUserEditContent(
201 wfMessage(
'spam_blanking', $domain )->inContentLanguage()->text(),
211require_once RUN_MAINTENANCE_IF_MAIN;
string[] $wgLocalDatabases
Other wikis on this site, can be administered from a single developer account.
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.
Maintenance script to cleanup all spam from a given hostname.
__construct()
Default constructor.
cleanupArticle( $id, $domain, $protocol, Authority $performer)
execute()
Do the actual work.
static getQueryConditions( $filterEntry, array $options=[])
Return query conditions which will match the specified string.
static matchEntry(Content $content, $filterEntry, $protocol='http://')
Check whether $content contains a link to $filterEntry.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true)
Add some args that are needed.
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DBs to catch up.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static setUser( $user)
Reset the stub global user to a different "real" user object, while ensuring that any method calls on...
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.