r81736 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81735‎ | r81736 | r81737 >
Date:13:30, 8 February 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: Properly merge NewUserMessage part of r81612
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/NewUserMessage/NewUserMessage.class.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/NewUserMessage/NewUserMessage.class.php
@@ -140,6 +140,7 @@
141141 $talk = $user->getTalkPage();
142142
143143 if ( !$talk->exists() ) {
 144+ $article = new Article( $talk );
144145 $subject = self::fetchSubject();
145146 $text = self::fetchText();
146147 $signature = self::fetchSignature();
@@ -150,8 +151,8 @@
151152 $subject = self::substString( $subject, $user, $editor, $talk, "preparse" );
152153 $text = self::substString( $text, $user, $editor, $talk );
153154
154 - return $user->leaveUserMessage( $subject, $text, $signature, $editSummary,
155 - $editor, $flags );
 155+ return self::leaveUserMessage( $user, $article, $subject, $text,
 156+ $signature, $editSummary, $editor, $flags );
156157 }
157158 }
158159
@@ -178,4 +179,62 @@
179180 $names[] = 'msg:newusermessage-editor';
180181 return true;
181182 }
 183+
 184+ /**
 185+ * Leave a user a message
 186+ * @param $subject String the subject of the message
 187+ * @param $text String the message to leave
 188+ * @param $signature String Text to leave in the signature
 189+ * @param $summary String the summary for this change, defaults to
 190+ * "Leave system message."
 191+ * @param $editor User The user leaving the message, defaults to
 192+ * "{{MediaWiki:usermessage-editor}}"
 193+ * @param $flags Int default edit flags
 194+ *
 195+ * @return boolean true if it was successful
 196+ */
 197+ public static function leaveUserMessage( $user, $article, $subject, $text, $signature,
 198+ $summary, $editor, $flags ) {
 199+
 200+ $text = self::formatUserMessage( $subject, $text, $signature );
 201+ $flags = $article->checkFlags( $flags );
 202+
 203+ if ( $flags & EDIT_UPDATE ) {
 204+ $text = $article->getContent() . $text;
 205+ }
 206+
 207+ $dbw = wfGetDB( DB_MASTER );
 208+ $dbw->begin();
 209+
 210+ try {
 211+ $status = $article->doEdit( $text, $summary, $flags, false, $editor );
 212+ } catch ( DBQueryError $e ) {
 213+ $status = Status::newFatal( 'DB Error' );
 214+ }
 215+
 216+ if ( $status->isGood() ) {
 217+ // Set newtalk with the right user ID
 218+ $user->setNewtalk( true );
 219+ $dbw->commit();
 220+ } else {
 221+ // The article was concurrently created
 222+ wfDebug( __METHOD__ . ": Error ".$status->getWikiText() );
 223+ $dbw->rollback();
 224+ }
 225+
 226+ return $status->isGood();
 227+ }
 228+
 229+ /**
 230+ * Format the user message using a hook, a template, or, failing these, a static format.
 231+ * @param $subject String the subject of the message
 232+ * @param $text String the content of the message
 233+ * @param $signature String the signature, if provided.
 234+ */
 235+ static protected function formatUserMessage( $subject, $text, $signature ) {
 236+ $signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~";
 237+ $text = "\n== $subject ==\n\n$text\n\n-- $signature";
 238+
 239+ return $text;
 240+ }
182241 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r81612Per CR r66438 and IRC, revert User::leaveNewMessage for now. Copied the funct...btongminh22:44, 6 February 2011

Status & tagging log