r37370 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37369‎ | r37370 | r37371 >
Date:07:02, 9 July 2008
Author:werdna
Status:old
Tags:
Comment:
Add log entries for actions done by the extension. Also, properly scramble conflicting accounts by resetting email too
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.i18n.php (modified) (history)
  • /trunk/extensions/AbuseFilter/install.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -376,6 +376,7 @@
377377 wfLoadExtensionMessages( 'AbuseFilter' );
378378
379379 global $wgUser;
 380+ $filterUser = AbuseFilter::getFilterUser();
380381
381382 // Create a block.
382383 $block = new Block;
@@ -392,6 +393,16 @@
393394
394395 $block->insert();
395396
 397+ // Log it
 398+ # Prepare log parameters
 399+ $logParams = array();
 400+ $logParams[] = 'indefinite';
 401+ $logParams[] = 'nocreate, angry-autoblock';
 402+
 403+ $log = new LogPage( 'block' );
 404+ $log->addEntry( 'block', Title::makeTitle( NS_USER, $wgUser->getName() ),
 405+ wfMsgForContent( 'abusefilter-blockreason', $rule_desc ), $logParams, self::getFilterUser() );
 406+
396407 $display .= wfMsgNoTrans( 'abusefilter-blocked-display', $rule_desc ) ."<br />\n";
397408 break;
398409 case 'throttle':
@@ -421,6 +432,18 @@
422433
423434 $display .= wfMsgNoTrans( 'abusefilter-degrouped', $rule_desc ) ."<br />\n";
424435
 436+ // Log it.
 437+ $log = new LogPage( 'rights' );
 438+
 439+ $log->addEntry( 'rights',
 440+ $wgUser->getUserPage(),
 441+ wfMsgForContent( 'abusefilter-degroupreason', $rule_desc ),
 442+ array(
 443+ implode( ', ', $groups ),
 444+ wfMsgForContent( 'rightsnone' )
 445+ )
 446+ , self::getFilterUser() );
 447+
425448 break;
426449 case 'blockautopromote':
427450 wfLoadExtensionMessages( 'AbuseFilter' );
@@ -513,4 +536,36 @@
514537 public static function autoPromoteBlockKey( $user ) {
515538 return wfMemcKey( 'abusefilter', 'block-autopromote', $user->getId() );
516539 }
 540+
 541+ public static function getFilterUser() {
 542+ wfLoadExtensionMessages( 'AbuseFilter' );
 543+
 544+ $user = User::newFromName( wfMsgForContent( 'abusefilter-blocker' ) );
 545+ $user->load();
 546+ if ($user->getId() && $user->mPassword == '') {
 547+ // Already set up.
 548+ return $user;
 549+ }
 550+
 551+ // Not set up. Create it.
 552+
 553+ if (!$user->getId()) {
 554+ $user->addToDatabase();
 555+ $user->saveSettings();
 556+ } else {
 557+ // Take over the account
 558+ $user->setPassword( null );
 559+ $user->setEmail( null );
 560+ $user->saveSettings();
 561+ }
 562+
 563+ # Promote user so it doesn't look too crazy.
 564+ $user->addGroup( 'sysop' );
 565+
 566+ # Increment site_stats.ss_users
 567+ $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
 568+ $ssu->doUpdate();
 569+
 570+ return $user;
 571+ }
517572 }
Index: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
@@ -40,8 +40,10 @@
4141 'abusefilter-autopromote-blocked' => "This action has been automatically identified as harmful, and it has been disallowed.
4242 In addition, as a security measure, some privileges routinely granted to established accounts have been temporarily revoked from your account.
4343 A brief description of the abuse rule which your action matched is: $1",
 44+
4445 'abusefilter-blocker' => 'Abuse filter',
4546 'abusefilter-blockreason' => 'Automatically blocked by abuse filter. Rule description: $1',
 47+ 'abusefilter-degroupreason' => 'Rights automatically stripped by abuse filter. Rule description: $1',
4648
4749 'abusefilter-accountreserved' => 'This account name is reserved for use by the abuse filter.',
4850
Index: trunk/extensions/AbuseFilter/install.php
@@ -20,6 +20,7 @@
2121 } else {
2222 // Sorry dude, we need this account.
2323 $user->setPassword( null );
 24+ $user->setEmail( null );
2425 $user->saveSettings();
2526 }
2627

Status & tagging log