Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php |
— | — | @@ -14,64 +14,60 @@ |
15 | 15 | die( 'Not an entry point.' ); |
16 | 16 | |
17 | 17 | class NewUserMessage { |
18 | | - /* |
19 | | - * Add the message if the users talk page does not already exist |
20 | | - * @param $user User object |
| 18 | + |
| 19 | + /** |
| 20 | + * Produce the editor for new user messages. |
| 21 | + * @returns User |
21 | 22 | */ |
22 | | - static function createNewUserMessage( $user ) { |
23 | | - $talk = $user->getTalkPage(); |
| 23 | + static function fetchEditor() { |
| 24 | + // Create a user object for the editing user and add it to the |
| 25 | + // database if it is not there already |
| 26 | + $editor = User::newFromName( wfMsgForContent( 'newusermessage-editor' ) ); |
| 27 | + if ( !$editor->isLoggedIn() ) { |
| 28 | + $editor->addToDatabase(); |
| 29 | + } |
24 | 30 | |
25 | | - if ( !$talk->exists() ) { |
26 | | - global $wgUser; |
| 31 | + return $editor; |
| 32 | + } |
27 | 33 | |
28 | | - wfLoadExtensionMessages( 'NewUserMessage' ); |
| 34 | + /** |
| 35 | + * Produce a (possibly random) signature. |
| 36 | + * @returns String |
| 37 | + */ |
| 38 | + static function fetchSignature() { |
| 39 | + $signatures = wfMsgForContent( 'newusermessage-signatures' ); |
| 40 | + $signature = ''; |
29 | 41 | |
30 | | - $editSummary = wfMsgForContent( 'newuseredit-summary' ); |
31 | | - |
32 | | - // Create a user object for the editing user and add it to the |
33 | | - // database if it is not there already |
34 | | - $editor = User::newFromName( wfMsgForContent( 'newusermessage-editor' ) ); |
35 | | - if ( !$editor->isLoggedIn() ) { |
36 | | - $editor->addToDatabase(); |
| 42 | + if ( !wfEmptyMsg( 'newusermessage-signatures', $signatures ) ) { |
| 43 | + $pattern = '/^\* ?(.*?)$/m'; |
| 44 | + preg_match_all( $pattern, $signatures, $signatureList, PREG_SET_ORDER ); |
| 45 | + if ( count( $signatureList ) > 0 ) { |
| 46 | + $rand = rand( 0, count( $signatureList ) - 1 ); |
| 47 | + $signature = $signatureList[$rand][1]; |
37 | 48 | } |
| 49 | + } |
38 | 50 | |
39 | | - $signatures = wfMsgForContent( 'newusermessage-signatures' ); |
40 | | - $signature = null; |
41 | | - |
42 | | - if ( !wfEmptyMsg( 'newusermessage-signatures', $signatures ) ) { |
43 | | - $pattern = '/^\* ?(.*?)$/m'; |
44 | | - preg_match_all( $pattern, $signatures, $signatureList, PREG_SET_ORDER ); |
45 | | - if ( count( $signatureList ) > 0 ) { |
46 | | - $rand = rand( 0, count( $signatureList ) - 1 ); |
47 | | - $signature = $signatureList[$rand][1]; |
48 | | - } |
49 | | - } |
50 | | - |
51 | | - // Add (any) content to [[MediaWiki:Newusermessage-substitute]] to substitute the welcome template. |
52 | | - $substitute = wfMsgForContent( 'newusermessage-substitute' ); |
53 | | - |
54 | | - self::setupAndLeaveMessage( $user, $editor, $editSummary, $substitute, $signature ); |
55 | | - } |
56 | | - return true; |
| 51 | + return $signature; |
57 | 52 | } |
58 | 53 | |
59 | 54 | /** |
60 | | - * Take care of some housekeeping before leaving the actual message |
61 | | - * @param $user User the user object who's talk page is being created |
62 | | - * @param $editor User the user that we'll use to leave the message |
63 | | - * @param $editSummary String the edit summary |
64 | | - * @param $substitute Bool Template text needs substitution |
65 | | - * @param $signature String the signature |
| 55 | + * Produce a subject for the message. |
| 56 | + * @returns String |
66 | 57 | */ |
67 | | - static function setupAndLeaveMessage( $user, $editor, $editSummary, $substitute, $signature ) { |
68 | | - $talk = $user->getTalkPage(); |
69 | | - $article = new Article( $talk ); |
70 | | - |
| 58 | + static function fetchSubject() { |
71 | 59 | $subject = ''; |
72 | 60 | if ( wfRunHooks( 'SetupNewUserMessageSubject', array( &$subject ) ) ) { |
73 | 61 | $subject = wfMsg( 'newusermessage-template-subject' ); |
74 | 62 | } |
75 | 63 | |
| 64 | + return $subject; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Produce the text of the message. |
| 69 | + * @returns String |
| 70 | + */ |
| 71 | + static function fetchText() { |
76 | 72 | $text = ''; |
77 | 73 | if ( wfRunHooks( 'SetupNewUserMessageBody', array( &$text ) ) ) { |
78 | 74 | $text = wfMsg( 'newusermessage-template-body' ); |
— | — | @@ -86,21 +82,30 @@ |
87 | 83 | $text = $template->getText(); |
88 | 84 | } |
89 | 85 | } |
| 86 | + return $text; |
| 87 | + } |
90 | 88 | |
91 | | - if ( $substitute ) { |
92 | | - $subject = self::substString( $subject, $user, "preparse" ); |
93 | | - $text = self::substString( $text, $user ); |
94 | | - } |
95 | | - |
| 89 | + /** |
| 90 | + * Produce the flags to set on Article::doEdit |
| 91 | + * @returns Int |
| 92 | + */ |
| 93 | + static function fetchFlags() { |
96 | 94 | global $wgNewUserMinorEdit, $wgNewUserSuppressRC; |
97 | 95 | |
98 | 96 | $flags = EDIT_NEW; |
99 | 97 | if ( $wgNewUserMinorEdit ) $flags = $flags | EDIT_MINOR; |
100 | 98 | if ( $wgNewUserSuppressRC ) $flags = $flags | EDIT_SUPPRESS_RC; |
101 | 99 | |
102 | | - return $user->leaveUserMessage( $subject, $text, $signature, $editSummary, $editor, $flags ); |
| 100 | + return $flags; |
103 | 101 | } |
104 | 102 | |
| 103 | + /** |
| 104 | + * Take care of substition on the string in a uniform manner |
| 105 | + * @param $str String |
| 106 | + * @param $user User |
| 107 | + * @param $preparse if provided, then preparse the string using a Parser |
| 108 | + * @returns String |
| 109 | + */ |
105 | 110 | static private function substString( $str, $user, $preparse = null ) { |
106 | 111 | $realName = $user->getRealName(); |
107 | 112 | $name = $user->getName(); |
— | — | @@ -122,7 +127,35 @@ |
123 | 128 | return $str; |
124 | 129 | } |
125 | 130 | |
| 131 | + /** |
| 132 | + * Add the message if the users talk page does not already exist |
| 133 | + * @param $user User object |
| 134 | + */ |
| 135 | + static function createNewUserMessage( $user ) { |
| 136 | + $talk = $user->getTalkPage(); |
126 | 137 | |
| 138 | + if ( !$talk->exists() ) { |
| 139 | + wfLoadExtensionMessages( 'NewUserMessage' ); |
| 140 | + |
| 141 | + $subject = self::fetchSubject(); |
| 142 | + $text = self::fetchText(); |
| 143 | + $signature = self::fetchSignature(); |
| 144 | + $editSummary = wfMsgForContent( 'newuseredit-summary' ); |
| 145 | + $editor = self::fetchEditor(); |
| 146 | + $flags = self::fetchFlags(); |
| 147 | + |
| 148 | + // Add (any) content to [[MediaWiki:Newusermessage-substitute]] to substitute the welcome template. |
| 149 | + $substitute = wfMsgForContent( 'newusermessage-substitute' ); |
| 150 | + |
| 151 | + if ( $substitute ) { |
| 152 | + $subject = self::substString( $subject, $user, "preparse" ); |
| 153 | + $text = self::substString( $text, $user ); |
| 154 | + } |
| 155 | + |
| 156 | + return $user->leaveUserMessage( $subject, $text, $signature, $editSummary, $editor, $flags ); |
| 157 | + } |
| 158 | + } |
| 159 | + |
127 | 160 | /** |
128 | 161 | * Hook function to create a message on an auto-created user |
129 | 162 | * @param $user User object of the user |
Index: trunk/extensions/LiquidThreads/LiquidThreads.php |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | |
101 | 101 | // New User Messages |
102 | 102 | $wgHooks['SetupNewUserMessageSubject'][] = 'LqtHooks::setupNewUserMessageSubject'; |
103 | | -$wgHooks['SetupNewUserMessageSubject'][] = 'LqtHooks::setupNewUserMessageBody'; |
| 103 | +$wgHooks['SetupNewUserMessageBody'][] = 'LqtHooks::setupNewUserMessageBody'; |
104 | 104 | |
105 | 105 | // User Message |
106 | 106 | $wgHooks['SetupUserMessageArticle'][] = 'LqtHooks::setupUserMessageArticle'; |
Index: trunk/extensions/LiquidThreads/classes/Hooks.php |
— | — | @@ -488,7 +488,8 @@ |
489 | 489 | wfLoadExtensionMessages( 'LiquidThreads' ); |
490 | 490 | |
491 | 491 | $subject = self::getTextForPageInKey( 'lqt-newusermessage-template-subject' ); |
492 | | - // Do not continue if there is no valid subject title |
| 492 | + |
| 493 | + // Let someone else take over if we didn't get a valid subject |
493 | 494 | if ( !$subject ) { |
494 | 495 | wfDebug( __METHOD__ . ": no text found for the subject\n" ); |
495 | 496 | return true; |
— | — | @@ -503,7 +504,7 @@ |
504 | 505 | // Get the body text |
505 | 506 | $text = self::getTextForPageInKey( 'lqt-newusermessage-template-body' ); |
506 | 507 | |
507 | | - // Do not continue if there is no body text |
| 508 | + // Let someone else take over if we didn't get a valid body |
508 | 509 | if ( !$text ) { |
509 | 510 | wfDebug( __METHOD__ . ": no text found for the body\n" ); |
510 | 511 | return true; |
— | — | @@ -512,7 +513,7 @@ |
513 | 514 | return false; |
514 | 515 | } |
515 | 516 | |
516 | | - static function setupUserMessageArticle( &$article, $subject, $user, $editor ) { |
| 517 | + static function setupUserMessageArticle( $user, &$article, $subject, $text, $signature, $summary, $editor ) { |
517 | 518 | global $wgLqtTalkPages; |
518 | 519 | |
519 | 520 | if ( $wgLqtTalkPages && LqtDispatch::isLqtPage( $article->getTitle() ) ) { |
— | — | @@ -529,7 +530,7 @@ |
530 | 531 | return true; |
531 | 532 | } |
532 | 533 | |
533 | | - static function afterUserMessage( $user, $article, $summary, $signature, $editor, $text ) { |
| 534 | + static function afterUserMessage( $user, $article, $subject, $text, $signature, $summary, $editor ) { |
534 | 535 | global $wgLqtTalkPages; |
535 | 536 | $talk = $user->getTalkPage(); |
536 | 537 | |