r81612 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81611‎ | r81612 | r81613 >
Date:22:44, 6 February 2011
Author:btongminh
Status:resolved (Comments)
Tags:brion 
Comment:
Per CR r66438 and IRC, revert User::leaveNewMessage for now. Copied the function and stripped it down for use in NewUserMessage. Could probably need some cleanup.
Modified paths:
  • /trunk/extensions/NewUserMessage/NewUserMessage.class.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/extensions/NewUserMessage/NewUserMessage.class.php
@@ -141,6 +141,7 @@
142142 $talk = $user->getTalkPage();
143143
144144 if ( !$talk->exists() ) {
 145+ $article = new Article( $talk );
145146 $subject = self::fetchSubject();
146147 $text = self::fetchText();
147148 $signature = self::fetchSignature();
@@ -151,8 +152,8 @@
152153 $subject = self::substString( $subject, $user, $editor, $talk, "preparse" );
153154 $text = self::substString( $text, $user, $editor, $talk );
154155
155 - return $user->leaveUserMessage( $subject, $text, $signature, $editSummary,
156 - $editor, $flags );
 156+ return self::leaveUserMessage( $user, $article, $subject, $text,
 157+ $signature, $editSummary, $editor, $flags );
157158 }
158159 }
159160
@@ -179,4 +180,62 @@
180181 $names[] = 'msg:newusermessage-editor';
181182 return true;
182183 }
 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+ }
183242 }
Index: trunk/phase3/includes/User.php
@@ -3767,91 +3767,7 @@
37683768 return $ret;
37693769 }
37703770
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 ) ) ) {
37803771
3781 - $signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~";
37823772
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 - }
37933773
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 - }
38583774 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r81615Follow-up r81612, disable $wgAllowAsyncCopyUploadsbtongminh22:53, 6 February 2011
r816981.17wmf1: MFT r80837, r81612, r81615, r81657, r81674, r81689catrope08:21, 8 February 2011
r817361.17wmf1: Properly merge NewUserMessage part of r81612catrope13:30, 8 February 2011
r96329Cleanup to r81612: this functionality was removed from core, so LQT doesn't n...demon13:19, 6 September 2011
r96330Cleanup to r81612: first sig should be ~~~~demon13:30, 6 September 2011
r96673FU r81612: use getRawText() in leaveUserMessage()aaron17:34, 9 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r66438Start adding support for leaving user's messages. Begin using it in UploadFr...mah20:36, 14 May 2010

Comments

#Comment by 😂 (talk | contribs)   15:01, 7 February 2011

Hook removals need removing in docs/hooks.txt

#Comment by Brion VIBBER (talk | contribs)   02:12, 8 February 2011

Per comments on the orig, we might want to leave the hook in for the moment so LQT can still hook into it. (Can ignore that if we know for sure that NewUserMessage and LiquidThreads aren't enabled on the same wikis and won't be until things are sorted better.)

#Comment by MarkAHershberger (talk | contribs)   16:30, 5 March 2011

This revert should be merged back in or corresponding changes made in UploadFromUrlJob.

#Comment by Bryan (talk | contribs)   17:30, 5 March 2011

UploadFromUrlJob is disabled in 1.17, so it's good enough for 1.17.

I'm hoping that hashar will fix bug 27829 before 1.18 release.

#Comment by Krinkle (talk | contribs)   01:24, 3 June 2011

+		$signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~";

Shouldn't the first "~~~~~" be 4 tildes instead of 5 ?

#Comment by Bryan (talk | contribs)   21:36, 7 September 2011

Chad fixed the mentioned issues in r96330 and r96330, thanks for that.

#Comment by Aaron Schulz (talk | contribs)   17:31, 9 September 2011
$text = $article->getContent() . $text;

Shouldn't that use getRawText()?

Status & tagging log