Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php |
— | — | @@ -141,6 +141,7 @@ |
142 | 142 | $talk = $user->getTalkPage(); |
143 | 143 | |
144 | 144 | if ( !$talk->exists() ) { |
| 145 | + $article = new Article( $talk ); |
145 | 146 | $subject = self::fetchSubject(); |
146 | 147 | $text = self::fetchText(); |
147 | 148 | $signature = self::fetchSignature(); |
— | — | @@ -151,8 +152,8 @@ |
152 | 153 | $subject = self::substString( $subject, $user, $editor, $talk, "preparse" ); |
153 | 154 | $text = self::substString( $text, $user, $editor, $talk ); |
154 | 155 | |
155 | | - return $user->leaveUserMessage( $subject, $text, $signature, $editSummary, |
156 | | - $editor, $flags ); |
| 156 | + return self::leaveUserMessage( $user, $article, $subject, $text, |
| 157 | + $signature, $editSummary, $editor, $flags ); |
157 | 158 | } |
158 | 159 | } |
159 | 160 | |
— | — | @@ -179,4 +180,62 @@ |
180 | 181 | $names[] = 'msg:newusermessage-editor'; |
181 | 182 | return true; |
182 | 183 | } |
| 184 | + |
| 185 | + /** |
| 186 | + * Leave a user a message |
| 187 | + * @param $subject String the subject of the message |
| 188 | + * @param $text String the message to leave |
| 189 | + * @param $signature String Text to leave in the signature |
| 190 | + * @param $summary String the summary for this change, defaults to |
| 191 | + * "Leave system message." |
| 192 | + * @param $editor User The user leaving the message, defaults to |
| 193 | + * "{{MediaWiki:usermessage-editor}}" |
| 194 | + * @param $flags Int default edit flags |
| 195 | + * |
| 196 | + * @return boolean true if it was successful |
| 197 | + */ |
| 198 | + public static function leaveUserMessage( $user, $article, $subject, $text, $signature, |
| 199 | + $summary, $editor, $flags ) { |
| 200 | + |
| 201 | + $text = self::formatUserMessage( $subject, $text, $signature ); |
| 202 | + $flags = $article->checkFlags( $flags ); |
| 203 | + |
| 204 | + if ( $flags & EDIT_UPDATE ) { |
| 205 | + $text = $article->getContent() . $text; |
| 206 | + } |
| 207 | + |
| 208 | + $dbw = wfGetDB( DB_MASTER ); |
| 209 | + $dbw->begin(); |
| 210 | + |
| 211 | + try { |
| 212 | + $status = $article->doEdit( $text, $summary, $flags, false, $editor ); |
| 213 | + } catch ( DBQueryError $e ) { |
| 214 | + $status = Status::newFatal( 'DB Error' ); |
| 215 | + } |
| 216 | + |
| 217 | + if ( $status->isGood() ) { |
| 218 | + // Set newtalk with the right user ID |
| 219 | + $user->setNewtalk( true ); |
| 220 | + $dbw->commit(); |
| 221 | + } else { |
| 222 | + // The article was concurrently created |
| 223 | + wfDebug( __METHOD__ . ": Error ".$status->getWikiText() ); |
| 224 | + $dbw->rollback(); |
| 225 | + } |
| 226 | + |
| 227 | + return $status->isGood(); |
| 228 | + } |
| 229 | + |
| 230 | + /** |
| 231 | + * Format the user message using a hook, a template, or, failing these, a static format. |
| 232 | + * @param $subject String the subject of the message |
| 233 | + * @param $text String the content of the message |
| 234 | + * @param $signature String the signature, if provided. |
| 235 | + */ |
| 236 | + static protected function formatUserMessage( $subject, $text, $signature ) { |
| 237 | + $signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~"; |
| 238 | + $text = "\n== $subject ==\n\n$text\n\n-- $signature"; |
| 239 | + |
| 240 | + return $text; |
| 241 | + } |
183 | 242 | } |
Index: trunk/phase3/includes/User.php |
— | — | @@ -3767,91 +3767,7 @@ |
3768 | 3768 | return $ret; |
3769 | 3769 | } |
3770 | 3770 | |
3771 | | - /** |
3772 | | - * Format the user message using a hook, a template, or, failing these, a static format. |
3773 | | - * @param $subject String the subject of the message |
3774 | | - * @param $text String the content of the message |
3775 | | - * @param $signature String the signature, if provided. |
3776 | | - */ |
3777 | | - static protected function formatUserMessage( $subject, $text, $signature ) { |
3778 | | - if ( wfRunHooks( 'FormatUserMessage', |
3779 | | - array( $subject, &$text, $signature ) ) ) { |
3780 | 3771 | |
3781 | | - $signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~"; |
3782 | 3772 | |
3783 | | - $template = Title::newFromText( wfMsgForContent( 'usermessage-template' ) ); |
3784 | | - if ( !$template |
3785 | | - || $template->getNamespace() !== NS_TEMPLATE |
3786 | | - || !$template->exists() ) { |
3787 | | - $text = "\n== $subject ==\n\n$text\n\n-- $signature"; |
3788 | | - } else { |
3789 | | - $text = '{{'. $template->getText() |
3790 | | - . " | subject=$subject | body=$text | signature=$signature }}"; |
3791 | | - } |
3792 | | - } |
3793 | 3773 | |
3794 | | - return $text; |
3795 | | - } |
3796 | | - |
3797 | | - /** |
3798 | | - * Leave a user a message |
3799 | | - * @param $subject String the subject of the message |
3800 | | - * @param $text String the message to leave |
3801 | | - * @param $signature String Text to leave in the signature |
3802 | | - * @param $summary String the summary for this change, defaults to |
3803 | | - * "Leave system message." |
3804 | | - * @param $editor User The user leaving the message, defaults to |
3805 | | - * "{{MediaWiki:usermessage-editor}}" |
3806 | | - * @param $flags Int default edit flags |
3807 | | - * |
3808 | | - * @return boolean true if it was successful |
3809 | | - */ |
3810 | | - public function leaveUserMessage( $subject, $text, $signature = "", |
3811 | | - $summary = null, $editor = null, $flags = 0 ) { |
3812 | | - if ( !isset( $summary ) ) { |
3813 | | - $summary = wfMsgForContent( 'usermessage-summary' ); |
3814 | | - } |
3815 | | - |
3816 | | - if ( !isset( $editor ) ) { |
3817 | | - $editor = User::newFromName( wfMsgForContent( 'usermessage-editor' ) ); |
3818 | | - if ( !$editor->isLoggedIn() ) { |
3819 | | - $editor->addToDatabase(); |
3820 | | - } |
3821 | | - } |
3822 | | - |
3823 | | - $article = new Article( $this->getTalkPage() ); |
3824 | | - wfRunHooks( 'SetupUserMessageArticle', |
3825 | | - array( $this, &$article, $subject, $text, $signature, $summary, $editor ) ); |
3826 | | - |
3827 | | - |
3828 | | - $text = self::formatUserMessage( $subject, $text, $signature ); |
3829 | | - $flags = $article->checkFlags( $flags ); |
3830 | | - |
3831 | | - if ( $flags & EDIT_UPDATE ) { |
3832 | | - $text = $article->getContent() . $text; |
3833 | | - } |
3834 | | - |
3835 | | - $dbw = wfGetDB( DB_MASTER ); |
3836 | | - $dbw->begin(); |
3837 | | - |
3838 | | - try { |
3839 | | - $status = $article->doEdit( $text, $summary, $flags, false, $editor ); |
3840 | | - } catch ( DBQueryError $e ) { |
3841 | | - $status = Status::newFatal("DB Error"); |
3842 | | - } |
3843 | | - |
3844 | | - if ( $status->isGood() ) { |
3845 | | - // Set newtalk with the right user ID |
3846 | | - $this->setNewtalk( true ); |
3847 | | - wfRunHooks( 'AfterUserMessage', |
3848 | | - array( $this, $article, $subject, $text, $signature, $summary, $editor ) ); |
3849 | | - $dbw->commit(); |
3850 | | - } else { |
3851 | | - // The article was concurrently created |
3852 | | - wfDebug( __METHOD__ . ": Error ".$status->getWikiText() ); |
3853 | | - $dbw->rollback(); |
3854 | | - } |
3855 | | - |
3856 | | - return $status->isGood(); |
3857 | | - } |
3858 | 3774 | } |