28require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
40 $this->
addOption(
'all',
'Check all wikis in $wgLocalDatabases' );
41 $this->
addOption(
'delete',
'Delete pages containing only spam instead of blanking them' );
44 'Hostname that was spamming, single * wildcard in the beginning allowed'
51 $username =
wfMessage(
'spambot_username' )->text();
54 $this->
fatalError(
"Invalid username specified in 'spambot_username' message: $username" );
57 $user->addGroup(
'bot' );
60 $spec = $this->
getArg( 0 );
63 foreach ( [
'http://',
'https://' ] as $prot ) {
66 $this->
fatalError(
"Not a valid hostname specification: $spec" );
68 $protConds[$prot] = $conds;
79 foreach ( $protConds as $conds ) {
80 $count =
$dbr->selectField(
89 "$IP/maintenance/cleanupSpam.php",
90 [
'--wiki', $wikiId, $spec ]
92 passthru(
"$cmd | sed 's/^/$wikiId: /'" );
97 $this->
output(
"All done\n" );
99 $this->
output(
"None found\n" );
107 foreach ( $protConds as $prot => $conds ) {
110 [
'DISTINCT el_from' ],
115 $this->
output(
"Found $count articles containing $spec\n" );
116 foreach (
$res as $row ) {
126 $this->
output(
"Done\n" );
139 $title = Title::newFromID( $id );
141 $this->
error(
"Internal error: no page for ID $id" );
148 $revLookup = MediaWikiServices::getInstance()->getRevisionLookup();
149 $rev = $revLookup->getRevisionByTitle(
$title );
150 $currentRevId = $rev->getId();
152 while ( $rev && ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
154 $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW ),
159 $rev = $revLookup->getPreviousRevision( $rev );
162 if ( $rev && $rev->getId() == $currentRevId ) {
165 $this->
output(
"False match\n" );
169 $page = WikiPage::factory(
$title );
172 $content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
174 $this->
output(
"reverting\n" );
175 $page->doEditContent(
177 wfMessage(
'spam_reverting', $domain )->inContentLanguage()->text(),
181 } elseif ( $this->
hasOption(
'delete' ) ) {
183 $this->
output(
"deleting\n" );
184 $page->doDeleteArticleReal(
185 wfMessage(
'spam_deleting', $domain )->inContentLanguage()->text(),
190 $handler = MediaWikiServices::getInstance()
191 ->getContentHandlerFactory()
192 ->getContentHandler(
$title->getContentModel() );
193 $content = $handler->makeEmptyContent();
195 $this->
output(
"blanking\n" );
196 $page->doEditContent(
198 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, User $deleter)
__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 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.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.