Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php |
— | — | @@ -51,16 +51,35 @@ |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
| 55 | + * Return the template name if it exists, or '' otherwise. |
| 56 | + * @returns string |
| 57 | + */ |
| 58 | + static function fetchTemplateIfExists( $template ) { |
| 59 | + $text = Title::newFromText( $template ); |
| 60 | + |
| 61 | + if ( !$text ) { |
| 62 | + wfDebug( __METHOD__ . ": '$template' is not a valid title.\n" ); |
| 63 | + return ''; |
| 64 | + } elseif ( $text->getNamespace() !== NS_TEMPLATE ) { |
| 65 | + wfDebug( __METHOD__ . ": '$template' is not a valid Template.\n" ); |
| 66 | + return ''; |
| 67 | + } elseif ( !$text->exists() ) { |
| 68 | + return ''; |
| 69 | + |
| 70 | + if ( $template->getNamespace() == NS_TEMPLATE ) { |
| 71 | + $text = $template->getText(); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + return $text->getText(); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
55 | 79 | * Produce a subject for the message. |
56 | 80 | * @returns String |
57 | 81 | */ |
58 | 82 | static function fetchSubject() { |
59 | | - $subject = ''; |
60 | | - if ( wfRunHooks( 'SetupNewUserMessageSubject', array( &$subject ) ) ) { |
61 | | - $subject = wfMsg( 'newusermessage-template-subject' ); |
62 | | - } |
63 | | - |
64 | | - return $subject; |
| 83 | + return self::fetchTemplateIfExists( wfMsg( 'newusermessage-template-subject' ) ); |
65 | 84 | } |
66 | 85 | |
67 | 86 | /** |
— | — | @@ -68,21 +87,7 @@ |
69 | 88 | * @returns String |
70 | 89 | */ |
71 | 90 | static function fetchText() { |
72 | | - $text = ''; |
73 | | - if ( wfRunHooks( 'SetupNewUserMessageBody', array( &$text ) ) ) { |
74 | | - $text = wfMsg( 'newusermessage-template-body' ); |
75 | | - |
76 | | - $template = Title::newFromText( $text ); |
77 | | - if ( !$template ) { |
78 | | - wfDebug( __METHOD__ . ": invalid title in newusermessage-template-body\n" ); |
79 | | - return; |
80 | | - } |
81 | | - |
82 | | - if ( $template->getNamespace() == NS_TEMPLATE ) { |
83 | | - $text = $template->getText(); |
84 | | - } |
85 | | - } |
86 | | - return $text; |
| 91 | + return self::fetchTemplateIfExists( wfMsg( 'newusermessage-template-body' ) ); |
87 | 92 | } |
88 | 93 | |
89 | 94 | /** |
— | — | @@ -103,25 +108,29 @@ |
104 | 109 | * Take care of substition on the string in a uniform manner |
105 | 110 | * @param $str String |
106 | 111 | * @param $user User |
| 112 | + * @param $editor User |
| 113 | + * @param $talk Article |
107 | 114 | * @param $preparse if provided, then preparse the string using a Parser |
108 | 115 | * @returns String |
109 | 116 | */ |
110 | | - static private function substString( $str, $user, $preparse = null ) { |
| 117 | + static private function substString( $str, $user, $editor, $talk, $preparse = null ) { |
111 | 118 | $realName = $user->getRealName(); |
112 | 119 | $name = $user->getName(); |
113 | 120 | |
114 | | - $str = "{{subst:{{$str}}}|realName=$realName|name=$name}}"; |
| 121 | + // Add (any) content to [[MediaWiki:Newusermessage-substitute]] to substitute the |
| 122 | + // welcome template. |
| 123 | + $substitute = wfMsgForContent( 'newusermessage-substitute' ); |
115 | 124 | |
| 125 | + if ( $substitute ) { |
| 126 | + $str = "{{subst:{{$str}}}|realName=$realName|name=$name}}"; |
| 127 | + } else { |
| 128 | + $str = "{{{$str}|realName=$realName|name=$name}}"; |
| 129 | + } |
| 130 | + |
116 | 131 | if ( $preparse ) { |
117 | | - /* Create the final subject text. |
118 | | - * Always substituted and processed by parser to avoid awkward subjects |
119 | | - */ |
120 | | - $parser = new Parser; |
121 | | - $parser->setOutputType( 'wiki' ); |
122 | | - $parserOptions = new ParserOptions; |
| 132 | + global $wgParser; |
123 | 133 | |
124 | | - $str = $parser->preSaveTransform($str, $talk /* as dummy */, |
125 | | - $editor, $parserOptions ); |
| 134 | + $str = $wgParser->preSaveTransform($str, $talk, $editor, new ParserOptions ); |
126 | 135 | } |
127 | 136 | |
128 | 137 | return $str; |
— | — | @@ -144,15 +153,11 @@ |
145 | 154 | $editor = self::fetchEditor(); |
146 | 155 | $flags = self::fetchFlags(); |
147 | 156 | |
148 | | - // Add (any) content to [[MediaWiki:Newusermessage-substitute]] to substitute the welcome template. |
149 | | - $substitute = wfMsgForContent( 'newusermessage-substitute' ); |
| 157 | + $subject = self::substString( $subject, $user, $editor, $talk, "preparse" ); |
| 158 | + $text = self::substString( $text, $user, $editor, $talk ); |
150 | 159 | |
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 ); |
| 160 | + return $user->leaveUserMessage( $subject, $text, $signature, $editSummary, |
| 161 | + $editor, $flags ); |
157 | 162 | } |
158 | 163 | } |
159 | 164 | |