r38765 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38764‎ | r38765 | r38766 >
Date:10:44, 7 August 2008
Author:tstarling
Status:old
Tags:
Comment:
* Create the notifying user if it doesn't exist, don't just use some random reserved user
* Reserve the notifying user's username (requires phase3 r38763)
* Don't blank the user talk page if someone else edited in the same second as the account was created
* Use the Template namespace for templates, not the MediaWiki namespace -- that's what it's for. Use a sensible default title.
Modified paths:
  • /trunk/extensions/NewUserMessage/NewUserMessage.class.php (modified) (history)
  • /trunk/extensions/NewUserMessage/NewUserMessage.i18n.php (modified) (history)
  • /trunk/extensions/NewUserMessage/NewUserMessage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NewUserMessage/NewUserMessage.i18n.php
@@ -11,19 +11,17 @@
1212 * @author [http://www.organicdesign.co.nz/User:Nad Nad]
1313 */
1414 $messages['en'] = array(
15 - 'newusermessage-desc' => "Adds a [[MediaWiki:NewUserMessage|message]] to newly created user's talk pages",
16 - 'newuseredit-summary' => 'Adding [[{{MediaWiki:Newusermessage-template}}|welcome message]] to new user\'s talk page',
17 -
18 - // Configuration (should not be translated)
19 - 'newusermessage-template' => 'MediaWiki:NewUserMessage', # do not translate this message to other languages
20 - 'newusermessage-editor' => 'MediaWiki default', # do not translate this message to other languages
 15+ 'newusermessage-desc' => "Adds a message to newly created user's talk pages",
 16+ 'newuseredit-summary' => 'Adding [[{{int:newusermessage-template}}|welcome message]] to new user\'s talk page',
 17+ 'newusermessage-template' => 'Template:Welcome', // The title of the message template
 18+ 'newusermessage-editor' => 'New user message', // The username used for the edit
2119 );
2220
2321 /** Afrikaans (Afrikaans)
2422 * @author Naudefj
2523 */
2624 $messages['af'] = array(
27 - 'newusermessage-desc' => "Plaas 'n [[MediaWiki:NewUserMessage|boodskap]] op alle nuwe gebruikers se besprekingsbladsye",
 25+ 'newusermessage-desc' => "Plaas 'n [[Template:NewUserMessage|boodskap]] op alle nuwe gebruikers se besprekingsbladsye",
2826 );
2927
3028 /** Arabic (العربية)
Index: trunk/extensions/NewUserMessage/NewUserMessage.php
@@ -22,6 +22,7 @@
2323 $wgAutoloadClasses['NewUserMessage'] = $dir . 'NewUserMessage.class.php';
2424
2525 $wgHooks['AddNewAccount'][] = 'NewUserMessage::createNewUserMessage';
 26+$wgHooks['UserGetReservedNames'][] = 'NewUserMessage::onUserGetReservedNames';
2627
2728 $wgExtensionCredits['other'][] = array(
2829 'name' => 'NewUserMessage',
Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php
@@ -30,24 +30,52 @@
3131 // Need to make the edit on the user talk page in another
3232 // user's context. Park the current user object and create
3333 // a user object for $editingUser. If that user does not
34 - // exist, make the edit as reserved user
35 - // "MediaWiki default".
 34+ // exist, create it.
3635 $parkedWgUser = $wgUser;
37 - $editingUser = wfMsg( 'newusermessage-editor' );
38 - if( User::idFromName( $editingUser ) ) {
39 - $wgUser = User::newFromName( $editingUser );
 36+ $wgUser = User::newFromName( wfMsgForContent( 'newusermessage-editor' ) );
 37+ if ( !$wgUser->isLoggedIn() ) {
 38+ $wgUser->addToDatabase();
4039 }
41 - else
42 - $wgUser = User::newFromName( "MediaWiki default" );
4340
44 - $flags = 0;
45 - $messageTemplate = wfMsg( 'newusermessage-template' );
 41+ $flags = EDIT_NEW;
 42+ $templateTitleText = wfMsg( 'newusermessage-template' );
 43+ $templateTitle = Title::newFromText( $templateTitleText );
 44+ if ( !$templateTitle ) {
 45+ wfDebug( __METHOD__. ": invalid title in newusermessage-template\n" );
 46+ return true;
 47+ }
 48+ if ( $templateTitle->getNamespace() == NS_TEMPLATE ) {
 49+ $templateTitleText = $templateTitle->getText();
 50+ }
4651 if ($wgNewUserMinorEdit) $flags = $flags | EDIT_MINOR;
4752 if ($wgNewUserSupressRC) $flags = $flags | EDIT_SUPPRESS_RC;
4853
49 - $article->doEdit('{'.'{'."$messageTemplate|$name}}", wfMsg( 'newuseredit-summary' ), $flags);
 54+ $dbw = wfGetDB( DB_MASTER );
 55+ $dbw->begin();
 56+ $good = true;
 57+ try {
 58+ $article->doEdit("{{{$templateTitleText}|$name}}", wfMsgForContent( 'newuseredit-summary' ), $flags);
 59+ } catch ( DBQueryError $e ) {
 60+ $good = false;
 61+ }
 62+
 63+ if ( $good ) {
 64+ // Set newtalk with the right user ID
 65+ $user->setNewtalk( true );
 66+ $dbw->commit();
 67+ } else {
 68+ // The article was concurrently created
 69+ wfDebug( __METHOD__. ": the article has already been created despite !\$talk->exists()\n" );
 70+ $dbw->rollback();
 71+ }
5072 $wgUser = $parkedWgUser;
5173 }
5274 return true;
5375 }
 76+
 77+ static function onUserGetReservedNames( &$names ) {
 78+ wfLoadExtensionMessages( 'NewUserMessage' );
 79+ $names[] = 'msg:newusermessage-editor';
 80+ return true;
 81+ }
5482 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r38763Changes for NewUserMessage:...tstarling10:39, 7 August 2008

Status & tagging log