r84011 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84010‎ | r84011 | r84012 >
Date:12:15, 15 March 2011
Author:werdna
Status:deferred
Tags:
Comment:
Add pass-through LiquidThreadsPostVersion property setters to the LiquidThreadsPost class. Works by maintaining an internal "to save" version, which can be committed using the LiquidThreadsPost::save() method.
Modified paths:
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/new-schema.sql (modified) (history)

Diff [purge]

Index: branches/lqt-updates/extensions/LiquidThreads/new-schema.sql
@@ -49,6 +49,9 @@
5050 -- Edit comment for this change, if applicable
5151 ltv_comment TINYBLOB,
5252
 53+ -- Bitfield for single-version deletion
 54+ ltv_deleted tinyint unsigned NOT NULL default 0,
 55+
5356 ltv_subject TINYBLOB NOT NULL,
5457 ltv_channel bigint(10) unsigned not null
5558 ) /*$wgDBTableOptions*/;
@@ -97,6 +100,9 @@
98101 -- Edit comment for this change, if applicable
99102 lpv_comment TINYBLOB,
100103
 104+ -- Bitfield for single-version deletion
 105+ lpv_deleted tinyint unsigned NOT NULL default 0,
 106+
101107 -- ACTUAL DATA
102108
103109 -- User IP/ID for the ORIGINAL POSTER
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php
@@ -178,7 +178,6 @@
179179 */
180180 public function save( $comment = null ) {
181181 if ( $this->pendingVersion ) {
182 - $this->pendingVersion->setComment( $comment );
183182 $this->pendingVersion->commit( $comment );
184183 $this->pendingVersion = null;
185184
@@ -245,7 +244,7 @@
246245 * It is saved to the database when you call LiquidThreadsPost::commit()
247246 * If it doesn't exist, it will be created.
248247 */
249 - protected function getPendingVersion() {
 248+ public function getPendingVersion() {
250249 if ( !$this->pendingVersion ) {
251250 $this->pendingVersion = LiquidThreadsPostVersion::create( $this );
252251 }
@@ -253,6 +252,14 @@
254253 return $this->pendingVersion;
255254 }
256255
 256+ /**
 257+ * Discard unsaved changes.
 258+ */
 259+ public function reset() {
 260+ $this->pendingVersion->destroy();
 261+ $this->pendingVersion = null;
 262+ }
 263+
257264 /* Accessors for various properties. Mostly stored in the current version */
258265
259266 /**
@@ -292,6 +299,85 @@
293300
294301 /* PROPERTY SETTERS */
295302
 303+ /**
 304+ * Sets the text content of this post.
 305+ * @param $text String: new text content.
 306+ */
 307+ public function setText( $text ) {
 308+ $this->getPendingVersion()->setText( $text );
 309+ }
296310
 311+ /**
 312+ * Sets the topic ID for this post (i.e. moves the post to a new topic)
 313+ * Also handles removing the parent, if one exists and we're changing topic.
 314+ * @param $id Integer: The ID of the topic to move the post to.
 315+ */
 316+ public function setTopicID( $id ) {
 317+ $this->getPendingVersion()->setTopicID( $id );
 318+
 319+ if ( $id != $this->getTopicID() ) {
 320+ $this->setParent(null);
 321+ }
 322+ }
 323+
 324+ /**
 325+ * Sets the parent ID for this post (i.e. moves the post underneath another post).
 326+ * It is assumed that the other post is contained in the same topic.
 327+ * If you're not sure, instantiate the new parent Post and use
 328+ * LiquidThreadsPost::setParent()
 329+ * @param $id Integer: The ID of the post to move this post underneath.
 330+ */
 331+ public function setParentID( $id ) {
 332+ $this->getPendingVersion()->setParentID( $id );
 333+ }
 334+
 335+ /**
 336+ * Sets the parent post to $post (moves this post underneath $post.
 337+ * An exception will be thrown if the new parent post is in a different topic.
 338+ * @param $post LiquidThreadsPost: The post to move underneath, or NULL for none.
 339+ * @param $check Boolean: Whether or not to check if the new parent post is in the same topic.
 340+ */
 341+ public function setParent( LiquidThreadsPost $post, $check = true ) {
 342+ if ( $post == null ) {
 343+ $this->setParentID(0);
 344+ return;
 345+ }
 346+
 347+ $parent_topics = array( $post->getTopicID() );
 348+ $parent_topics[] = $post->getPendingVersion()->getTopicID();
 349+ $parent_topics = array_unique( $parent_topics );
 350+
 351+ $my_topics = array( $this->getTopicID() );
 352+ $my_topics[] = $this->getPendingVersion()->getTopicID();
 353+
 354+ // If the new parent is neither currently nor going to be in the same topic
 355+ if ( $check &&
 356+ count(array_intersect( $my_topics, $parent_topics )) == 0 )
 357+ {
 358+ throw new MWException( "Attempt to assign parent post to a post outside this topic." );
 359+ }
 360+
 361+ $this->setParentID( $post->getID() );
 362+ }
 363+
 364+ /**
 365+ * Moves this post to another topic.
 366+ * @param $topic LiquidThreadsTopic: Where to move this post.
 367+ */
 368+ public function setTopic( LiquidThreadsTopic $topic ) {
 369+ if ( !$topic || ! $topic instanceof LiquidThreadsTopic ) {
 370+ throw new MWException( "Invalid argument to ".__METHOD__ );
 371+ }
 372+
 373+ $this->setTopicID( $topic->getID() );
 374+ }
 375+
 376+ /**
 377+ * Sets the signature for this post.
 378+ * @param $sig String: The new signature
 379+ */
 380+ public function setSignature( $sig ) {
 381+ $this->getPendingVersion()->setSignature( $sig );
 382+ }
297383 }
298384

Status & tagging log