26require_once __DIR__ .
'/Maintenance.php';
36 parent::__construct();
38 $this->
addOption(
'all',
'Check all wikis in $wgLocalDatabases' );
39 $this->
addOption(
'delete',
'Delete pages containing only spam instead of blanking them' );
42 'Hostname that was spamming, single * wildcard in the beginning allowed'
49 $username =
wfMessage(
'spambot_username' )->text();
50 $wgUser = User::newSystemUser( $username );
52 $this->
fatalError(
"Invalid username specified in 'spambot_username' message: $username" );
55 $wgUser->addGroup(
'bot' );
57 $spec = $this->
getArg( 0 );
60 foreach ( [
'http://',
'https://' ] as $prot ) {
63 $this->
fatalError(
"Not a valid hostname specification: $spec" );
65 $protConds[$prot] = $conds;
76 foreach ( $protConds as $conds ) {
77 $count =
$dbr->selectField(
86 "$IP/maintenance/cleanupSpam.php",
87 [
'--wiki', $wikiId, $spec ]
89 passthru(
"$cmd | sed 's/^/$wikiId: /'" );
94 $this->
output(
"All done\n" );
96 $this->
output(
"None found\n" );
104 foreach ( $protConds as $prot => $conds ) {
107 [
'DISTINCT el_from' ],
112 $this->
output(
"Found $count articles containing $spec\n" );
113 foreach (
$res as $row ) {
118 $this->
output(
"Done\n" );
130 $title = Title::newFromID( $id );
132 $this->
error(
"Internal error: no page for ID $id" );
138 $rev = Revision::newFromTitle(
$title );
139 $currentRevId = $rev->getId();
141 while ( $rev && ( $rev->isDeleted( RevisionRecord::DELETED_TEXT )
144 $rev = $rev->getPrevious();
147 if ( $rev && $rev->getId() == $currentRevId ) {
150 $this->
output(
"False match\n" );
154 $page = WikiPage::factory(
$title );
157 $content = $rev->getContent( RevisionRecord::RAW );
159 $this->
output(
"reverting\n" );
160 $page->doEditContent(
162 wfMessage(
'spam_reverting', $domain )->inContentLanguage()->text(),
166 } elseif ( $this->
hasOption(
'delete' ) ) {
168 $this->
output(
"deleting\n" );
169 $page->doDeleteArticle(
170 wfMessage(
'spam_deleting', $domain )->inContentLanguage()->text()
174 $handler = ContentHandler::getForTitle(
$title );
175 $content = $handler->makeEmptyContent();
177 $this->
output(
"blanking\n" );
178 $page->doEditContent(
180 wfMessage(
'spam_blanking', $domain )->inContentLanguage()->text(),
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.
const RUN_MAINTENANCE_IF_MAIN
Maintenance script to cleanup all spam from a given hostname.
cleanupArticle( $id, $domain, $protocol)
__construct()
Default constructor.
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 transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation 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 exists.
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.