From e8215b27e423c14f7db68ddd75550e526aba80c2 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 13 Sep 2008 00:29:33 +0000 Subject: [PATCH] Add newuser log to core --- includes/DefaultSettings.php | 5 ++++ includes/LogEventsList.php | 14 +++++++++- includes/Setup.php | 10 +++++++ includes/User.php | 37 ++++++++++++++++++++++++++ includes/specials/SpecialUserlogin.php | 3 +++ languages/messages/MessagesEn.php | 10 +++++++ 6 files changed, 78 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index d149d9fcdd..81d5a10f39 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index b189667773..5f4fa7251c 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -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) ) { diff --git a/includes/Setup.php b/includes/Setup.php index ecc6deff73..b03e1884c2 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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; diff --git a/includes/User.php b/includes/User.php index 5fa2ff5c28..bc4b13192c 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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; + } + } diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index 9d5cce926f..b6908c94f2 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -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; } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 5d3ee52427..f10350938b 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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. -- 2.20.1