Go to the documentation of this file.
26 require_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();
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" );
132 $this->
error(
"Internal error: no page for ID $id" );
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" );
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()
175 $content = $handler->makeEmptyContent();
177 $this->
output(
"blanking\n" );
178 $page->doEditContent(
180 wfMessage(
'spam_blanking', $domain )->inContentLanguage()->text(),
const RUN_MAINTENANCE_IF_MAIN
string[] $wgLocalDatabases
Other wikis on this site, can be administered from a single developer account.
Maintenance script to cleanup all spam from a given hostname.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
cleanupArticle( $id, $domain, $protocol)
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
__construct()
Default constructor.
addArg( $arg, $description, $required=true)
Add some args that are needed.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
execute()
Do the actual work.
getArg( $argId=0, $default=null)
Get an argument.
static newFromID( $id, $flags=0)
Create a new Title from an article ID.