r66676 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66675‎ | r66676 | r66677 >
Date:02:16, 20 May 2010
Author:mah
Status:deferred
Tags:
Comment:
* LiquidThreads:
* Fix typo in LiquidThreads hook setup that kept one of the hooks from being called.
* NewUserMessage:
* Adapt hook arguments to changes in trunk for NewUserMessage
* Clean-up/refactor createNewUserMessage() so it reads straight.
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Hooks.php (modified) (history)
  • /trunk/extensions/NewUserMessage/NewUserMessage.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php
@@ -14,64 +14,60 @@
1515 die( 'Not an entry point.' );
1616
1717 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
2122 */
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+ }
2430
25 - if ( !$talk->exists() ) {
26 - global $wgUser;
 31+ return $editor;
 32+ }
2733
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 = '';
2941
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];
3748 }
 49+ }
3850
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;
5752 }
5853
5954 /**
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
6657 */
67 - static function setupAndLeaveMessage( $user, $editor, $editSummary, $substitute, $signature ) {
68 - $talk = $user->getTalkPage();
69 - $article = new Article( $talk );
70 -
 58+ static function fetchSubject() {
7159 $subject = '';
7260 if ( wfRunHooks( 'SetupNewUserMessageSubject', array( &$subject ) ) ) {
7361 $subject = wfMsg( 'newusermessage-template-subject' );
7462 }
7563
 64+ return $subject;
 65+ }
 66+
 67+ /**
 68+ * Produce the text of the message.
 69+ * @returns String
 70+ */
 71+ static function fetchText() {
7672 $text = '';
7773 if ( wfRunHooks( 'SetupNewUserMessageBody', array( &$text ) ) ) {
7874 $text = wfMsg( 'newusermessage-template-body' );
@@ -86,21 +82,30 @@
8783 $text = $template->getText();
8884 }
8985 }
 86+ return $text;
 87+ }
9088
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() {
9694 global $wgNewUserMinorEdit, $wgNewUserSuppressRC;
9795
9896 $flags = EDIT_NEW;
9997 if ( $wgNewUserMinorEdit ) $flags = $flags | EDIT_MINOR;
10098 if ( $wgNewUserSuppressRC ) $flags = $flags | EDIT_SUPPRESS_RC;
10199
102 - return $user->leaveUserMessage( $subject, $text, $signature, $editSummary, $editor, $flags );
 100+ return $flags;
103101 }
104102
 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+ */
105110 static private function substString( $str, $user, $preparse = null ) {
106111 $realName = $user->getRealName();
107112 $name = $user->getName();
@@ -122,7 +127,35 @@
123128 return $str;
124129 }
125130
 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();
126137
 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+
127160 /**
128161 * Hook function to create a message on an auto-created user
129162 * @param $user User object of the user
Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -99,7 +99,7 @@
100100
101101 // New User Messages
102102 $wgHooks['SetupNewUserMessageSubject'][] = 'LqtHooks::setupNewUserMessageSubject';
103 -$wgHooks['SetupNewUserMessageSubject'][] = 'LqtHooks::setupNewUserMessageBody';
 103+$wgHooks['SetupNewUserMessageBody'][] = 'LqtHooks::setupNewUserMessageBody';
104104
105105 // User Message
106106 $wgHooks['SetupUserMessageArticle'][] = 'LqtHooks::setupUserMessageArticle';
Index: trunk/extensions/LiquidThreads/classes/Hooks.php
@@ -488,7 +488,8 @@
489489 wfLoadExtensionMessages( 'LiquidThreads' );
490490
491491 $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
493494 if ( !$subject ) {
494495 wfDebug( __METHOD__ . ": no text found for the subject\n" );
495496 return true;
@@ -503,7 +504,7 @@
504505 // Get the body text
505506 $text = self::getTextForPageInKey( 'lqt-newusermessage-template-body' );
506507
507 - // Do not continue if there is no body text
 508+ // Let someone else take over if we didn't get a valid body
508509 if ( !$text ) {
509510 wfDebug( __METHOD__ . ": no text found for the body\n" );
510511 return true;
@@ -512,7 +513,7 @@
513514 return false;
514515 }
515516
516 - static function setupUserMessageArticle( &$article, $subject, $user, $editor ) {
 517+ static function setupUserMessageArticle( $user, &$article, $subject, $text, $signature, $summary, $editor ) {
517518 global $wgLqtTalkPages;
518519
519520 if ( $wgLqtTalkPages && LqtDispatch::isLqtPage( $article->getTitle() ) ) {
@@ -529,7 +530,7 @@
530531 return true;
531532 }
532533
533 - static function afterUserMessage( $user, $article, $summary, $signature, $editor, $text ) {
 534+ static function afterUserMessage( $user, $article, $subject, $text, $signature, $summary, $editor ) {
534535 global $wgLqtTalkPages;
535536 $talk = $user->getTalkPage();
536537

Status & tagging log