r40769 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40768‎ | r40769 | r40770 >
Date:00:29, 13 September 2008
Author:aaron
Status:old
Tags:
Comment:
Add newuser log to core
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuthHooks.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/ConfirmAccount_body.php (modified) (history)
  • /trunk/extensions/Newuserlog/Newuserlog.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -3194,4 +3194,41 @@
31953195 return self::oldCrypt( $password, $userId ) === $hash;
31963196 }
31973197 }
 3198+
 3199+ /**
 3200+ * Add a newuser log entry for this user
 3201+ * @param bool $byEmail, account made by email?
 3202+ */
 3203+ public function addNewUserLogEntry( $byEmail = false ) {
 3204+ global $wgUser, $wgContLang, $wgNewUserLog;
 3205+ if( empty($wgNewUserLog) ) {
 3206+ return true; // disabled
 3207+ }
 3208+ $talk = $wgContLang->getFormattedNsText( NS_TALK );
 3209+ if( $this->getName() == $wgUser->getName() ) {
 3210+ $action = 'create';
 3211+ $message = '';
 3212+ } else {
 3213+ $action = 'create2';
 3214+ $message = $byEmail ? wfMsgForContent( 'newuserlog-byemail' ) : '';
 3215+ }
 3216+ $log = new LogPage( 'newusers' );
 3217+ $log->addEntry( $action, $this->getUserPage(), $message, array( $this->getId() ) );
 3218+ return true;
 3219+ }
 3220+
 3221+ /**
 3222+ * Add an autocreate newuser log entry for this user
 3223+ * Used by things like CentralAuth and perhaps other authplugins.
 3224+ */
 3225+ public static function addNewUserLogEntryAutoCreate() {
 3226+ global $wgNewUserLog;
 3227+ if( empty($wgNewUserLog) ) {
 3228+ return true; // disabled
 3229+ }
 3230+ $log = new LogPage( 'newusers', false );
 3231+ $log->addEntry( 'autocreate', $this->getUserPage(), '', array( $this->getId() ) );
 3232+ return true;
 3233+ }
 3234+
31983235 }
Index: trunk/phase3/includes/Setup.php
@@ -315,6 +315,16 @@
316316 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
317317 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
318318
 319+if( !empty($wgNewUserLog) ) {
 320+ # Add a new log type
 321+ $wgLogTypes[] = 'newusers';
 322+ $wgLogNames['newusers'] = 'newuserlogpage';
 323+ $wgLogHeaders['newusers'] = 'newuserlogpagetext';
 324+ $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
 325+ $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
 326+ $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
 327+ $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
 328+}
319329
320330 wfDebug( "Fully initialised\n" );
321331 $wgFullyInitialised = true;
Index: trunk/phase3/includes/LogEventsList.php
@@ -279,10 +279,22 @@
280280 $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
281281 'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
282282 }
 283+ // Self-created users
 284+ } else if( self::typeAction($row,'newusers','create2') ) {
 285+ if( isset( $paramArray[0] ) ) {
 286+ $revert = $this->skin->userToolLinks( $paramArray[0], $title->getDBkey(), true );
 287+ } else {
 288+ # Fall back to a blue contributions link
 289+ $revert = $this->skin->userToolLinks( 1, $title->getDBkey() );
 290+ }
 291+ if( $time < '20080129000000' ) {
 292+ # Suppress $comment from old entries (before 2008-01-29), not needed and can contain incorrect links
 293+ $comment = '';
 294+ }
 295+ // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
283296 } else {
284297 wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
285298 &$comment, &$revert, $row->log_timestamp ) );
286 - // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
287299 }
288300 // Event description
289301 if( self::isDeleted($row,LogPage::DELETED_ACTION) ) {
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2748,6 +2748,11 @@
27492749 $wgLogActionsHandlers = array();
27502750
27512751 /**
 2752+ * Maintain a log of newusers at Log/newusers?
 2753+ */
 2754+$wgNewUserLog = true;
 2755+
 2756+/**
27522757 * List of special pages, followed by what subtitle they should go under
27532758 * at Special:SpecialPages
27542759 */
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -129,6 +129,7 @@
130130 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
131131
132132 wfRunHooks( 'AddNewAccount', array( $u, true ) );
 133+ $u->addNewUserLogEntry();
133134
134135 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
135136 $wgOut->setRobotPolicy( 'noindex,nofollow' );
@@ -182,6 +183,7 @@
183184 $wgUser = $u;
184185 $wgUser->setCookies();
185186 wfRunHooks( 'AddNewAccount', array( $wgUser ) );
 187+ $wgUser->addNewUserLogEntry();
186188 if( $this->hasSessionCookie() ) {
187189 return $this->successfulCreation();
188190 } else {
@@ -197,6 +199,7 @@
198200 $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
199201 $wgOut->returnToMain( false, $self );
200202 wfRunHooks( 'AddNewAccount', array( $u ) );
 203+ $u->addNewUserLogEntry();
201204 return true;
202205 }
203206 }
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2107,6 +2107,16 @@
21082108 'listusers-submit' => 'Show',
21092109 'listusers-noresult' => 'No user found.',
21102110
 2111+# New user log
 2112+'newuserlogpage' => 'User creation log',
 2113+'newuserlogpagetext' => 'This is a log of user creations.',
 2114+'newuserlog-desc' => 'Adds a [[Special:Log/newusers|log of account creations]]',
 2115+'newuserlogentry' => '', # For compatibility, do not translate this
 2116+'newuserlog-byemail' => 'password sent by e-mail',
 2117+'newuserlog-create-entry' => 'New user',
 2118+'newuserlog-create2-entry' => 'created account for $1',
 2119+'newuserlog-autocreate-entry' => 'Account created automatically',
 2120+
21112121 # Special:ListGroupRights
21122122 'listgrouprights' => 'User group rights',
21132123 'listgrouprights-summary' => 'The following is a list of user groups defined on this wiki, with their associated access rights.
Index: trunk/extensions/Newuserlog/Newuserlog.php
@@ -1,5 +1,5 @@
22 <?php
3 -if (!defined('MEDIAWIKI')) die();
 3+if( !defined('MEDIAWIKI') ) die();
44 /**
55 * Add a new log to Special:Log that displays account creations in reverse
66 * chronological order using the AddNewAccount hook
@@ -21,22 +21,26 @@
2222 'author' => 'Ævar Arnfjörð Bjarmason'
2323 );
2424
25 -$wgExtensionMessagesFiles['Newuserlog'] = dirname(__FILE__) . '/Newuserlog.i18n.php';
 25+if( isset($wgNewUserLog) ) {
 26+ echo( "You must remove the newuserlog extension, as it is now in the core software!\n" );
 27+} else {
 28+ # Run this hook on new account creation
 29+ $wgHooks['AddNewAccount'][] = 'wfNewuserlogHook';
 30+ $wgHooks['AuthPluginAutoCreate'][] = 'wfNewuserlogAutoCreate';
 31+ # Run this hook on Special:Log
 32+ $wgHooks['LogLine'][] = 'wfNewuserlogLogLine';
 33+ # Set message file
 34+ $wgExtensionMessagesFiles['Newuserlog'] = dirname(__FILE__) . '/Newuserlog.i18n.php';
 35+ # Add a new log type
 36+ $wgLogTypes[] = 'newusers';
 37+ $wgLogNames['newusers'] = 'newuserlogpage';
 38+ $wgLogHeaders['newusers'] = 'newuserlogpagetext';
 39+ $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
 40+ $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
 41+ $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
 42+ $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
 43+}
2644
27 -# Add a new log type
28 -$wgLogTypes[] = 'newusers';
29 -$wgLogNames['newusers'] = 'newuserlogpage';
30 -$wgLogHeaders['newusers'] = 'newuserlogpagetext';
31 -$wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
32 -$wgLogActions['newusers/create'] = 'newuserlog-create-entry';
33 -$wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
34 -$wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
35 -# Run this hook on new account creation
36 -$wgHooks['AddNewAccount'][] = 'wfNewuserlogHook';
37 -$wgHooks['AuthPluginAutoCreate'][] = 'wfNewuserlogAutoCreate';
38 -# Run this hook on Special:Log
39 -$wgHooks['LogLine'][] = 'wfNewuserlogLogLine';
40 -
4145 function wfNewuserlogHook( $user = null, $byEmail = false ) {
4246 global $wgUser, $wgContLang;
4347
@@ -80,7 +84,9 @@
8185 * @param string $time timestamp of the log entry
8286 * @return bool true
8387 */
84 -function wfNewuserlogLogLine( $log_type = '', $log_action = '', $title = null, $paramArray = array(), &$comment = '', &$revert = '', $time = '' ) {
 88+function wfNewuserlogLogLine( $log_type = '', $log_action = '', $title = null, $paramArray = array(),
 89+ &$comment = '', &$revert = '', $time = '' )
 90+{
8591 if ( $log_action == 'create2' ) {
8692 global $wgUser;
8793 $skin = $wgUser->getSkin();
Index: trunk/extensions/CentralAuth/CentralAuthHooks.php
@@ -393,6 +393,7 @@
394394
395395 # Notify hooks (e.g. Newuserlog)
396396 wfRunHooks( 'AuthPluginAutoCreate', array( $user ) );
 397+ $user->addNewUserLogEntryAutoCreate();
397398 return true;
398399 }
399400
Index: trunk/extensions/ConfirmAccount/ConfirmAccount_body.php
@@ -558,6 +558,7 @@
559559
560560 # Safe to hook/log now...
561561 wfRunHooks( 'AddNewAccount', array( $user ) );
 562+ $user->addNewUserLogEntry();
562563 # OK, now remove the request from the queue
563564 $dbw->delete( 'account_requests', array('acr_id' => $this->acrID), __METHOD__ );
564565 # Clear cache for notice of how many account requests there are

Follow-up revisions

RevisionCommit summaryAuthorDate
r40777* add OBSOLETE to Newuserlog. Was added to core in MediaWiki 1.14alpha r40769...siebrand08:11, 13 September 2008
r40779Cleanup after r40723, r40769, and r40770. C'mon guys. Messages need to be reg...siebrand08:32, 13 September 2008