Add newuser log to core
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 13 Sep 2008 00:29:33 +0000 (00:29 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 13 Sep 2008 00:29:33 +0000 (00:29 +0000)
includes/DefaultSettings.php
includes/LogEventsList.php
includes/Setup.php
includes/User.php
includes/specials/SpecialUserlogin.php
languages/messages/MessagesEn.php

index d149d9f..81d5a10 100644 (file)
@@ -2747,6 +2747,11 @@ $wgLogActions = array(
  */
 $wgLogActionsHandlers = array();
 
+/**
+ * Maintain a log of newusers at Log/newusers?
+ */
+$wgNewUserLog = true;
+
 /**
  * List of special pages, followed by what subtitle they should go under
  * at Special:SpecialPages
index b189667..5f4fa72 100644 (file)
@@ -279,10 +279,22 @@ class LogEventsList {
                                $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'], 
                                        'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
                        }
+               // Self-created users
+               } else if( self::typeAction($row,'newusers','create2') ) {
+                       if( isset( $paramArray[0] ) ) {
+                               $revert = $this->skin->userToolLinks( $paramArray[0], $title->getDBkey(), true );
+                       } else {
+                               # Fall back to a blue contributions link
+                               $revert = $this->skin->userToolLinks( 1, $title->getDBkey() );
+                       }
+                       if( $time < '20080129000000' ) {
+                               # Suppress $comment from old entries (before 2008-01-29), not needed and can contain incorrect links
+                               $comment = '';
+                       }
+               // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
                } else {
                        wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
                                &$comment, &$revert, $row->log_timestamp ) );
-                       // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
                }
                // Event description
                if( self::isDeleted($row,LogPage::DELETED_ACTION) ) {
index ecc6def..b03e188 100644 (file)
@@ -315,6 +315,16 @@ wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
 
+if( !empty($wgNewUserLog) ) {
+       # Add a new log type
+       $wgLogTypes[]                        = 'newusers';
+       $wgLogNames['newusers']              = 'newuserlogpage';
+       $wgLogHeaders['newusers']            = 'newuserlogpagetext';
+       $wgLogActions['newusers/newusers']   = 'newuserlogentry'; // For compatibility with older log entries
+       $wgLogActions['newusers/create']     = 'newuserlog-create-entry';
+       $wgLogActions['newusers/create2']    = 'newuserlog-create2-entry';
+       $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
+}
 
 wfDebug( "Fully initialised\n" );
 $wgFullyInitialised = true;
index 5fa2ff5..bc4b131 100644 (file)
@@ -3194,4 +3194,41 @@ class User {
                        return self::oldCrypt( $password, $userId ) === $hash;
                }
        }
+       
+       /**
+        * Add a newuser log entry for this user
+        * @param bool $byEmail, account made by email?
+        */
+       public function addNewUserLogEntry( $byEmail = false ) {
+               global $wgUser, $wgContLang, $wgNewUserLog;
+               if( empty($wgNewUserLog) ) {
+                       return true; // disabled
+               }
+               $talk = $wgContLang->getFormattedNsText( NS_TALK );
+               if( $this->getName() == $wgUser->getName() ) {
+                       $action = 'create';
+                       $message = '';
+               } else {
+                       $action = 'create2';
+                       $message = $byEmail ? wfMsgForContent( 'newuserlog-byemail' ) : '';
+               }
+               $log = new LogPage( 'newusers' );
+               $log->addEntry( $action, $this->getUserPage(), $message, array( $this->getId() ) );
+               return true;
+       }
+
+       /**
+        * Add an autocreate newuser log entry for this user
+        * Used by things like CentralAuth and perhaps other authplugins.
+        */
+       public static function addNewUserLogEntryAutoCreate() {
+               global $wgNewUserLog;
+               if( empty($wgNewUserLog) ) {
+                       return true; // disabled
+               }
+               $log = new LogPage( 'newusers', false );
+               $log->addEntry( 'autocreate', $this->getUserPage(), '', array( $this->getId() ) );
+               return true;
+       }
+
 }
index 9d5cce9..b6908c9 100644 (file)
@@ -129,6 +129,7 @@ class LoginForm {
                $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
 
                wfRunHooks( 'AddNewAccount', array( $u, true ) );
+               $u->addNewUserLogEntry();
 
                $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
@@ -182,6 +183,7 @@ class LoginForm {
                        $wgUser = $u;
                        $wgUser->setCookies();
                        wfRunHooks( 'AddNewAccount', array( $wgUser ) );
+                       $wgUser->addNewUserLogEntry();
                        if( $this->hasSessionCookie() ) {
                                return $this->successfulCreation();
                        } else {
@@ -197,6 +199,7 @@ class LoginForm {
                        $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
                        $wgOut->returnToMain( false, $self );
                        wfRunHooks( 'AddNewAccount', array( $u ) );
+                       $u->addNewUserLogEntry();
                        return true;
                }
        }
index 5d3ee52..f103509 100644 (file)
@@ -2107,6 +2107,16 @@ Also see [[Special:WantedCategories|wanted categories]].',
 'listusers-submit'   => 'Show',
 'listusers-noresult' => 'No user found.',
 
+# New user log
+'newuserlogpage'              => 'User creation log',
+'newuserlogpagetext'          => 'This is a log of user creations.',
+'newuserlog-desc'             => 'Adds a [[Special:Log/newusers|log of account creations]]',
+'newuserlogentry'             => '', # For compatibility, do not translate this
+'newuserlog-byemail'          => 'password sent by e-mail',
+'newuserlog-create-entry'     => 'New user',
+'newuserlog-create2-entry'    => 'created account for $1',
+'newuserlog-autocreate-entry' => 'Account created automatically',
+
 # Special:ListGroupRights
 'listgrouprights'                 => 'User group rights',
 'listgrouprights-summary'         => 'The following is a list of user groups defined on this wiki, with their associated access rights.