Index: branches/lqt-updates/extensions/LiquidThreads/new-schema.sql |
— | — | @@ -49,6 +49,9 @@ |
50 | 50 | -- Edit comment for this change, if applicable |
51 | 51 | ltv_comment TINYBLOB, |
52 | 52 | |
| 53 | + -- Bitfield for single-version deletion |
| 54 | + ltv_deleted tinyint unsigned NOT NULL default 0, |
| 55 | + |
53 | 56 | ltv_subject TINYBLOB NOT NULL, |
54 | 57 | ltv_channel bigint(10) unsigned not null |
55 | 58 | ) /*$wgDBTableOptions*/; |
— | — | @@ -97,6 +100,9 @@ |
98 | 101 | -- Edit comment for this change, if applicable |
99 | 102 | lpv_comment TINYBLOB, |
100 | 103 | |
| 104 | + -- Bitfield for single-version deletion |
| 105 | + lpv_deleted tinyint unsigned NOT NULL default 0, |
| 106 | + |
101 | 107 | -- ACTUAL DATA |
102 | 108 | |
103 | 109 | -- User IP/ID for the ORIGINAL POSTER |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php |
— | — | @@ -178,7 +178,6 @@ |
179 | 179 | */ |
180 | 180 | public function save( $comment = null ) { |
181 | 181 | if ( $this->pendingVersion ) { |
182 | | - $this->pendingVersion->setComment( $comment ); |
183 | 182 | $this->pendingVersion->commit( $comment ); |
184 | 183 | $this->pendingVersion = null; |
185 | 184 | |
— | — | @@ -245,7 +244,7 @@ |
246 | 245 | * It is saved to the database when you call LiquidThreadsPost::commit() |
247 | 246 | * If it doesn't exist, it will be created. |
248 | 247 | */ |
249 | | - protected function getPendingVersion() { |
| 248 | + public function getPendingVersion() { |
250 | 249 | if ( !$this->pendingVersion ) { |
251 | 250 | $this->pendingVersion = LiquidThreadsPostVersion::create( $this ); |
252 | 251 | } |
— | — | @@ -253,6 +252,14 @@ |
254 | 253 | return $this->pendingVersion; |
255 | 254 | } |
256 | 255 | |
| 256 | + /** |
| 257 | + * Discard unsaved changes. |
| 258 | + */ |
| 259 | + public function reset() { |
| 260 | + $this->pendingVersion->destroy(); |
| 261 | + $this->pendingVersion = null; |
| 262 | + } |
| 263 | + |
257 | 264 | /* Accessors for various properties. Mostly stored in the current version */ |
258 | 265 | |
259 | 266 | /** |
— | — | @@ -292,6 +299,85 @@ |
293 | 300 | |
294 | 301 | /* PROPERTY SETTERS */ |
295 | 302 | |
| 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 | + } |
296 | 310 | |
| 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 | + } |
297 | 383 | } |
298 | 384 | |