Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php |
— | — | @@ -50,9 +50,7 @@ |
51 | 51 | // Add (any) content to [[MediaWiki:Newusermessage-substitute]] to substitute the welcome template. |
52 | 52 | $substitute = wfMsgForContent( 'newusermessage-substitute' ); |
53 | 53 | |
54 | | - if ( wfRunHooks( 'CreateNewUserMessage', array( $user, $editor, $editSummary, $substitute, $signature ) ) ) { |
55 | | - self::setupAndLeaveMessage( $user, $editor, $editSummary, $substitute, $signature ); |
56 | | - } |
| 54 | + self::setupAndLeaveMessage( $user, $editor, $editSummary, $substitute, $signature ); |
57 | 55 | } |
58 | 56 | return true; |
59 | 57 | } |
— | — | @@ -67,35 +65,64 @@ |
68 | 66 | */ |
69 | 67 | static function setupAndLeaveMessage( $user, $editor, $editSummary, $substitute, $signature ) { |
70 | 68 | $talk = $user->getTalkPage(); |
| 69 | + $article = new Article( $talk ); |
71 | 70 | |
72 | | - $templateTitleText = wfMsg( 'newusermessage-template' ); |
73 | | - $templateTitle = Title::newFromText( $templateTitleText ); |
74 | | - if ( !$templateTitle ) { |
75 | | - wfDebug( __METHOD__ . ": invalid title in newusermessage-template\n" ); |
76 | | - return; |
| 71 | + $subject = ''; |
| 72 | + if ( wfRunHooks( 'SetupNewUserMessageSubject', array( &$subject ) ) ) { |
| 73 | + $subject = wfMsg( 'newusermessage-template-subject' ); |
77 | 74 | } |
78 | 75 | |
79 | | - if ( $templateTitle->getNamespace() == NS_TEMPLATE ) { |
80 | | - $templateTitleText = $templateTitle->getText(); |
| 76 | + $text = ''; |
| 77 | + if ( wfRunHooks( 'SetupNewUserMessageBody', array( &$text ) ) ) { |
| 78 | + $text = wfMsg( 'newusermessage-template-body' ); |
| 79 | + |
| 80 | + $template = Title::newFromText( $text ); |
| 81 | + if ( !$template ) { |
| 82 | + wfDebug( __METHOD__ . ": invalid title in newusermessage-template-body\n" ); |
| 83 | + return; |
| 84 | + } |
| 85 | + |
| 86 | + if ( $template->getNamespace() == NS_TEMPLATE ) { |
| 87 | + $text = $template->getText(); |
| 88 | + } |
81 | 89 | } |
82 | 90 | |
| 91 | + if ( $substitute ) { |
| 92 | + $subject = self::substString( $subject, $user, "preparse" ); |
| 93 | + $text = self::substString( $text, $user ); |
| 94 | + } |
| 95 | + |
| 96 | + global $wgNewUserMinorEdit, $wgNewUserSuppressRC; |
| 97 | + |
| 98 | + $flags = EDIT_NEW; |
| 99 | + if ( $wgNewUserMinorEdit ) $flags = $flags | EDIT_MINOR; |
| 100 | + if ( $wgNewUserSuppressRC ) $flags = $flags | EDIT_SUPPRESS_RC; |
| 101 | + |
| 102 | + return $user->leaveUserMessage( $subject, $text, $signature, $editSummary, $editor, $flags ); |
| 103 | + } |
| 104 | + |
| 105 | + static private function substString( $str, $user, $preparse = null ) { |
83 | 106 | $realName = $user->getRealName(); |
84 | 107 | $name = $user->getName(); |
85 | | - $article = new Article( $talk ); |
86 | 108 | |
87 | | - if ( $substitute ) { |
88 | | - $text = "{{subst:{$templateTitleText}|$name|$realName}}"; |
89 | | - } else { |
90 | | - $text = "{{{$templateTitleText}|$name|$realName}}"; |
91 | | - } |
| 109 | + $str = "{{subst:{{$str}}}|realName=$realName|name=$name}}"; |
92 | 110 | |
93 | | - if ( $signature ) { |
94 | | - $text .= "\n-- {$signature} ~~~~~"; |
| 111 | + if ( $preparse ) { |
| 112 | + /* Create the final subject text. |
| 113 | + * Always substituted and processed by parser to avoid awkward subjects |
| 114 | + */ |
| 115 | + $parser = new Parser; |
| 116 | + $parser->setOutputType( 'wiki' ); |
| 117 | + $parserOptions = new ParserOptions; |
| 118 | + |
| 119 | + $str = $parser->preSaveTransform($str, $talk /* as dummy */, |
| 120 | + $editor, $parserOptions ); |
95 | 121 | } |
96 | 122 | |
97 | | - self::writeWelcomeMessage( $user, $article, $text, $editSummary, $editor ); |
| 123 | + return $str; |
98 | 124 | } |
99 | 125 | |
| 126 | + |
100 | 127 | /** |
101 | 128 | * Hook function to create a message on an auto-created user |
102 | 129 | * @param $user User object of the user |
— | — | @@ -120,67 +147,4 @@ |
121 | 148 | $names[] = 'msg:newusermessage-editor'; |
122 | 149 | return true; |
123 | 150 | } |
124 | | - |
125 | | - /** |
126 | | - * Create a page with text |
127 | | - * @param $user User object: user that was just created |
128 | | - * @param $article Article object: the article where $text is to be put |
129 | | - * @param $text String: text to put in $article |
130 | | - * @param $summary String: edit summary text |
131 | | - * @param $editor User object: user that will make the edit |
132 | | - */ |
133 | | - public static function writeWelcomeMessage( $user, $article, $text, $summary, $editor ) { |
134 | | - global $wgNewUserMinorEdit, $wgNewUserSuppressRC; |
135 | | - |
136 | | - wfLoadExtensionMessages( 'NewUserMessage' ); |
137 | | - |
138 | | - $flags = EDIT_NEW; |
139 | | - if ( $wgNewUserMinorEdit ) $flags = $flags | EDIT_MINOR; |
140 | | - if ( $wgNewUserSuppressRC ) $flags = $flags | EDIT_SUPPRESS_RC; |
141 | | - |
142 | | - $dbw = wfGetDB( DB_MASTER ); |
143 | | - $dbw->begin(); |
144 | | - $good = true; |
145 | | - |
146 | | - try { |
147 | | - $article->doEdit( $text, $summary, $flags, false, $editor ); |
148 | | - } catch ( DBQueryError $e ) { |
149 | | - $good = false; |
150 | | - } |
151 | | - |
152 | | - if ( $good ) { |
153 | | - // Set newtalk with the right user ID |
154 | | - $user->setNewtalk( true ); |
155 | | - $dbw->commit(); |
156 | | - } else { |
157 | | - // The article was concurrently created |
158 | | - wfDebug( __METHOD__ . ": the article has already been created despite !\$talk->exists()\n" ); |
159 | | - $dbw->rollback(); |
160 | | - } |
161 | | - } |
162 | | - |
163 | | - /** |
164 | | - * Returns the text contents of a template page set in given key contents |
165 | | - * Returns empty string if no text could be retrieved. |
166 | | - * @param $key String: message key that should contain a template page name |
167 | | - */ |
168 | | - public static function getTextForPageInKey( $key ) { |
169 | | - $templateTitleText = wfMsgForContent( $key ); |
170 | | - $templateTitle = Title::newFromText( $templateTitleText ); |
171 | | - |
172 | | - // Do not continue if there is no valid subject title |
173 | | - if ( !$templateTitle ) { |
174 | | - wfDebug( __METHOD__ . ": invalid title in " . $key . "\n" ); |
175 | | - return ''; |
176 | | - } |
177 | | - |
178 | | - // Get the subject text from the page |
179 | | - if ( $templateTitle->getNamespace() == NS_TEMPLATE ) { |
180 | | - return $templateTitle->getText(); |
181 | | - } else { |
182 | | - // There is no subject text |
183 | | - wfDebug( __METHOD__ . ": " . $templateTitleText . " must be in NS_TEMPLATE\n" ); |
184 | | - return ''; |
185 | | - } |
186 | | - } |
187 | 151 | } |
Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php |
— | — | @@ -314,6 +314,10 @@ |
315 | 315 | |
316 | 316 | // Reply subpage name |
317 | 317 | 'lqt-reply-subpage' => 'reply', |
| 318 | + |
| 319 | + // New User Welcome Message |
| 320 | + 'lqt-newusermessage-template-subject' => 'Template:Welcome-subject', |
| 321 | + 'lqt-newusermessage-template-body' => 'Template:Welcome-body', |
318 | 322 | ); |
319 | 323 | |
320 | 324 | /** Message documentation (Message documentation) |
— | — | @@ -518,6 +522,8 @@ |
519 | 523 | 'lqt-reply-subpage' => 'Part of the page title when a LiquidThread answer is given. Should probably be translated as a noun and not as a verb. |
520 | 524 | |
521 | 525 | {{Identical|Reply}}', |
| 526 | + 'lqt-newusermessage-template-subject' => 'Always substituted. Used if LiquidThreads is enabled in the User_talk namespace. Do not translate or duplicate this message to other languages', |
| 527 | + 'lqt-newusermessage-template-body' => 'Used if LiquidThreads is enabled in the User_talk namespace. Do not translate or duplicate this message to other languages', |
522 | 528 | ); |
523 | 529 | |
524 | 530 | /** Faeag Rotuma (Faeag Rotuma) |
Index: trunk/extensions/LiquidThreads/LiquidThreads.php |
— | — | @@ -98,8 +98,13 @@ |
99 | 99 | $wgHooks['TitleGetRestrictionTypes'][] = 'LqtHooks::getProtectionTypes'; |
100 | 100 | |
101 | 101 | // New User Messages |
102 | | -$wgHooks['CreateNewUserMessage'][] = 'LqtHooks::createNewUserMessage'; |
| 102 | +$wgHooks['SetupNewUserMessageSubject'][] = 'LqtHooks::setupNewUserMessageSubject'; |
| 103 | +$wgHooks['SetupNewUserMessageSubject'][] = 'LqtHooks::setupNewUserMessageBody'; |
103 | 104 | |
| 105 | +// User Message |
| 106 | +$wgHooks['SetupUserMessageArticle'][] = 'LqtHooks::setupUserMessageArticle'; |
| 107 | +$wgHooks['AfterUserMessage'][] = 'LqtHooks::afterUserMessage'; |
| 108 | + |
104 | 109 | // Special pages |
105 | 110 | $wgSpecialPages['MoveThread'] = 'SpecialMoveThread'; |
106 | 111 | $wgSpecialPages['NewMessages'] = 'SpecialNewMessages'; |
Index: trunk/extensions/LiquidThreads/classes/Hooks.php |
— | — | @@ -483,98 +483,108 @@ |
484 | 484 | return true; |
485 | 485 | } |
486 | 486 | |
487 | | - static function createNewUserMessage( $user, $editor, $editSummary, $substitute, $signature ) { |
488 | | - global $wgLqtTalkPages; |
| 487 | + static function setupNewUserMessageSubject( &$subject ) { |
| 488 | + wfLoadExtensionMessages( 'LiquidThreads' ); |
489 | 489 | |
490 | | - $talk = $user->getTalkPage(); // We already know it exists. |
| 490 | + $subject = self::getTextForPageInKey( 'lqt-newusermessage-template-subject' ); |
| 491 | + // Do not continue if there is no valid subject title |
| 492 | + if ( !$subject ) { |
| 493 | + wfDebug( __METHOD__ . ": no text found for the subject\n" ); |
| 494 | + return true; |
| 495 | + } |
491 | 496 | |
492 | | - if ( $wgLqtTalkPages && LqtDispatch::isLqtPage( $talk ) ) { |
493 | | - $article = new Article( $talk ); |
494 | | - $realName = $user->getRealName(); |
495 | | - $name = $user->getName(); |
| 497 | + return false; |
| 498 | + } |
496 | 499 | |
497 | | - // Get subject text |
498 | | - $threadSubject = NewUserMessage::getTextForPageInKey( 'newusermessage-template-subject' ); |
| 500 | + static function setupNewUserMessageBody( &$text ) { |
| 501 | + wfLoadExtensionMessages( 'LiquidThreads' ); |
499 | 502 | |
500 | | - // Do not continue if there is no valid subject title |
501 | | - if ( !$threadSubject ) { |
502 | | - wfDebug( __METHOD__ . ": no text found for the subject\n" ); |
503 | | - return true; |
504 | | - } |
| 503 | + // Get the body text |
| 504 | + $text = self::getTextForPageInKey( 'lqt-newusermessage-template-body' ); |
505 | 505 | |
506 | | - /** Create the final subject text. |
507 | | - * Always substituted and processed by parser to avoid awkward subjects |
508 | | - * Use real name if new user provided it |
509 | | - */ |
510 | | - $parser = new Parser; |
511 | | - $parser->setOutputType( 'wiki' ); |
512 | | - $parserOptions = new ParserOptions; |
| 506 | + // Do not continue if there is no body text |
| 507 | + if ( !$text ) { |
| 508 | + wfDebug( __METHOD__ . ": no text found for the body\n" ); |
| 509 | + return true; |
| 510 | + } |
513 | 511 | |
514 | | - if ( $realName ) { |
515 | | - $threadSubject = $parser->preSaveTransform( |
516 | | - "{{subst:{$threadSubject}|$realName}}", |
517 | | - $talk /* as dummy */, |
518 | | - $editor, $parserOptions |
519 | | - ); |
520 | | - } else { |
521 | | - $threadSubject = $parser->preSaveTransform( |
522 | | - "{{subst:{$threadSubject}|$name}}", |
523 | | - $talk /* as dummy */, |
524 | | - $editor, |
525 | | - $parserOptions |
526 | | - ); |
527 | | - } |
| 512 | + return false; |
| 513 | + } |
528 | 514 | |
529 | | - // Get the body text |
530 | | - $threadBody = NewUserMessage::getTextForPageInKey( 'newusermessage-template-body' ); |
| 515 | + static function setupUserMessageArticle( &$article, $subject, $user, $editor ) { |
| 516 | + global $wgLqtTalkPages; |
531 | 517 | |
532 | | - // Do not continue if there is no body text |
533 | | - if ( !$threadBody ) { |
534 | | - wfDebug( __METHOD__ . ": no text found for the body\n" ); |
535 | | - return true; |
536 | | - } |
| 518 | + if ( $wgLqtTalkPages && LqtDispatch::isLqtPage( $article->getTitle() ) ) { |
| 519 | + $threadTitle = Threads::newThreadTitle( $subject, $article ); |
537 | 520 | |
538 | | - // Create the final body text after checking if the template is to be substituted. |
539 | | - if ( $substitute ) { |
540 | | - $threadBody = "{{subst:{$threadBody}|$name|$realName}}"; |
541 | | - } else { |
542 | | - $threadBody = "{{{$threadBody}|$name|$realName}}"; |
543 | | - } |
544 | | - |
545 | | - $threadTitle = Threads::newThreadTitle( $threadSubject, $article ); |
546 | | - |
547 | 521 | if ( !$threadTitle ) { |
548 | 522 | wfDebug( __METHOD__ . ": invalid title $threadTitle\n" ); |
549 | 523 | return true; |
550 | 524 | } |
551 | 525 | |
552 | | - $threadArticle = new Article( $threadTitle ); |
553 | | - NewUserMessage::writeWelcomeMessage( $user, $threadArticle, $threadBody, $editSummary, $editor ); |
| 526 | + $article = new Article( $threadTitle ); |
| 527 | + return false; |
| 528 | + } |
| 529 | + return true; |
| 530 | + } |
554 | 531 | |
| 532 | + static function afterUserMessage( $user, $article, $summary, $signature, $editor, $text ) { |
| 533 | + global $wgLqtTalkPages; |
| 534 | + $talk = $user->getTalkPage(); |
| 535 | + |
| 536 | + if ( $wgLqtTalkPages && LqtDispatch::isLqtPage( $talk ) ) { |
555 | 537 | // Need to edit as another user. Lqt does not provide an interface to alternative users, |
556 | 538 | // so replacing $wgUser here. |
557 | 539 | global $wgUser; |
558 | 540 | $parkedUser = $wgUser; |
559 | 541 | $wgUser = $editor; |
560 | 542 | |
| 543 | + $title = preg_replace( "{/[^/]+}", "", $article->getTitle()->getBaseText() ); |
| 544 | + $baseArticle = new Article( Title::newFromText( $title ) ); |
| 545 | + $threadTitle = preg_replace( "{.*/([^/]+)}", '$1', $article->getTitle()->getBaseText() ); |
| 546 | + |
561 | 547 | LqtView::newPostMetadataUpdates( |
562 | 548 | array( |
563 | | - 'talkpage' => $article, |
564 | | - 'text' => $threadBody, |
565 | | - 'summary' => $editSummary, |
566 | | - 'root' => $threadArticle, |
567 | | - 'subject' => $threadSubject, |
| 549 | + 'talkpage' => $baseArticle, |
| 550 | + 'text' => $text, |
| 551 | + 'summary' => $summary, |
| 552 | + 'root' => $article, |
| 553 | + 'subject' => $threadTitle, |
568 | 554 | 'signature' => $signature, |
569 | 555 | ) |
570 | 556 | ); |
571 | 557 | |
572 | 558 | // Set $wgUser back to the newly created user |
573 | 559 | $wgUser = $parkedUser; |
574 | | - |
575 | | - // Stop processing after this hook. |
576 | 560 | return false; |
577 | 561 | } |
578 | 562 | return true; |
579 | 563 | } |
580 | 564 | |
| 565 | + /** |
| 566 | + * Returns the text contents of a template page set in given key contents |
| 567 | + * Returns empty string if no text could be retrieved. |
| 568 | + * @param $key String: message key that should contain a template page name |
| 569 | + */ |
| 570 | + private static function getTextForPageInKey( $key ) { |
| 571 | + wfLoadExtensionMessages( 'LiquidThreads' ); |
| 572 | + |
| 573 | + $templateTitleText = wfMsgForContent( $key ); |
| 574 | + $templateTitle = Title::newFromText( $templateTitleText ); |
| 575 | + |
| 576 | + // Do not continue if there is no valid subject title |
| 577 | + if ( !$templateTitle ) { |
| 578 | + wfDebug( __METHOD__ . ": invalid title in " . $key . "\n" ); |
| 579 | + return ''; |
| 580 | + } |
| 581 | + |
| 582 | + // Get the subject text from the page |
| 583 | + if ( $templateTitle->getNamespace() == NS_TEMPLATE ) { |
| 584 | + return $templateTitle->getText(); |
| 585 | + } else { |
| 586 | + // There is no subject text |
| 587 | + wfDebug( __METHOD__ . ": " . $templateTitleText . " must be in NS_TEMPLATE\n" ); |
| 588 | + return ''; |
| 589 | + } |
| 590 | + } |
581 | 591 | } |