r85329 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85328‎ | r85329 | r85330 >
Date:13:58, 4 April 2011
Author:werdna
Status:deferred
Tags:
Comment:
Commit new Topic and TopicVersion files. Code needs to be refactored into VersionedObject and ObjectVersion, but will be duplicated for now.
Modified paths:
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php (added) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php (added) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php (added) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/VersionedObject.php (added) (history)

Diff [purge]

Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php
@@ -175,7 +175,7 @@
176176 */
177177 public static function newFromRow( $row ) {
178178 $version = new LiquidThreadsPostVersion;
179 - $post->initialiseFromRow( $row );
 179+ $version->initialiseFromRow( $row );
180180
181181 return $version;
182182 }
@@ -294,7 +294,7 @@
295295 // Copy all data members across.
296296 $this->text = $baseVersion->getText();
297297 $this->textDirty = false;
298 - $this->textID = $baseVersion->textiD;
 298+ $this->textID = $baseVersion->textID;
299299 $this->poster = $baseVersion->getPoster();
300300 $this->topicID = $baseVersion->getTopicID();
301301 $this->parentID = $baseVersion->getParentID();
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php
@@ -0,0 +1,365 @@
 2+<?php
 3+
 4+/**
 5+ * LiquidThreads Topic class.
 6+ * This class represents a single threaded discussion.
 7+ * @addtogroup LiquidThreads model
 8+ */
 9+class LiquidThreadsTopic {
 10+
 11+ /* MEMBER VARIABLES */
 12+ /** The current LiquidThreadsTopicVersion object. **/
 13+ protected $currentVersion;
 14+ /** The ID of the current version **/
 15+ protected $currentVersionID;
 16+
 17+ /** The version that is being worked on by set methods **/
 18+ protected $pendingVersion;
 19+
 20+ /** The unique ID for this Topic **/
 21+ protected $id;
 22+
 23+ /** The ID of the channel that this topic is in. **/
 24+ protected $channelID;
 25+ /** The LiquidThreadsChannel object that this topic is in. **/
 26+ protected $channel;
 27+
 28+ /** Array of LiquidThreadsPost objects, the posts in this topic **/
 29+ protected $posts;
 30+
 31+ /** The number of replies that this topic has **/
 32+ protected $replyCount;
 33+
 34+ /* FACTORY METHODS */
 35+
 36+ /**
 37+ * Default constructor.
 38+ * Not to be called directly.
 39+ */
 40+ protected function __construct() {
 41+
 42+ }
 43+
 44+ /**
 45+ * Factory method to retrieve Topics from Database conditions.
 46+ * Don't use this method externally, use one of the other factory methods.
 47+ * @param $conditions Array: Conditions to pass to Database::select
 48+ * @return Array of LiquidThreadsTopic objects with those conditions.
 49+ */
 50+ public static function loadFromConditions( $conditions, $fetchText = false ) {
 51+ $dbr = wfGetDB( DB_SLAVE );
 52+
 53+ $tables = array( 'lqt_topic', 'lqt_topic_version' );
 54+ $fields = '*';
 55+ $joins = array(
 56+ 'lqt_topic_version' => array(
 57+ 'left join' => array(
 58+ 'lqt_current_version=ltv_id',
 59+ ),
 60+ ),
 61+ );
 62+
 63+ $res = $dbr->select( $tables, $fields, $conditions, __METHOD__, array(), $joins );
 64+
 65+ $output = array();
 66+
 67+ foreach( $res as $row ) {
 68+ $topic = new LiquidThreadsTopic;
 69+ $topic->initialiseFromRow( $row );
 70+
 71+ $output[$topic->getID()] = $topic;
 72+ }
 73+
 74+ return $output;
 75+ }
 76+
 77+ /**
 78+ * Factory method to retrieve a Topic by ID.
 79+ * Throws an exception if the topic does not exist.
 80+ * @param $id Integer The ID of the topic to retrieve.
 81+ * @return LiquidThreadsTopic: The topic with that ID.
 82+ */
 83+ public static function newFromID( $id ) {
 84+ $condition = array( 'lqt_id' => $id );
 85+
 86+ $topics = self::loadFromConditions( $condition );
 87+
 88+ // Check that the post actually exists.
 89+ if ( count($topics) < 1 ) {
 90+ throw new MWException( "Attempt to load topic #$id, which does not exist" );
 91+ }
 92+
 93+ $topic = array_shift( $topics );
 94+ return $topic;
 95+ }
 96+
 97+ /**
 98+ * Factory method to load a topic from a row object.
 99+ * The row object may optionally contain the appropriate Version data, too.
 100+ * @param $row Object: Row object returned from DatabaseResult::fetchObject()
 101+ * @return LiquidThreadsTopic The new Topic object.
 102+ */
 103+ public static function newFromRow( $row ) {
 104+ $topic = new LiquidThreadsTopic;
 105+ $topic->initialiseFromRow( $row );
 106+
 107+ return $topic;
 108+ }
 109+
 110+ /**
 111+ * Factory method to create a new topic.
 112+ * Must be saved with LiquidThreadsTopic::save()
 113+ * @param $channel LiquidThreadsChannel: The channel this topic is in.
 114+ * @return LiquidThreadsTopic: The new post.
 115+ */
 116+ public static function create( $channel ) {
 117+ $topic = new LiquidThreadsTopic;
 118+
 119+ $topic->initialiseNew( $channel );
 120+
 121+ return $topic;
 122+ }
 123+
 124+ /* Initialisation functions. One of these has to be called on a new object */
 125+
 126+ /**
 127+ * Initialise this object from a database row.
 128+ * This "row" may be joined to the current version row.
 129+ * @param $row Object: A row object containing the
 130+ * appropriate lqt_topic and (optionally) lqt_topic_version rows.
 131+ */
 132+ protected function initialiseFromRow( $row ) {
 133+ if ( empty($row->lqt_id) ) {
 134+ throw new MWException( "Invalid input to ".__METHOD__ );
 135+ }
 136+
 137+ // Load members
 138+ $this->id = $row->lqt_id;
 139+ $this->channelID = $row->lqt_channel;
 140+ $this->currentVersionID = $row->lqt_current_version;
 141+
 142+ if ( isset($row->ltv_id) ) {
 143+ $version = LiquidThreadsTopicVersion::newFromRow( $row );
 144+ $this->currentVersion = $version;
 145+ }
 146+ }
 147+
 148+ /**
 149+ * Initialise this object as a new Topic.
 150+ * @param $channel LiquidThreadsChannel: The channel this topic is in.
 151+ */
 152+ protected function initialiseNew( $channel ) {
 153+ $this->id = 0;
 154+
 155+ $this->currentVersionID = 0;
 156+ $this->currentVersion = LiquidThreadsTopicVersion::createNewTopic();
 157+ $this->pendingVersion = $this->currentVersion;
 158+
 159+ $this->channel = $channel;
 160+ }
 161+
 162+ /* SAVE CODE */
 163+
 164+ /**
 165+ * Commits pending changes to the database.
 166+ * Internally, triggers a commit() operation on the current pending version.
 167+ * @param $comment String: Optional edit comment for this operation.
 168+ */
 169+ public function save( $comment = null ) {
 170+ if ( $this->pendingVersion ) {
 171+ $this->pendingVersion->commit( $comment );
 172+ $this->currentVersion = $this->pendingVersion;
 173+ $this->pendingVersion = null;
 174+
 175+ if ( $this->id ) {
 176+ $this->update( );
 177+ } else {
 178+ $this->insert( );
 179+ }
 180+ } else {
 181+ throw new MWException( "There are no pending changes." );
 182+ }
 183+ }
 184+
 185+ /**
 186+ * Updates the Topic row in the database.
 187+ * To be called after a new LiquidThreadsTopicVersion is inserted and
 188+ * $this->currentVersion has been updated.
 189+ * Should only really be called from LiquidThreadsPost::save
 190+ * @param $version The LiquidThreadsTopicVersion object that was just saved.
 191+ */
 192+ protected function update( $version ) {
 193+ if ( ! $this->getID() ) {
 194+ throw new MWException( "Attempt to call update() on a topic not yet in the database." );
 195+ }
 196+
 197+ $dbw = wfGetDB( DB_MASTER );
 198+
 199+ $row = $this->getRow();
 200+ $dbw->update( 'lqt_topic', $row, array( 'lqt_id' => $this->getID() ),
 201+ __METHOD__ );
 202+ }
 203+
 204+ /**
 205+ * Inserts this Post into the database.
 206+ * ONLY to be called *after* the first PostVersion is saved to the database.
 207+ * This should only really be called from LiquidThreadsPost::save
 208+ */
 209+ protected function insert() {
 210+ if ( $this->getID() ) {
 211+ throw new MWException( "Attempt to call insert() on a topic already inserted" );
 212+ }
 213+
 214+ $dbw = wfGetDB( DB_MASTER );
 215+
 216+ $row = $this->getRow();
 217+ $dbw->insert( 'lqt_post', $row, __METHOD__ );
 218+
 219+ $postId = $dbw->insertId();
 220+ $this->id = $postId;
 221+
 222+ $dbw->update( 'lqt_topic_version', array( 'ltv_topic' => $postId ),
 223+ array( 'ltv_id' => $this->currentVersion->getID() ),
 224+ __METHOD__ );
 225+ }
 226+
 227+ /**
 228+ * Generates a row object to be inserted or updated in the database.
 229+ * Used internally by update() and insert()
 230+ */
 231+ protected function getRow() {
 232+ $row = array(
 233+ 'lqt_current_version' => $this->currentVersion->getID(),
 234+ 'lqt_channel' => $this->getChannelID(),
 235+ 'lqt_replies' => $this->replyCount,
 236+ );
 237+
 238+ if ( $this->id ) {
 239+ $row['lqt_id'] = $dbw->nextSequenceValue( 'lqt_topic_lqt_id' );
 240+ }
 241+
 242+ return $row;
 243+ }
 244+
 245+ /* PROPERTY ACCESSORS */
 246+
 247+ /**
 248+ * Returns the unique ID assigned to this Post. This ID is unique among Posts.
 249+ */
 250+ public function getID() {
 251+ return $this->id;
 252+ }
 253+
 254+ /**
 255+ * Returns the current version object.
 256+ */
 257+ public function getCurrentVersion() {
 258+ if ( $this->currentVersion ) {
 259+ return $this->currentVersion;
 260+ } elseif ( $this->currentVersionID ) {
 261+ $this->currentVersion =
 262+ LiquidThreadsTopicVersion::newFromID( $this->currentVersionID );
 263+ return $this->currentVersion;
 264+ } else {
 265+ throw new MWException( "No current version to retrieve" );
 266+ }
 267+ }
 268+
 269+ /**
 270+ * Returns the pending version object.
 271+ * The pending version is the version being affected by set*() functions.
 272+ * It is saved to the database when you call LiquidThreadsTopic::save()
 273+ * If it doesn't exist, it will be created.
 274+ */
 275+ public function getPendingVersion() {
 276+ if ( !$this->pendingVersion ) {
 277+ $this->pendingVersion = LiquidThreadsTopicVersion::create( $this );
 278+ }
 279+
 280+ return $this->pendingVersion;
 281+ }
 282+
 283+ /**
 284+ * Discard unsaved changes.
 285+ */
 286+ public function reset() {
 287+ $this->pendingVersion->destroy();
 288+ $this->pendingVersion = null;
 289+ }
 290+
 291+ /* Accessors for various properties. Mostly stored in the current version */
 292+
 293+ /**
 294+ * @return String: The current subject text for this Topic.
 295+ */
 296+ public function getSubject() {
 297+ return $this->getCurrentVersion()->getSubject();
 298+ }
 299+
 300+ /**
 301+ * Returns the ID of the channel that this topic belongs to.
 302+ */
 303+ public function getChannelID() {
 304+ return $this->getCurrentVersion()->getChannelID();
 305+ }
 306+
 307+ /**
 308+ * Returns the channel object that this topic belongs to.
 309+ */
 310+ public function getChannel() {
 311+ if ( $this->channel instanceof LiquidThreadsChannel ) {
 312+ return $this->channel;
 313+ } // else
 314+
 315+ $this->channel = LiquidThreadsChannel::newFromId( $this->channelID );
 316+
 317+ return $this->channel;
 318+ }
 319+
 320+ /**
 321+ * Retrieves this topic's posts
 322+ * @return Array of LiquidThreadsPost objects.
 323+ */
 324+ public function getPosts() {
 325+ if ( is_array( $this->posts ) ) {
 326+ return $this->posts;
 327+ } // else
 328+
 329+ $conds = array( 'lqp_topic' => $this->getId() );
 330+
 331+ $this->posts = LiquidThreadsPost::loadFromConditions( $conds );
 332+
 333+ return $this->posts;
 334+ }
 335+
 336+ /* PROPERTY SETTERS */
 337+
 338+ /**
 339+ * Sets the subject of this topic.
 340+ * @param $text String: new subject.
 341+ */
 342+ public function setSubject( $text ) {
 343+ $this->getPendingVersion()->setSubject( $text );
 344+ }
 345+
 346+ /**
 347+ * Sets the channel ID for this topic (i.e. moves the topic to a new channel)
 348+ * @param $id Integer: The ID of the channel to move the topic to.
 349+ */
 350+ public function setChannelID( $id ) {
 351+ $this->getPendingVersion()->setChannelID( $id );
 352+ }
 353+
 354+ /**
 355+ * Moves this post to another topic.
 356+ * @param $topic LiquidThreadsTopic: Where to move this post.
 357+ */
 358+ public function setChannel( LiquidThreadsChannel $channel ) {
 359+ if ( !$channel || ! $channel instanceof LiquidThreadsChannel ) {
 360+ throw new MWException( "Invalid argument to ".__METHOD__ );
 361+ }
 362+
 363+ $this->setChannelID( $channel->getID() );
 364+ }
 365+}
 366+
Property changes on: branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php
___________________________________________________________________
Added: svn:eol-style
1367 + native
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php
@@ -0,0 +1,422 @@
 2+<?php
 3+
 4+/**
 5+ * This class represents a single version of a specific Topic.
 6+ */
 7+class LiquidThreadsTopicVersion {
 8+ /*** MEMBERS ***/
 9+
 10+ /*** Metadata ***/
 11+
 12+ /** ID of this version **/
 13+ protected $id;
 14+
 15+ /** ID of the post that this version applies to **/
 16+ protected $postID;
 17+
 18+ /** User object for the person who created this *VERSION* **/
 19+ protected $versionUser;
 20+
 21+ /** Timestamp that this version was created **/
 22+ protected $timestamp;
 23+
 24+ /** Edit comment associated with this version **/
 25+ protected $comment;
 26+
 27+ /*** Version data ***/
 28+
 29+ /** The ID of the channel that this topic is in **/
 30+ protected $channelID = null;
 31+
 32+ /** This topic's subject **/
 33+ protected $subject = null;
 34+
 35+ /* Ancestry information, for not-saved errors */
 36+
 37+ /** Where this object was instantiated. Used for not-saved errors **/
 38+ protected $source;
 39+
 40+ /** Whether or not this object has been destroyed **/
 41+ protected $destroyed = false;
 42+
 43+ /*** FACTORY FUNCTIONS ***/
 44+
 45+ /**
 46+ * Default constructor.
 47+ * Don't use this externally! Use one of the other factory methods.
 48+ */
 49+ protected function __construct() {
 50+ $this->source = wfGetAllCallers();
 51+ }
 52+
 53+ /**
 54+ * Default destructor
 55+ * If this Version has yet to be saved, throws an exception.
 56+ * To prevent this behaviour, call destroy()
 57+ */
 58+ public function __destruct() {
 59+ if ( $this->id == 0 && !$this->destroyed ) {
 60+ throw new MWException( "Version object has not been saved nor destroyed. From: " . $this->source );
 61+ }
 62+ }
 63+
 64+ /**
 65+ * Disables the "not saved" error message.
 66+ * This MUST be called if you do not plan to save this version.
 67+ */
 68+ public function destroy() {
 69+ $this->destroyed = true;
 70+ }
 71+
 72+ /**
 73+ * Factory method to retrieve TopicVersions from Database conditions.
 74+ * Don't use this method externally, use one of the other factory methods.
 75+ * @param $conditions Array: Conditions to pass to Database::select
 76+ * @return Array: LiquidThreadsTopicVersion objects with those conditions.
 77+ */
 78+ public static function loadFromConditions( $conditions, $fetchText = false, $options = array() ) {
 79+ $dbr = wfGetDB( DB_SLAVE );
 80+
 81+ $tables = array( 'lqt_topic_version' );
 82+ $fields = '*';
 83+
 84+ $res = $dbr->select( $tables, $fields, $conditions, __METHOD__, array(), $joins );
 85+
 86+ $output = array();
 87+
 88+ foreach( $res as $row ) {
 89+ $version = new LiquidThreadsTopicVersion;
 90+ $version->initialiseFromRow( $row );
 91+
 92+ $output[$version->getID()] = $version;
 93+ }
 94+
 95+ return $output;
 96+ }
 97+
 98+ /**
 99+ * Factory method to retrieve a TopicVersion from a Topic and point in time.
 100+ * If the point in time is blank, it retrieves the most recent one.
 101+ * @param $post The LiquidThreadsTopic to retrieve a version for.
 102+ * @param $timestamp String: A timestamp for the point in time (optional)
 103+ * @return The LiquidThreadsTopicVersion object for that topic at that point in time, or null.
 104+ */
 105+ public static function newPointInTime( $topic, $timestamp = null ) {
 106+ if ( ! $topic instanceof LiquidThreadsTopic ) {
 107+ throw new MWException( "Invalid argument to ".__METHOD__ );
 108+ }
 109+
 110+ $dbr = wfGetDB( DB_SLAVE );
 111+
 112+ $conds = array( 'ltv_topic' => $topic->getID() );
 113+
 114+ if ( $timestamp ) {
 115+ $conds[] = 'ltv_timestamp < ' .
 116+ $dbr->addQuotes( $dbr->timestamp( $timestamp ) );
 117+ }
 118+
 119+ $row = $dbr->selectRow( 'lqt_topic_version', '*', $conds, __METHOD__ );
 120+
 121+ if ( $row ) {
 122+ return self::newFromRow( $row );
 123+ } else {
 124+ return null;
 125+ }
 126+ }
 127+
 128+ /**
 129+ * Factory method to retrieve a TopicVersion by ID.
 130+ * Throws an exception if the version does not exist.
 131+ * @param $id Integer: The ID of the version to retrieve.
 132+ * @return LiquidThreadsTopicVersion: The Version with that ID.
 133+ */
 134+ public static function newFromID( $id ) {
 135+ $condition = array( 'ltv_id' => $id );
 136+
 137+ $versions = self::loadFromConditions( $condition );
 138+
 139+ // Check that the version actually exists.
 140+ if ( count($versions) < 1 ) {
 141+ throw new MWException( "Attempt to load topic version #$id, which does not exist" );
 142+ }
 143+
 144+ $version = array_shift( $versions );
 145+ return $version;
 146+ }
 147+
 148+ /**
 149+ * Factory method to load a version from a row object.
 150+ * @param $row Object: Row object returned from DatabaseResult::fetchObject()
 151+ * @return LiquidThreadsTopicVersion: The new TopicVersion object.
 152+ */
 153+ public static function newFromRow( $row ) {
 154+ $version = new LiquidThreadsTopicVersion;
 155+ $version->initialiseFromRow( $row );
 156+
 157+ return $version;
 158+ }
 159+
 160+ /**
 161+ * Factory method to create a new version of a topic.
 162+ * @param $post The LiquidThreadsTopic to create a version of.
 163+ * @param $baseVersion LiquidThreadsTopicVersion: The revision to base on. \em{(optional)}
 164+ * @return LiquidThreadsTopicVersion: The new version object.
 165+ */
 166+ public static function create( LiquidThreadsTopic $topic,
 167+ LiquidThreadsTopicVersion $baseVersion = null )
 168+ {
 169+ $version = new LiquidThreadsTopicVersion;
 170+
 171+ $version->initialiseNew( $topic, $baseVersion );
 172+
 173+ return $version;
 174+ }
 175+
 176+ /**
 177+ * Factory method to create a Version for a new LiquidThreadsTopic.
 178+ * @param $channel The LiquidThreadsChannel to put this topic in.
 179+ * @return LiquidThreadsTopicVersion: A Version object for a new topic.
 180+ */
 181+ public static function createNewTopic( LiquidThreadsChannel $channel )
 182+ {
 183+ $version = new LiquidThreadsTopicVersion;
 184+
 185+ $version->initialiseNewTopic( $channel );
 186+
 187+ return $post;
 188+ }
 189+
 190+ /* Initialisation functions. One of these has to be called on a new object */
 191+
 192+ /**
 193+ * Initialise this object from a database row.
 194+ * This "row" may be joined to the text row.
 195+ * @param $row Object: A row object containing the
 196+ * appropriate lqt_topic_version row.
 197+ */
 198+ protected function initialiseFromRow( $row ) {
 199+ if ( empty($row->ltv_id) ) {
 200+ throw new MWException( "Invalid input to ".__METHOD__ );
 201+ }
 202+
 203+ // Load members
 204+ $this->id = $row->ltv_id;
 205+
 206+ // Metadata members
 207+ $user = null;
 208+ if ( $row->ltv_user_id > 0 ) {
 209+ if ( empty($row->user_name) ) {
 210+ $user = User::newFromId( $row->ltv_user_id );
 211+ } else {
 212+ $user = User::newFromRow( $row );
 213+ }
 214+ } elseif ( User::isIP( $row->ltv_user_ip ) ) {
 215+ $user = User::newFromName( $row->ltv_user_ip );
 216+ }
 217+
 218+ if ( is_null($user) ) {
 219+ throw new MWException( "Invalid user found in ltv_user: {$row->ltv_user_id}/{$row->ltv_user_ip}" );
 220+ }
 221+ $this->versionUser = $user;
 222+
 223+ // Other metadata
 224+ $this->comment = $row->ltv_comment
 225+ $this->timestamp = wfTimestamp( TS_MW, $row->ltv_timestamp );
 226+ $this->topicID = $row->ltv_topic;
 227+
 228+ // Real version data loading
 229+ $this->channelID = $row->ltv_channel;
 230+ $this->subject = $row->ltv_subject;
 231+ }
 232+
 233+ /**
 234+ * Initialise a new version object for a post.
 235+ * If the base revision is not specified, it is based on the current version of the Post.
 236+ * @param $post LiquidThreadsPost: The post that this version is for.
 237+ * @param $baseVersion LiquidThreadsPostVersion: The base version for this version. \em{(optional)}
 238+ */
 239+ protected function initialiseNew( LiquidThreadsPost $post,
 240+ LiquidThreadsPostVersion $baseVersion = null )
 241+ {
 242+ if ( ! $baseVersion ) {
 243+ $baseVersion = $post->getCurrentVersion();
 244+ }
 245+
 246+ // Copy all data members across.
 247+ $this->channelID = $baseVersion->getChannelID();
 248+ $this->subject = $baseVersion->getSubject();
 249+
 250+ global $wgUser;
 251+ $this->editor = $wgUser;
 252+
 253+ $this->id = 0;
 254+ $this->topicID = $topic->getID();
 255+ }
 256+
 257+ /**
 258+ * Initialise a new version object for a new topic.
 259+ * @param $channel LiquidThreadsChannel: The channel that this topic is in.
 260+ */
 261+ protected function initialiseNewTopic( LiquidThreadsChannel $channel )
 262+ {
 263+ global $wgUser;
 264+
 265+ $this->id = 0;
 266+ $this->versionUser = $wgUser;
 267+ $this->channelID = $channel->getID();
 268+ $this->subject = '';
 269+ }
 270+
 271+ /* SETTING AND SAVING */
 272+
 273+ /**
 274+ * Returns true if you're allowed to change properties.
 275+ * Currently, this is only if the version hasn't been saved to the DB.
 276+ */
 277+ protected function isMutable() {
 278+ return $this->id == 0;
 279+ }
 280+
 281+ /**
 282+ * Set the editor for this version.
 283+ * @param $editor User: The user who created this version.
 284+ */
 285+ public function setEditor( User $newEditor ) {
 286+ if ( !$this->isMutable() ) {
 287+ throw new MWException( "This Version object is not mutable." );
 288+ }
 289+
 290+ $this->editor = $newEditor;
 291+ }
 292+
 293+ /**
 294+ * Set the edit comment for this version.
 295+ * @param $comment String: The edit comment for this version
 296+ */
 297+ public function setComment( $comment ) {
 298+ if ( !$this->isMutable() ) {
 299+ throw new MWException( "This Version object is not mutable." );
 300+ }
 301+
 302+ $this->comment = $comment;
 303+ }
 304+
 305+ /**
 306+ * Set the parent channel for this version.
 307+ * @param $channel LiquidThreadsChannel: The new parent channel.
 308+ */
 309+ public function setChannel( LiquidThreadsChannel $channel ) {
 310+ $this->channelID = $channel->getID();
 311+ }
 312+
 313+ /**
 314+ * Sets the subject associated with this version.
 315+ * @param $subject String: The new subject
 316+ */
 317+ public function setSignature( $subject ) {
 318+ $this->subject = $subject;
 319+ }
 320+
 321+ /**
 322+ * Saves this Version to the database.
 323+ * @param $comment String: (optional) The edit comment for this version.
 324+ */
 325+ public function commit( $comment = null ) {
 326+ if ( $this->id != 0 ) {
 327+ throw new MWException( "Attempt to save a version already in the database." );
 328+ }
 329+
 330+ if ( $comment !== null ) {
 331+ $this->comment = $comment;
 332+ }
 333+
 334+ $dbw = wfGetDB( DB_MASTER );
 335+
 336+ $row = array(
 337+ 'ltv_id' => $dbw->nextSequenceValue( 'lqt_topic_version_ltv_id' ),
 338+ 'ltv_topic' => $this->topicID,
 339+ 'ltv_timestamp' => $dbw->timestamp( wfTimestampNow() ),
 340+ 'ltv_comment' => $this->comment,
 341+ 'ltv_channel' => $this->channelID,
 342+ 'ltv_subject' => $this->subject,
 343+ );
 344+
 345+ // Poster and user data
 346+ $editor = $this->getEditor();
 347+
 348+ if ( $editor->isAnon() ) {
 349+ $row['ltv_user_ip'] = $editor->getName();
 350+ } else {
 351+ $row['ltv_user_id'] = $editor->getID();
 352+ }
 353+
 354+ $dbw->insert( 'lqt_topic_version', $row, __METHOD__ );
 355+
 356+ $this->id = $dbw->insertId();
 357+
 358+ // Update pointer
 359+ if ( $this->topicID ) {
 360+ $dbw->update( 'lqt_topic', array( 'lqt_current_version', $this->id ),
 361+ array( 'lqt_id' => $this->topicID ), __METHOD__ );
 362+ }
 363+ }
 364+
 365+ /* PROPERTY ACCESSORS */
 366+
 367+ /**
 368+ * Returns the unique ID assigned to this Topic Version.
 369+ * This ID is unique among Topic Versions.
 370+ */
 371+ public function getID() {
 372+ if ( ! $this->id ) {
 373+ throw new MWException( "This Topic Version does not have an ID" );
 374+ }
 375+
 376+ return $this->id;
 377+ }
 378+
 379+ /**
 380+ * Returns the user who created this version.
 381+ */
 382+ public function getEditor() {
 383+ if ( ! $this->versionUser ) {
 384+ throw new MWException( "Invalid or missing editor" );
 385+ }
 386+
 387+ return $this->versionUser;
 388+ }
 389+
 390+ /**
 391+ * Returns the timestamp for this version.
 392+ */
 393+ public function getEditTime() {
 394+ if ( ! $this->timestamp ) {
 395+ throw new MWException( "Missing timestamp" );
 396+ }
 397+
 398+ return $this->timestamp;
 399+ }
 400+
 401+ /**
 402+ * Returns the edit comment for this version
 403+ */
 404+ public function getEditComment() {
 405+ return $this->comment;
 406+ }
 407+
 408+ /* Data */
 409+
 410+ /**
 411+ * Retrieves the ID of the channel associated with this Topic Version.
 412+ */
 413+ public function getChannelID() {
 414+ return $this->channelID;
 415+ }
 416+
 417+ /**
 418+ * Retrieves the subject shown for this post.
 419+ */
 420+ public function getSubject() {
 421+ return $this->subject;
 422+ }
 423+}
Property changes on: branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php
___________________________________________________________________
Added: svn:eol-style
1424 + native
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php
@@ -8,14 +8,7 @@
99 class LiquidThreadsPost {
1010
1111 /* MEMBER VARIABLES */
12 - /** The current LiquidThreadsPostVersion object. **/
13 - protected $currentVersion;
14 - /** The ID of the current version **/
15 - protected $currentVersionID;
1612
17 - /** The version that is being worked on by set methods **/
18 - protected $pendingVersion;
19 -
2013 /** The unique ID for this Post **/
2114 protected $id;
2215
@@ -172,6 +165,43 @@
173166 /* SAVE CODE */
174167
175168 /**
 169+ * Returns the current version object.
 170+ */
 171+ public function getCurrentVersion() {
 172+ if ( $this->currentVersion ) {
 173+ return $this->currentVersion;
 174+ } elseif ( $this->currentVersionID ) {
 175+ $this->currentVersion =
 176+ LiquidThreadsPostVersion::newFromID( $this->currentVersionID );
 177+ return $this->currentVersion;
 178+ } else {
 179+ throw new MWException( "No current version to retrieve" );
 180+ }
 181+ }
 182+
 183+ /**
 184+ * Returns the pending version object.
 185+ * The pending version is the version being affected by set*() functions.
 186+ * It is saved to the database when you call LiquidThreadsPost::commit()
 187+ * If it doesn't exist, it will be created.
 188+ */
 189+ public function getPendingVersion() {
 190+ if ( !$this->pendingVersion ) {
 191+ $this->pendingVersion = LiquidThreadsPostVersion::create( $this );
 192+ }
 193+
 194+ return $this->pendingVersion;
 195+ }
 196+
 197+ /**
 198+ * Discard unsaved changes.
 199+ */
 200+ public function reset() {
 201+ $this->pendingVersion->destroy();
 202+ $this->pendingVersion = null;
 203+ }
 204+
 205+ /**
176206 * Commits pending changes to the database.
177207 * Internally, triggers a commit() operation on the current pending version.
178208 * @param $comment String: Optional edit comment for this operation.
@@ -223,43 +253,6 @@
224254 return $this->id;
225255 }
226256
227 - /**
228 - * Returns the current version object.
229 - */
230 - public function getCurrentVersion() {
231 - if ( $this->currentVersion ) {
232 - return $this->currentVersion;
233 - } elseif ( $this->currentVersionID ) {
234 - $this->currentVersion =
235 - LiquidThreadsPostVersion::newFromID( $this->currentVersionID );
236 - return $this->currentVersion;
237 - } else {
238 - throw new MWException( "No current version to retrieve" );
239 - }
240 - }
241 -
242 - /**
243 - * Returns the pending version object.
244 - * The pending version is the version being affected by set*() functions.
245 - * It is saved to the database when you call LiquidThreadsPost::commit()
246 - * If it doesn't exist, it will be created.
247 - */
248 - public function getPendingVersion() {
249 - if ( !$this->pendingVersion ) {
250 - $this->pendingVersion = LiquidThreadsPostVersion::create( $this );
251 - }
252 -
253 - return $this->pendingVersion;
254 - }
255 -
256 - /**
257 - * Discard unsaved changes.
258 - */
259 - public function reset() {
260 - $this->pendingVersion->destroy();
261 - $this->pendingVersion = null;
262 - }
263 -
264257 /* Accessors for various properties. Mostly stored in the current version */
265258
266259 /**
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/VersionedObject.php
@@ -0,0 +1,33 @@
 2+<?php
 3+
 4+/**
 5+ * Top level class for objects which have versions.
 6+ */
 7+abstract class LiquidThreadsVersionedObject extends LiquidThreadsObject {
 8+//
 9+// /** The current LiquidThreadsVersionObject. **/
 10+// protected $currentVersion;
 11+// /** The ID of the current version **/
 12+// protected $currentVersionID;
 13+//
 14+// /** The version that is being worked on by set methods **/
 15+// protected $pendingVersion;
 16+//
 17+// /**
 18+// * @return String: The name of the class that version objects have.
 19+// */
 20+// abstract public static function getVersionClass();
 21+//
 22+// /**
 23+// * @return String: The name of the database field that stores the current version ID
 24+// */
 25+// abstract public static function getVersionField();
 26+
 27+}
 28+
 29+/**
 30+ * Top-level class for version objects.
 31+ */
 32+abstract class LiquidThreadsVersionObject extends LiquidThreadsObject {
 33+
 34+}
Property changes on: branches/lqt-updates/extensions/LiquidThreads/classes/model/VersionedObject.php
___________________________________________________________________
Added: svn:eol-style
135 + native
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php
@@ -0,0 +1,11 @@
 2+<?php
 3+
 4+class LiquidThreadsObject {
 5+ /**
 6+ * Returns a unique identifier for this object instance.
 7+ * It should be unique for this class.
 8+ * You should return NULL or zero if this instance does not have any
 9+ * unique identifier.
 10+ */
 11+ public abstract function getID();
 12+}
Property changes on: branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php
___________________________________________________________________
Added: svn:eol-style
113 + native

Status & tagging log