Index: trunk/extensions/NewUserMessage/NewUserMessage.i18n.php |
— | — | @@ -11,19 +11,17 @@ |
12 | 12 | * @author [http://www.organicdesign.co.nz/User:Nad Nad] |
13 | 13 | */ |
14 | 14 | $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 |
21 | 19 | ); |
22 | 20 | |
23 | 21 | /** Afrikaans (Afrikaans) |
24 | 22 | * @author Naudefj |
25 | 23 | */ |
26 | 24 | $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", |
28 | 26 | ); |
29 | 27 | |
30 | 28 | /** Arabic (العربية) |
Index: trunk/extensions/NewUserMessage/NewUserMessage.php |
— | — | @@ -22,6 +22,7 @@ |
23 | 23 | $wgAutoloadClasses['NewUserMessage'] = $dir . 'NewUserMessage.class.php'; |
24 | 24 | |
25 | 25 | $wgHooks['AddNewAccount'][] = 'NewUserMessage::createNewUserMessage'; |
| 26 | +$wgHooks['UserGetReservedNames'][] = 'NewUserMessage::onUserGetReservedNames'; |
26 | 27 | |
27 | 28 | $wgExtensionCredits['other'][] = array( |
28 | 29 | 'name' => 'NewUserMessage', |
Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php |
— | — | @@ -30,24 +30,52 @@ |
31 | 31 | // Need to make the edit on the user talk page in another |
32 | 32 | // user's context. Park the current user object and create |
33 | 33 | // 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. |
36 | 35 | $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(); |
40 | 39 | } |
41 | | - else |
42 | | - $wgUser = User::newFromName( "MediaWiki default" ); |
43 | 40 | |
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 | + } |
46 | 51 | if ($wgNewUserMinorEdit) $flags = $flags | EDIT_MINOR; |
47 | 52 | if ($wgNewUserSupressRC) $flags = $flags | EDIT_SUPPRESS_RC; |
48 | 53 | |
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 | + } |
50 | 72 | $wgUser = $parkedWgUser; |
51 | 73 | } |
52 | 74 | return true; |
53 | 75 | } |
| 76 | + |
| 77 | + static function onUserGetReservedNames( &$names ) { |
| 78 | + wfLoadExtensionMessages( 'NewUserMessage' ); |
| 79 | + $names[] = 'msg:newusermessage-editor'; |
| 80 | + return true; |
| 81 | + } |
54 | 82 | } |