http://www.mediawiki.org/wiki/Special:Code/MediaWiki/92464

Revision: 92464
Author:   werdna
Date:     2011-07-18 20:18:23 +0000 (Mon, 18 Jul 2011)
Log Message:
-----------
LiquidThreads backend rewrite: The main channel view is now working with the 
new backend, sans javascript.

Modified Paths:
--------------
    branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php
    branches/lqt-updates/extensions/LiquidThreads/classes/Dispatch.php
    branches/lqt-updates/extensions/LiquidThreads/classes/View.php
    branches/lqt-updates/extensions/LiquidThreads/classes/model/Channel.php
    branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php
    branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php
    branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php
    branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php
    branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/Formatter.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/PostFormatter.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/PostToolbar.php
    
branches/lqt-updates/extensions/LiquidThreads/classes/view/TopicFormatter.php
    branches/lqt-updates/extensions/LiquidThreads/lqt.css
    branches/lqt-updates/extensions/LiquidThreads/new-schema.sql
    branches/lqt-updates/extensions/LiquidThreads/pages/TalkpageView.php

Modified: branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php     
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php     
2011-07-18 20:18:23 UTC (rev 92464)
@@ -72,7 +72,7 @@
 
 $wgResourceModules['ext.liquidThreads'] = $lqtResourceTemplate + array(
        'styles' => array( 'lqt.css', 'jquery/jquery.thread_collapse.css' ),
-       'scripts' => array( 'lqt.js', 'js/lqt.toolbar.js', 
'jquery/jquery.thread_collapse.js', 'jquery/jquery.autogrow.js' ),
+//     'scripts' => array( 'lqt.js', 'js/lqt.toolbar.js', 
'jquery/jquery.thread_collapse.js', 'jquery/jquery.autogrow.js' ),
        'dependencies' => array( 'jquery.ui.dialog' ),
        'messages' => $lqtMessages
 );
@@ -93,9 +93,9 @@
 // $wgHooks['CanonicalNamespaces'][] = 'LqtHooks::onCanonicalNamespaces';
 // 
 // // Main dispatch hook
-// $wgHooks['MediaWikiPerformAction'][] = 'LqtDispatch::tryPage';
-// $wgHooks['SkinTemplateTabs'][] = 'LqtDispatch::onSkinTemplateTabs';
-// $wgHooks['SkinTemplateNavigation'][] = 
'LqtDispatch::onSkinTemplateNavigation';
+$wgHooks['MediaWikiPerformAction'][] = 'LqtDispatch::tryPage';
+$wgHooks['SkinTemplateTabs'][] = 'LqtDispatch::onSkinTemplateTabs';
+$wgHooks['SkinTemplateNavigation'][] = 'LqtDispatch::onSkinTemplateNavigation';
 // 
 // // Customisation of recentchanges
 // $wgHooks['OldChangesListRecentChangesLine'][] = 
'LqtHooks::customizeOldChangesList';
@@ -178,15 +178,15 @@
 // $wgHooks['userCan'][] = 'LqtHooks::onGetUserPermissionsErrors';
 // 
 // // Classes
-// $wgAutoloadClasses['LqtDispatch'] = $dir . 'classes/Dispatch.php';
-// $wgAutoloadClasses['LqtView'] = $dir . 'classes/View.php';
+$wgAutoloadClasses['LqtDispatch'] = $dir . 'classes/Dispatch.php';
+$wgAutoloadClasses['LqtView'] = $dir . 'classes/View.php';
 // $wgAutoloadClasses['HistoricalThread'] = $dir . 
'classes/HistoricalThread.php';
 // $wgAutoloadClasses['Thread'] = $dir . 'classes/Thread.php';
 // $wgAutoloadClasses['Threads'] = $dir . 'classes/Threads.php';
 // $wgAutoloadClasses['NewMessages'] = $dir . 
'classes/NewMessagesController.php';
 // $wgAutoloadClasses['LqtParserFunctions'] = $dir . 
'classes/ParserFunctions.php';
 // $wgAutoloadClasses['LqtDeletionController'] = $dir . 
'classes/DeletionController.php';
-// $wgAutoloadClasses['LqtHooks'] = $dir . 'classes/Hooks.php';
+$wgAutoloadClasses['LqtHooks'] = $dir . 'classes/Hooks.php';
 // $wgAutoloadClasses['ThreadRevision'] = $dir . "classes/ThreadRevision.php";
 // $wgAutoloadClasses['SynchroniseThreadArticleDataJob'] = $dir . 
'classes/SynchroniseThreadArticleDataJob.php';
 // $wgAutoloadClasses['ThreadHistoryPager'] = $dir . 
'classes/ThreadHistoryPager.php';
@@ -195,7 +195,7 @@
 // $wgAutoloadClasses['LqtLogFormatter'] = $dir . 'classes/LogFormatter.php';
 // 
 // // View classes
-// $wgAutoloadClasses['TalkpageView'] = $dir . 'pages/TalkpageView.php';
+$wgAutoloadClasses['TalkpageView'] = $dir . 'pages/TalkpageView.php';
 // $wgAutoloadClasses['ThreadPermalinkView'] = $dir . 
'pages/ThreadPermalinkView.php';
 // $wgAutoloadClasses['TalkpageHeaderView'] = $dir . 
'pages/TalkpageHeaderView.php';
 // $wgAutoloadClasses['IndividualThreadHistoryView'] = $dir . 
'pages/IndividualThreadHistoryView.php';
@@ -271,7 +271,11 @@
 // Edit Forms
 $wgAutoloadClasses['LiquidThreadsEditForm'] = "$dir/classes/view/EditForm.php";
 $wgAutoloadClasses['LiquidThreadsNewTopicForm'] = 
"$dir/classes/view/NewTopicForm.php";
+$wgAutoloadClasses['LiquidThreadsReplyForm'] = 
"$dir/classes/view/ReplyForm.php";
 
+// Views
+$wgAutoloadClasses['LiquidThreadsChannelView'] = 
"$dir/classes/view/ChannelView.php";  
+
 /** CONFIGURATION SECTION */
 
 $wgDefaultUserOptions['lqt-watch-threads'] = true;

Modified: branches/lqt-updates/extensions/LiquidThreads/classes/Dispatch.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/Dispatch.php  
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/Dispatch.php  
2011-07-18 20:18:23 UTC (rev 92464)
@@ -47,7 +47,7 @@
                        $viewname = 'TalkpageView';
                }
 
-               Thread::$titleCacheById[$article->getId()] = $title;
+//             Thread::$titleCacheById[$article->getId()] = $title;
 
                $view = new $viewname( $output, $article, $title, $user, 
$request );
                self::$primaryView = $view;
@@ -202,4 +202,29 @@
 
                return true;
        }
+       
+       /**
+        * Gets a description of the action to be taken from the web request.
+        * @param $request The request to get the data from.
+        * @return Mixed: NULL for no action, array(action, target) for an 
action
+        */
+       public static function getAction( $request = null ) {
+               global $wgRequest;
+               
+               if ( $request == null ) {
+                       $request = $wgRequest;
+               }
+               
+               if ( $request->getCheck( 'lqt_action' ) ) {
+                       $ret = array( $request->getVal('lqt_action') );
+                       
+                       if ( $request->getCheck('lqt_target') ) {
+                               $ret[] = $request->getVal('lqt_target');
+                       }
+                       
+                       return $ret;
+               } else {
+                       return null;
+               }
+       }
 }

Modified: branches/lqt-updates/extensions/LiquidThreads/classes/View.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/View.php      
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/View.php      
2011-07-18 20:18:23 UTC (rev 92464)
@@ -784,50 +784,6 @@
                return true;
        }
 
-       public function getSubjectEditor( $db_subject, $subject ) {
-               if ( $subject === false ) $subject = $db_subject;
-
-               $subject_label = wfMsg( 'lqt_subject' );
-
-               $attr = array( 'tabindex' => 1 );
-
-               return Xml::inputLabel( $subject_label, 'lqt_subject_field',
-                               'lqt_subject_field', 60, $subject, $attr ) .
-                       Xml::element( 'br' );
-       }
-
-       public function getSignatureEditor( $from ) {
-               $signatureText = $this->request->getVal( 'wpLqtSignature', null 
);
-
-               if ( is_null( $signatureText ) ) {
-                       if ( $from instanceof User ) {
-                               $signatureText = LqtView::getUserSignature( 
$from );
-                       } elseif ( $from instanceof Thread ) {
-                               $signatureText = $from->signature();
-                       }
-               }
-
-               $signatureHTML = LqtView::parseSignature( $signatureText );
-
-               // Signature edit box
-               $signaturePreview = Xml::tags(
-                       'span',
-                       array(
-                               'class' => 'lqt-signature-preview',
-                               'style' => 'display: none;'
-                       ),
-                       $signatureHTML
-               );
-               $signatureEditBox = Xml::input(
-                       'wpLqtSignature', 45, $signatureText,
-                       array( 'class' => 'lqt-signature-edit' )
-               );
-
-               $signatureEditor = $signaturePreview . $signatureEditBox;
-
-               return array( $signatureEditor, $signatureHTML );
-       }
-
        static function replyMetadataUpdates( $data = array() ) {
                $requiredFields = array( 'replyTo', 'root', 'text' );
 

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/model/Channel.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/model/Channel.php     
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/model/Channel.php     
2011-07-18 20:18:23 UTC (rev 92464)
@@ -190,4 +190,12 @@
                
                return $row;
        }
+       
+       /**
+        * Gets a globally unique (for all objects) identifier for this object
+        * @return String
+        */
+       public function getUniqueIdentifier() {
+               return 'lqt-channel:'.$this->getID();
+       }
 }

Modified: branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php      
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/model/Object.php      
2011-07-18 20:18:23 UTC (rev 92464)
@@ -15,6 +15,9 @@
         * @return Integer: an ID for the text table.
         */
        public static function saveText( $data ) {
+               if ( $data === null ) {
+                       throw new MWException( "Attempt to save NULL text" );
+               }
                global $wgDefaultExternalStore;
                
                $dbw = wfGetDB( DB_MASTER );
@@ -49,4 +52,10 @@
                
                return $dbw->insertId();
        }
+       
+       /**
+        * Gets a globally unique (for all objects) identifier for this object
+        * @return String
+        */
+       abstract public function getUniqueIdentifier();
 }

Modified: branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php        
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/model/Post.php        
2011-07-18 20:18:23 UTC (rev 92464)
@@ -163,7 +163,7 @@
        protected function initialiseNew( $topic, $parent = null ) {
                $this->id = 0;
                
-               $this->currentVersion = 
LiquidThreadsPostVersion::createNewPost( $topic, $parent );
+               $this->currentVersion = 
LiquidThreadsPostVersion::createNewPost( $this, $topic, $parent );
                $this->pendingVersion = $this->currentVersion;
                
                $this->topic = $topic;
@@ -217,14 +217,6 @@
        public function save( $comment = null ) {
                if ( $this->pendingVersion ) {
                        $this->pendingVersion->commit( $comment );
-                       $this->currentVersion = $this->pendingVersion;
-                       $this->pendingVersion = null;
-                       
-                       if ( !$this->id ) {
-                               $this->insert();
-                       } else {
-                               $this->update();
-                       }
                } else {
                        throw new MWException( "There are no pending changes." 
);
                }
@@ -262,8 +254,9 @@
         * Inserts this Post into the database.
         * ONLY to be called *after* the first PostVersion is saved to the 
database.
         * This should only really be called from LiquidThreadsPost::save
+        * @param $version The LiquidThreadsPostVersion that has just been 
inserted.
         */
-       protected function insert() {
+       public function insert( $version ) {
                $dbw = wfGetDB( DB_MASTER );
                
                if ( $this->getID() ) {
@@ -277,7 +270,9 @@
                $postId = $dbw->insertId();
                $this->id = $postId;
                
-               $this->currentVersion->setPostID( $postId );
+               $this->currentVersion = $version;
+               $this->pendingVersion = null;
+               $version->setPostID( $postId );
                
                if ( $this->topic ) {
                        $this->topic->addPost( $this );
@@ -288,18 +283,25 @@
         * Updates this post in the database.
         * ONLY to be called *after* a PostVersion has been moved into 
currentVersion.
         * Only to be called from LiquidThreadsPost::update()
+        * @param $version The newest version of the post.
         */
-       protected function update() {
+       public function update( $version ) {
                $dbw = wfGetDB( DB_MASTER );
                
                if ( ! $this->getID() ) {
                        throw new MWException( "Post has not been saved!" );
                }
                
+               $this->previousVersion = $this->currentVersion;
+               $this->currentVersion = $version;
+               $this->pendingVersion = null;
+               
                $row = $this->getRow();
                
                $dbw->update( 'lqt_post', $row, array( 'lqp_id' => 
$this->getID() ),
                                __METHOD__ );
+                               
+               $this->getTopic()->touch();
        }
 
        /* PROPERTY ACCESSORS */
@@ -335,6 +337,17 @@
        }
        
        /**
+        * Returns the LiquidThreadsTopic that this post belongs to.
+        */
+       public function getTopic() {
+               if ( !$this->topic ) {
+                       $this->topic = LiquidThreadsTopic::newFromID( 
$this->getTopicID() );
+               }
+               
+               return $this->topic;
+       }
+       
+       /**
         * Returns the ID of the parent post for this post.
         */
        public function getParentID() {
@@ -449,5 +462,13 @@
                
                return $this->replies;
        }
+       
+       /**
+        * Gets a globally unique (for all objects) identifier for this object
+        * @return String
+        */
+       public function getUniqueIdentifier() {
+               return 'lqt-post:'.$this->getID();
+       }
 }
 

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php 
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php 
2011-07-18 20:18:23 UTC (rev 92464)
@@ -216,15 +216,20 @@
        
        /**
         * Factory method to create a Version for a new Post.
+        * @param $post LiquidThreadsPost: The new post.
+        * @param $topic LiquidThreadsTopic: The topic that this post is in.
+        * @param $parent LiquidThreadsPost: (Optional) A parent Post for this 
one.
         * @return LiquidThreadsPostVersion: A Version object for a new post.
         */
-       public static function createNewPost( LiquidThreadsTopic $topic, 
$parent = null )
-       {
-               $post = new LiquidThreadsPostVersion;
+       public static function createNewPost( LiquidThreadsPost $post,
+               LiquidThreadsTopic $topic,
+               $parent = null
+       ) {
+               $version = new LiquidThreadsPostVersion;
                
-               $post->initialiseNewPost( $topic, $parent );
+               $version->initialiseNewPost( $post, $topic, $parent );
                
-               return $post;
+               return $version;
        }
        
        /* Initialisation functions. One of these has to be called on a new 
object */
@@ -327,26 +332,32 @@
        
        /**
         * Initialise a new version object for a new post.
+        * @param $post LiquidThreadsPost: The new post.
         * @param $topic LiquidThreadsTopic: The topic that this post is in.
         * @param $parent LiquidThreadsPost: (Optional) A parent Post for this 
one.
         */
-       protected function initialiseNewPost( LiquidThreadsTopic $topic,
-                       $parent = null )
-       {
+       protected function initialiseNewPost( LiquidThreadsPost $post,
+                       LiquidThreadsTopic $topic,
+                       $parent = null
+       ) {
                global $wgUser;
                
                $this->id = 0;
                $this->poster = $wgUser;
                $this->versionUser = $wgUser;
+               $this->post = $post;
                $this->postID = 0; // Filled later
                $this->textID = 0;
                $this->textRow = null;
                $this->textDirty = true;
                $this->topicID = $topic->getID();
                $this->signature = '';
+               $this->postTime = wfTimestampNow();
                
                if ( $parent ) {
                        $this->parentID = $parent->getID();
+               } else {
+                       $this->parentID = null;
                }
        }
        
@@ -472,6 +483,7 @@
                        'lpv_topic' => $this->topicID,
                        'lpv_signature' => $this->signature,
                        'lpv_post_time' => $this->postTime,
+                       'lpv_parent_post' => $this->parentID,
                );
                
                $this->timestamp = $row['lpv_timestamp'];
@@ -506,6 +518,12 @@
                $dbw->insert( 'lqt_post_version', $row, __METHOD__ );
                
                $this->id = $dbw->insertId();
+               
+               if ( $this->getPostID() == 0 ) {
+                       $this->getPost()->insert($this);
+               } else {
+                       $this->getPost()->update($this);
+               }
        }
 
        /* PROPERTY ACCESSORS */
@@ -701,4 +719,12 @@
                
                $this->post = $post;
        }
+       
+       /**
+        * Gets a globally unique (for all objects) identifier for this object
+        * @return String
+        */
+       public function getUniqueIdentifier() {
+               return 'lqt-post-version:'.$this->getID();
+       }
 }

Modified: branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php       
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/model/Topic.php       
2011-07-18 20:18:23 UTC (rev 92464)
@@ -33,6 +33,9 @@
        /** The number of replies that this topic has **/
        protected $replyCount;
        
+       /** The last time this LiquidThreadsTopic was modified or replied to. 
**/
+       protected $touchedTime;
+       
        /* FACTORY METHODS */
        
        /**
@@ -142,6 +145,7 @@
                $this->channelID = $row->lqt_channel;
                $this->currentVersionID = $row->lqt_current_version;
                $this->replyCount = $row->lqt_replies;
+               $this->touchedTime = $row->lqt_touched;
                
                if ( isset($row->ltv_id) ) {
                        $version = LiquidThreadsTopicVersion::newFromRow( $row 
);
@@ -157,7 +161,7 @@
                $this->id = 0;
                
                $this->currentVersionID = 0;
-               $this->currentVersion = 
LiquidThreadsTopicVersion::createNewTopic( $channel );
+               $this->currentVersion = 
LiquidThreadsTopicVersion::createNewTopic( $this, $channel );
                $this->pendingVersion = $this->currentVersion;
                $this->replyCount = 0;
                
@@ -174,14 +178,6 @@
        public function save( $comment = null ) {
                if ( $this->pendingVersion ) {
                        $this->pendingVersion->commit( $comment );
-                       $this->currentVersion = $this->pendingVersion;
-                       $this->pendingVersion = null;
-                       
-                       if ( $this->id ) {
-                               $this->update( );
-                       } else {
-                               $this->insert( );
-                       }
                } else {
                        throw new MWException( "There are no pending changes." 
);
                }
@@ -191,31 +187,42 @@
         * Updates the Topic row in the database.
         * To be called after a new LiquidThreadsTopicVersion is inserted and
         *  $this->currentVersion has been updated.
-        * Should only really be called from LiquidThreadsPost::save
+        * Should only really be called from LiquidThreadsTopicVersion::commit
         * @param $version The LiquidThreadsTopicVersion object that was just 
saved.
         */
-       protected function update( ) {
+       public function update( $version ) {
                if ( ! $this->getID() ) {
                        throw new MWException( "Attempt to call update() on a 
topic not yet in the database." );
                }
                
                $dbw = wfGetDB( DB_MASTER );
                
+               $this->pendingVersion = null;
+               $this->previousVersion = $this->currentVersion;
+               $this->currentVersion = $version;
+               
                $row = $this->getRow();
                $dbw->update( 'lqt_topic', $row, array( 'lqt_id' => 
$this->getID() ),
                                __METHOD__ );
+
+               $title = $this->getChannel()->getTitle();
+               $title->invalidateCache();
        }
        
        /**
         * Inserts this Post into the database.
         * ONLY to be called *after* the first PostVersion is saved to the 
database.
-        * This should only really be called from LiquidThreadsPost::save
+        * This should only really be called from 
LiquidThreadsTopicVersion::commit
+        * @param $version The LiquidThreadsTopicVersion object that was just 
saved.
         */
-       protected function insert() {
+       public function insert( $version ) {
                if ( $this->getID() ) {
                        throw new MWException( "Attempt to call insert() on a 
topic already inserted" );
                }
                
+               $this->currentVersion = $version;
+               $this->pendingVersion = null;
+               
                $dbw = wfGetDB( DB_MASTER );
                
                $row = $this->getRow();         
@@ -224,7 +231,10 @@
                $topicID = $dbw->insertId();
                $this->id = $topicID;
                
-               $this->currentVersion->setTopicID( $topicID );
+               $version->setTopicID( $topicID );
+               
+               $title = $this->getChannel()->getTitle();
+               $title->invalidateCache();
        }
        
        /**
@@ -237,6 +247,7 @@
                        'lqt_current_version' => $this->currentVersion->getID(),
                        'lqt_channel' => $this->getChannelID(),
                        'lqt_replies' => $this->replyCount,
+                       'lqt_touched' => $dbw->timestamp( wfTimestampNow() ),
                );
                
                if ( !$this->id ) {
@@ -340,6 +351,7 @@
                $conds = array( 'lqp_topic' => $this->getId() );
                
                $this->posts = LiquidThreadsPost::loadFromConditions( $conds );
+               $this->replyCount = count($this->posts);
                
                return $this->posts;
        }
@@ -367,6 +379,23 @@
                return $this->directResponses;
        }
        
+       /**
+        * Retrieves the "touched time" of this Topic.
+        * The last time this topic was modified or replied to.
+        * @return MW format timestamp.
+        */
+       public function getTouchedTime() {
+               return wfTimestamp( TS_MW, $this->touchedTime );
+       }
+       
+       /**
+        * @return The number of posts in this topic.
+        */
+       public function getPostCount() {
+               return count( $this->getPosts() );
+       }
+       
+       
        /* PROPERTY SETTERS */
        
        /**
@@ -420,6 +449,31 @@
                }
                
                $this->posts[$post->getId()] = $post;
+               
+               $this->touch();
        }
+       
+       /**
+        * Gets a globally unique (for all objects) identifier for this object
+        * @return String
+        */
+       public function getUniqueIdentifier() {
+               return 'lqt-topic:'.$this->getID();
+       }
+       
+       /**
+        * Update the last-modified date for this topic.
+        */
+       public function touch() {
+               $dbw = wfGetDB( DB_MASTER );
+               
+               $dbw->update( 'lqt_topic',
+                       array( 'lqt_touched' => $dbw->timestamp( 
wfTimestampNow() ) ),
+                       array( 'lqt_id' => $this->getID() ),
+                       __METHOD__ );
+               
+               $title = $this->getChannel()->getTitle();
+               $title->invalidateCache();
+       }
 }
 

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php
===================================================================
--- 
branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php    
    2011-07-18 20:11:53 UTC (rev 92463)
+++ 
branches/lqt-updates/extensions/LiquidThreads/classes/model/TopicVersion.php    
    2011-07-18 20:18:23 UTC (rev 92464)
@@ -11,6 +11,9 @@
        /** ID of this version **/
        protected $id;
        
+       /** The topic that this version applies to **/
+       protected $topic;
+       
        /** ID of the topic that this version applies to **/
        protected $topicID;
        
@@ -98,7 +101,7 @@
                $tables = array( 'lqt_topic_version' );
                $fields = '*';
                
-               $res = $dbr->select( $tables, $fields, $conditions, __METHOD__, 
array(), $joins );
+               $res = $dbr->select( $tables, $fields, $conditions, __METHOD__, 
array() );
                
                $output = array();
                
@@ -192,14 +195,16 @@
        
        /**
         * Factory method to create a Version for a new LiquidThreadsTopic.
+        * @param $topic The LiquidThreadsTopic being created
         * @param $channel The LiquidThreadsChannel to put this topic in.
         * @return LiquidThreadsTopicVersion: A Version object for a new topic.
         */
-       public static function createNewTopic( LiquidThreadsChannel $channel )
+       public static function createNewTopic( LiquidThreadsTopic $topic,
+               LiquidThreadsChannel $channel )
        {
                $version = new LiquidThreadsTopicVersion;
                
-               $version->initialiseNewTopic( $channel );
+               $version->initialiseNewTopic( $topic, $channel );
                
                return $version;
        }
@@ -277,9 +282,11 @@
        
        /**
         * Initialise a new version object for a new topic.
+        * @param $topic The LiquidThreadsTopic being created
         * @param $channel LiquidThreadsChannel: The channel that this topic is 
in.
         */
-       protected function initialiseNewTopic( LiquidThreadsChannel $channel )
+       protected function initialiseNewTopic( LiquidThreadsTopic $topic,
+               LiquidThreadsChannel $channel )
        {
                global $wgUser;
                
@@ -291,6 +298,8 @@
                $this->summaryTextID = 0;
                $this->summaryTextRow = null;
                $this->summaryTextDirty = true;
+               $this->summaryText = '';
+               $this->topic = $topic;
        }
        
        /* SETTING AND SAVING */
@@ -383,15 +392,14 @@
                
                $this->timestamp = $row['ltv_timestamp'];
                
-               if ( $this->summaryTextDirty ) {
+               if ( $this->summaryTextDirty && $this->summaryText != '' ) {
                        $this->summaryTextID = 
LiquidThreadsObject::saveText($this->summaryText);
                        $this->summaryTextDirty = false;
+               } elseif ( $this->summaryText == '' ) {
+                       $this->summaryTextID = 0;
+                       $this->summaryTextDirty = false;
                }
                
-               if ( $this->summaryTextID == 0 ) {
-                       throw new MWException( "Unable to store revision text" 
);
-               }
-               
                $row['ltv_summary_text_id'] = $this->summaryTextID;
                
                // Poster and user data
@@ -406,6 +414,12 @@
                $dbw->insert( 'lqt_topic_version', $row, __METHOD__ );
                
                $this->id = $dbw->insertId();
+               
+               if ( $this->getTopicID() == 0 ) {
+                       $this->getTopic()->insert( $this );
+               } else {
+                       $this->getTopic()->update( $this );
+               }
        }
 
        /* PROPERTY ACCESSORS */
@@ -468,6 +482,29 @@
        }
        
        /**
+        * @return The ID of the topic that this version is of.
+        */
+       public function getTopicID() {
+               return $this->topicID;
+       }
+       
+       /**
+        * @return The LiquidThreadsTopic that this version is of.
+        */
+       public function getTopic() {
+               $id = $this->getTopicID();
+               if ( ! $this->topic ) {
+                       if ( ! $id ) {
+                               throw new MWException( "This Topic Version is 
not associated with a topic" );
+                       }
+                       
+                       $this->topic = LiquidThreadsTopic::newFromID( $id );
+               }
+               
+               return $this->topic;
+       }
+       
+       /**
         * Lets you set the topic ID, once.
         * Only valid use is from LiquidThreadsTopic::save(), for a new 
LiquidThreadsTopic
         * @param $id Integer: The topic ID that this version applies to.
@@ -514,4 +551,12 @@
                        return false;
                }
        }
+       
+       /**
+        * Gets a globally unique (for all objects) identifier for this object
+        * @return String
+        */
+       public function getUniqueIdentifier() {
+               return 'lqt-topic-version:'.$this->getID();
+       }
 }

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php     
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php     
2011-07-18 20:18:23 UTC (rev 92464)
@@ -15,6 +15,46 @@
        public function __construct( $user ) {
                $this->user = $user;
        }
+       
+       /**
+        * Shows the form, and submits it if necessary
+        * @param $request Web request
+        * @return String: HTML
+        */
+       public function show( $request = null ) {
+               if ( ! $request ) {
+                       global $wgRequest;
+                       $request = $wgRequest;
+               }
+               
+               $tokenMatch = $this->user->matchEditToken( 
$request->getVal('edittoken') );
+               
+               if ( $request->wasPosted() && $tokenMatch ) {
+                       $result = $this->validate( $request );
+                       
+                       if ( $result === true ) {
+                               $result = $this->submit( $request );
+                               
+                               if ( $result ) {
+                                       return $result;
+                               }
+                       } elseif ( $result !== false ) {
+                               return $result;
+                       }
+               }
+               
+               return $this->getFormHTML();
+       }
+       
+       /**
+        * Runs form submission
+        * @param $request: The WebRequest to submit.
+        * @return boolean: False to show the rest of the form, else HTML result
+        */
+       abstract public function submit( $request = null );
+       
+       /**
+        * Validates form fields
 
        /**
         * Gets the HTML of the form, in edit mode.
@@ -64,6 +104,19 @@
                
                $fields['edittoken'] = $this->user->editToken();
                
+               // TODO Testing
+               global $wgTitle;
+               $fields['title'] = $wgTitle->getPrefixedText();
+               $action = LqtDispatch::getAction();
+               
+               if ( count($action) ) {
+                       $fields['lqt_action'] = $action[0];
+               }
+               
+               if ( count($action) > 1 ) {
+                       $fields['lqt_target'] = $action[1];
+               }
+               
                return $fields;
        }
        
@@ -74,7 +127,7 @@
        protected function getButtons() {
                $buttons = array();
                
-               $buttons[] = Html::input( 'save', wfMsg('savearticle'), 
'button',
+               $buttons[] = Html::input( 'save', wfMsg('savearticle'), 
'submit',
                                array(
                                        'class' => 'lqt-save',
                                ) );

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/Formatter.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/view/Formatter.php    
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/view/Formatter.php    
2011-07-18 20:18:23 UTC (rev 92464)
@@ -48,8 +48,8 @@
                        return true;
                }
                
-               if ( isset( $callbacks[$object->getID()] ) ) {
-                       $callback = $callbacks[$object->getID()];
+               if ( isset( $callbacks[$object->getUniqueIdentifier()] ) ) {
+                       $callback = $callbacks[$object->getUniqueIdentifier()];
                        call_user_func_array( $callback, array( $object, 
$context ) );
                        return false;
                } else {
@@ -157,4 +157,24 @@
        public function decrement( $field ) {
                $this->set( $field, $this->get($field) - 1);
        }
+       
+       /**
+        * Gets the action for a given object.
+        * @param $object LiquidThreadsObject: The object to search for.
+        * @return String: Either an action or false.
+        */
+       public function getActionFor( $object ) {
+               if ( $this->isValidField('action') && $this->get( 'action' ) ) {
+                       $actionStruct = $this->get('action');
+                       $match = $actionStruct[1] == 
$object->getUniqueIdentifier();
+                       
+                       if ( count($actionStruct) > 0 && $match ) {
+                               return $actionStruct[0];
+                       }
+               } elseif ( $this->isValidField('parent-context') && 
$this->get('parent-context') ) {
+                       return 
$this->get('parent-context')->getActionFor($object);
+               }
+               
+               return false;
+       }
 }

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php 
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php 
2011-07-18 20:18:23 UTC (rev 92464)
@@ -29,8 +29,43 @@
                
                $html .= $this->getSubjectEditor();
                $html .= $this->getTextbox('lqt-edit-content');
-               $html .= $this->getSignatureEditor();
+               $html .= $this->getSignatureEditor( 
LqtView::getUserSignature($this->user) );
                
                return $html;
        }
+       
+       public function submit( $request = null ) {
+               $subject = $request->getVal('lqt-subject');
+               $text = $request->getVal('lqt-edit-content');
+               $sig = $request->getVal('lqt-signature');
+               
+               // Set up the topic
+               $topic = LiquidThreadsTopic::create( $this->channel );
+               $topic->setSubject( $subject );
+               $topic->getPendingVersion()->setEditor( $this->user );
+               $topic->save();
+               
+               // Now add the first post
+               $post = LiquidThreadsPost::create( $topic );
+               $post->getPendingVersion()->setEditor( $this->user );
+               $post->getPendingVersion()->setPoster( $this->user );
+               $post->setText( $text );
+               $post->setSignature( $sig );
+               
+               $post->save();
+               
+               return true;
+       }
+       
+       public function validate( $request = null ) {
+               if ( ! $request->getVal('lqt-subject') ) {
+                       return false;
+               }
+               
+               if ( ! $request->getVal( 'lqt-edit-content' ) ) {
+                       return false;
+               }
+               
+               return true;
+       }
 }

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/PostFormatter.php
===================================================================
--- 
branches/lqt-updates/extensions/LiquidThreads/classes/view/PostFormatter.php    
    2011-07-18 20:11:53 UTC (rev 92463)
+++ 
branches/lqt-updates/extensions/LiquidThreads/classes/view/PostFormatter.php    
    2011-07-18 20:18:23 UTC (rev 92464)
@@ -53,6 +53,11 @@
                        $context->set('nesting-level', 0);
                }
                
+               if ( ! $context->get('base-url') ) {
+                       global $wgTitle;
+                       $context->set( 'base-url', $wgTitle->getFullURL() );
+               }
+               
                $timestamp = $context->get('timestamp');
                // NULL means current version
                $version = LiquidThreadsPostVersion::newPointInTime( $object, 
$timestamp );
@@ -91,24 +96,49 @@
                                'class' => implode(' ', $wrapperClasses ),
                                'id' => "lqt-post-id-".$object->getID(),
                        ) );
-               $html .= Xml::element( 'a', array('name' => 
$this->getAnchor($object) ) );
+               $html .= Xml::tags( 'span', array('id' => 
$this->getAnchor($object) ), ' ' );
                
                $html .= $this->formatSingleComment( $object, $version, 
$context );
                
-               if ( count($children) ) {
+               $replyForm = false;
+               
+               $myAction = $context->getActionFor( $object );
+               
+               if ( count($children) || $myAction == 'reply' ) {
                        $html .= Xml::openElement( 'div', array( 'class' => 
'lqt-replies' ) );
                        foreach( $children as $child ) {
-                               $html .= $this->formatSingleComment( $child );
+                               $childVersion = 
LiquidThreadsPostVersion::newPointInTime( $child, $context->get('timestamp') );
+                               $html .= $this->formatCommentTree( $child, 
$childVersion, $context );
                        }
+                       
+                       if ( $myAction == 'reply' ) {
+                               $form = new LiquidThreadsReplyForm( 
$context->get('user'), $object->getTopic(), $object );
+                               $formResult = $form->show();
+                               
+                               if ( $formResult !== true ) {
+                                       $html .= $formResult;
+                               } else {
+                                       // TODO hack
+                                       global $wgOut;
+                                       $wgOut->redirect( 
$context->get('base-url') );
+                               }
+                       }
+                       
                        $html .= Xml::closeElement( 'div' );
                }
                
+               $html .= Xml::closeElement( 'div' );
+               
                $context->decrement('nesting-level');
                
                return $html;
        }
        
        /**
+        * Get the action for a given object.
+        * @param $context LiquidThreadsFormatterContext object
+       
+       /**
         * Get the HTML for a *single comment*.
         * This is basically the guts of this formatter, without tree handling 
etc.
         * @param $object The LiquidThreadsPost to show.
@@ -136,7 +166,6 @@
 
                        $html .= $this->getToolbar( $object, $context );
                        $html .= $this->getPostSignature( $object, $version, 
$context );
-                       $html .= Xml::closeElement( 'div' );
                }
                
                $html = Xml::tags( 'div', array( 'class' => 'lqt-post-wrapper' 
), $html );
@@ -251,5 +280,7 @@
                'nesting-level',
                'post-callbacks',
                'version',
+               'parent-context',
+               'base-url',
        );
 }

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/PostToolbar.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/view/PostToolbar.php  
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/view/PostToolbar.php  
2011-07-18 20:18:23 UTC (rev 92464)
@@ -117,10 +117,17 @@
 //                     );
 //             }
 
+               $replyQuery = array(
+                       'lqt_action' => 'reply',
+                       'lqt_target' => $post->getUniqueIdentifier(),
+               );
+
+               $replyLink = wfAppendQuery( $context->get('base-url'), 
$replyQuery );
+
                // TODO permissions checking, proper URL
                $commands['reply'] = array(
                        'label' => wfMsgExt( 'lqt_reply', 'parseinline' ),
-                        'href' => SpecialPage::getTitleFor('Reply', 
$post->getID() )->getFullURL(),
+                        'href' => $replyLink,
                         'enabled' => true,
                         'showlabel' => 1,
                         'tooltip' => wfMsg( 'lqt_reply' ),
@@ -129,11 +136,11 @@
 
                // Parent post link
                if ( $version->getParentID() ) {
-                       $parentID = $version->getParentID();
+                       $parent = LiquidThreadsPost::newFromID( 
$version->getParentID() );
 
                        $commands['parent'] = array(
                                'label' => wfMsgExt( 'lqt-parent', 
'parseinline' ),
-                               'href' => '#' . $this->getAnchor($parentID),
+                               'href' => '#' . $this->getAnchor($parent),
                                'enabled' => true,
                                'showlabel' => 1,
                        );

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/TopicFormatter.php
===================================================================
--- 
branches/lqt-updates/extensions/LiquidThreads/classes/view/TopicFormatter.php   
    2011-07-18 20:11:53 UTC (rev 92463)
+++ 
branches/lqt-updates/extensions/LiquidThreads/classes/view/TopicFormatter.php   
    2011-07-18 20:18:23 UTC (rev 92464)
@@ -69,6 +69,8 @@
                        $postContext->set( 'timestamp', 
$context->get('timestamp') );
                        $postContext->set( 'user', $context->get('user') );
                        $postContext->set( 'language', 
$context->get('language') );
+                       $postContext->set( 'parent-context', $context );
+                       $postContext->set( 'base-url', 
$context->get('base-url') );
                }
                
                // Set up formatter
@@ -161,7 +163,10 @@
                'timestamp',
                'user',
                'language',
+               'parent-context',
+               'version',
+               'action',
                'post-context',
-               'version',
+               'base-url',
        );
 }

Modified: branches/lqt-updates/extensions/LiquidThreads/lqt.css
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/lqt.css       2011-07-18 
20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/lqt.css       2011-07-18 
20:18:23 UTC (rev 92464)
@@ -304,9 +304,8 @@
        padding-right: 0.5em;
 }
 
-.lqt-thread-replies {
+.lqt-replies {
        padding-left: 1em;
-       
 }
 
 .lqt-thread-replies-interruption {

Modified: branches/lqt-updates/extensions/LiquidThreads/new-schema.sql
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/new-schema.sql        
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/new-schema.sql        
2011-07-18 20:18:23 UTC (rev 92464)
@@ -30,10 +30,12 @@
        
        -- The Channel that this topic is contained in.
        -- Foreign key to lqt_channel.lqc_id
-       lqt_channel bigint(10) unsigned not null
+       lqt_channel bigint(10) unsigned not null,
+       
+       lqt_touched varbinary(14) not null
 ) /*$wgDBTableOptions*/;
 
-CREATE INDEX /*i*/lqt_topic_channel ON /*_*/lqt_topic (lqt_channel);
+CREATE INDEX /*i*/lqt_topic_channel ON /*_*/lqt_topic 
(lqt_channel,lqt_touched);
 
 
 -- Topic Version table

Modified: branches/lqt-updates/extensions/LiquidThreads/pages/TalkpageView.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/pages/TalkpageView.php        
2011-07-18 20:11:53 UTC (rev 92463)
+++ branches/lqt-updates/extensions/LiquidThreads/pages/TalkpageView.php        
2011-07-18 20:18:23 UTC (rev 92464)
@@ -2,7 +2,6 @@
 if ( !defined( 'MEDIAWIKI' ) ) die;
 
 class TalkpageView extends LqtView {
-       protected $mShowItems = array( 'toc', 'options', 'header' );
        protected $talkpage;
        
        function __construct( &$output, &$article, &$title, &$user, &$request ) 
{
@@ -116,469 +115,26 @@
                }
        }
 
-       function getTOC( $threads ) {
-               global $wgLang;
 
-               $html = '';
-
-               $h2_header = Xml::tags( 'h2', null, wfMsgExt( 
'lqt_contents_title', 'parseinline' ) );
-
-               // Header row
-               $headerRow = '';
-               $headers = array( 'lqt_toc_thread_title',
-                               'lqt_toc_thread_replycount', 
'lqt_toc_thread_modified' );
-               foreach ( $headers as $msg ) {
-                       $headerRow .= Xml::tags( 'th', null, wfMsgExt( $msg, 
'parseinline' ) );
-               }
-               $headerRow = Xml::tags( 'tr', null, $headerRow );
-               $headerRow = Xml::tags( 'thead', null, $headerRow );
-
-               // Table body
-               $rows = array();
-               foreach ( $threads as $thread ) {
-                       if ( $thread->root() && !$thread->root()->getContent() 
&&
-                                   !LqtView::threadContainsRepliesWithContent( 
$thread ) ) {
-                               continue;
-                       }
-
-                       $row = '';
-                       $anchor = '#' . $this->anchorName( $thread );
-                       $subject = Xml::tags( 'a', array( 'href' => $anchor ),
-                                       Threads::stripHTML( 
$thread->formattedSubject() ) );
-                       $row .= Xml::tags( 'td', null, $subject );
-
-                       $row .= Xml::element( 'td', null, $thread->replyCount() 
);
-
-                       $timestamp = $wgLang->timeanddate( $thread->modified(), 
true );
-                       $row .= Xml::element( 'td', null, $timestamp );
-
-                       $row = Xml::tags( 'tr', null, $row );
-                       $rows[] = $row;
-               }
-
-               $html .= $headerRow . "\n" . Xml::tags( 'tbody', null, implode( 
"\n", $rows ) );
-               $html = $h2_header . Xml::tags( 'table', array( 'class' => 
'lqt_toc' ), $html );
-               // wrap our output in a div for containment
-               $html = Xml::tags( 'div', array( 'class' => 
'lqt-contents-wrapper' ), $html );
-               
-               return $html;
-       }
-
-       function getList( $kind, $class, $id, $contents ) {
-               $html = '';
-               foreach ( $contents as $li ) {
-                       $html .= Xml::tags( 'li', null, $li );
-               }
-               $html = Xml::tags( $kind, array( 'class' => $class, 'id' => $id 
), $html );
-
-               return $html;
-       }
-
-       function getArchiveWidget( ) {
-               $url = $this->talkpageUrl( $this->title, 'talkpage_archive' );
-
-               $html = '';
-               $html = Xml::tags( 'div', array( 'class' => 
'lqt_archive_teaser' ), $html );
-               return $html;
-       }
-
-       function showTalkpageViewOptions( ) {
-               $form_action_url = $this->talkpageUrl( $this->title, 
'talkpage_sort_order' );
-               $html = '';
-
-               $html .= Xml::label( wfMsg( 'lqt_sorting_order' ), 
'lqt_sort_select' ) . ' ';
-
-               $sortOrderSelect =
-                       new XmlSelect( 'lqt_order', 'lqt_sort_select', 
$this->getSortType() );
-
-               $sortOrderSelect->setAttribute( 'class', 'lqt_sort_select' );
-               $sortOrderSelect->addOption(
-                       wfMsg( 'lqt_sort_newest_changes' ),
-                       LQT_NEWEST_CHANGES
-               );
-               $sortOrderSelect->addOption(
-                       wfMsg( 'lqt_sort_newest_threads' ),
-                       LQT_NEWEST_THREADS
-               );
-               $sortOrderSelect->addOption(
-                       wfMsg( 'lqt_sort_oldest_threads' ),
-                       LQT_OLDEST_THREADS
-               );
-               $html .= $sortOrderSelect->getHTML();
-
-               $html .= Xml::submitButton( wfMsg( 'go' ), array( 'class' => 
'lqt_go_sort' ) );
-               $html .= Html::hidden( 'title', $this->title->getPrefixedText() 
);
-
-
-               $html = Xml::tags(
-                       'form',
-                       array(
-                               'action' => $form_action_url,
-                               'method' => 'get',
-                               'name' => 'lqt_sort'
-                       ),
-                       $html
-               );
-               $html = Xml::tags( 'div', array( 'class' => 'lqt_view_options' 
), $html );
-
-               return $html;
-       }
-
        function show() {
-               $this->output->addModules( 'ext.liquidThreads' );
-
                $this->output->setPageTitle( $this->title->getPrefixedText() );
 
-               // Expose feed links.
-               global $wgFeedClasses;
-               $apiParams = array( 'action' => 'feedthreads', 'type' => 
'replies|newthreads',
-                               'talkpage' => $this->title->getPrefixedText() );
-               $urlPrefix = wfScript( 'api' ) . '?';
-               foreach ( $wgFeedClasses as $format => $class ) {
-                       $theseParams = $apiParams + array( 'feedformat' => 
$format );
-                       $url = $urlPrefix . wfArrayToCGI( $theseParams );
-                       $this->output->addFeedLink( $format, $url );
-               }
+               $this->showHeader();
 
-               $sk = $this->user->getSkin();
-
-               $article = new Article( $this->title );
-
-               if ( $this->request->getBool( 'lqt_inline' ) ) {
-                       $this->doInlineEditForm();
-                       return false;
+               try {
+                       $channel = LiquidThreadsChannel::newFromTitle( 
$this->title );
+               } catch ( MWException $excep ) {
+                       $channel = LiquidThreadsChannel::create( $title );
                }
-
-               // Search!
-               if ( $this->request->getCheck( 'lqt_search' ) ) {
-                       $q = $this->request->getText( 'lqt_search' );
-                       $q .= ' ondiscussionpage:' . 
$article->getTitle()->getPrefixedText();
-
-                       $params = array(
-                               'search' => $q,
-                               'fulltext' => 1,
-                               'ns' . NS_LQT_THREAD => 1,
-                       );
-
-                       $t = SpecialPage::getTitleFor( 'Search' );
-                       $url = $t->getLocalURL( wfArrayToCGI( $params ) );
-
-                       $this->output->redirect( $url );
-                       return true;
-               }
-
-               if ( $this->shouldShow('header') ) {
-                       $this->showHeader();
-               }
-
-               $html = '';
-
-               // Set up a per-page header for new threads, search box, and 
sorting stuff.
-
-               $talkpageHeader = '';
-
-               if ( Thread::canUserPost( $this->user, $this->article ) ) {
-                       $newThreadText = wfMsgExt( 'lqt_new_thread', 
'parseinline' );
-                       $newThreadLink = $sk->link(
-                               $this->title, $newThreadText,
-                               array( 'lqt_talkpage' => 
$this->talkpage->getTitle()->getPrefixedText() ),
-                               array( 'lqt_method' => 'talkpage_new_thread' ),
-                               array( 'known' )
-                       );
-
-                       $newThreadLink = Xml::tags(
-                               'strong',
-                               array( 'class' => 'lqt_start_discussion' ),
-                               $newThreadLink
-                       );
-                       
-                       $talkpageHeader .= $newThreadLink;
-               }
-
-               $talkpageHeader .= $this->getSearchBox();
-               $talkpageHeader .= $this->showTalkpageViewOptions( $article );
-               $talkpageHeader = Xml::tags(
-                       'div',
-                       array( 'class' => 'lqt-talkpage-header' ),
-                       $talkpageHeader
-               );
-
-               if ( $this->shouldShow('options') ) {
-                       $this->output->addHTML( $talkpageHeader );
-               } elseif ( $this->shouldShow('simplenew') ) {
-                       $this->output->addHTML( $newThreadLink );
-               }
-
-               if ( $this->methodApplies( 'talkpage_new_thread' ) ) {
-                       $params = array( 'class' => 'lqt-new-thread 
lqt-edit-form' );
-                       $this->output->addHTML( Xml::openElement( 'div', 
$params ) );
-                       $this->showNewThreadForm( $this->article );
-                       $this->output->addHTML( Xml::closeElement( 'div' ) );
-               } else {
-                       $this->output->addHTML( Xml::tags( 'div',
-                               array( 'class' => 'lqt-new-thread 
lqt-edit-form' ), '' ) );
-               }
-
-               $pager = $this->getPager();
-
-               $threads = $this->getPageThreads( $pager );
-
-               if ( count( $threads ) > 0 && $this->shouldShow('toc') ) {
-                       $html .= $this->getTOC( $threads );
-               } elseif ( count($threads) == 0 ) {
-                       $html .= Xml::tags( 'div', array( 'class' => 
'lqt-no-threads' ),
-                                       wfMsgExt( 'lqt-no-threads', 
'parseinline' ) );
-               }
-
-               $html .= $pager->getNavigationBar();
-               $html .= Xml::openElement( 'div', array( 'class' => 
'lqt-threads lqt-talkpage-threads' ) );
-
-               $this->output->addHTML( $html );
-
-               foreach ( $threads as $t ) {
-                       $this->showThread( $t );
-               }
-
-               $this->output->addHTML( Xml::closeElement( 'div' ) . 
$pager->getNavigationBar() );
                
-               // Workaround for bug 25077
-               global $wgOut, $wgUser;
-               $wgUser->getSkin()->setTitle( $wgOut->getTitle() );
+               $action = LqtDispatch::getAction();
+               
+               $channelView = new LiquidThreadsChannelView( $channel );
+               
+               $channelView->show( $action );
 
                return false;
        }
 
-       function getSearchBox() {
-               $html = '';
-               $html .= Xml::inputLabel(
-                       wfMsg( 'lqt-search-label' ),
-                       'lqt_search',
-                       'lqt-search-box',
-                       45
-               );
-
-               $html .= ' ' . Xml::submitButton( wfMsg( 'lqt-search-button' ) 
);
-               $html .= Html::hidden( 'title', $this->title->getPrefixedText() 
);
-               $html = Xml::tags(
-                       'form',
-                       array(
-                               'action' => $this->title->getLocalURL(),
-                               'method' => 'get'
-                       ),
-                       $html
-               );
-
-               $html = Xml::tags( 'div', array( 'class' => 
'lqt-talkpage-search' ), $html );
-
-               return $html;
-       }
-
-       function getPager() {
-
-               $sortType = $this->getSortType();
-               return new LqtDiscussionPager( $this->talkpage, $sortType );
-       }
-
-       function getPageThreads( $pager ) {
-               $rows = $pager->getRows();
-
-               return Thread::bulkLoad( $rows );
-       }
-
-       function getSortType() {
-               // Determine sort order
-               if ( $this->request->getCheck( 'lqt_order' ) ) {
-                       // Sort order is explicitly specified through UI
-                       $lqt_order = $this->request->getVal( 'lqt_order' );
-                       switch( $lqt_order ) {
-                               case 'nc':
-                                       return LQT_NEWEST_CHANGES;
-                               case 'nt':
-                                       return LQT_NEWEST_THREADS;
-                               case 'ot':
-                                       return LQT_OLDEST_THREADS;
-                       }
-               }
-
-               // Default
-               return LQT_NEWEST_CHANGES;
-       }
-       
-       // Hide a number of items from the view
-       // Valid values: toc, options, header
-       function hideItems( $items ) {
-               $this->mShowItems = array_diff( $this->mShowItems, 
(array)$items );
-       }
-       
-       // Show a number of items in the view
-       // Valid values: toc, options, header
-       function showItems( $items ) {
-               $this->mShowItems = array_merge( $this->mShowItems, 
(array)$items );
-       }
-       
-       // Whether or not to show an item
-       function shouldShow( $item ) {
-               return in_array( $item, $this->mShowItems );
-       }
-       
-       // Set the items shown
-       function setShownItems( $items ) {
-               $this->mShowItems = $items;
-       }
 }
 
-class LqtDiscussionPager extends IndexPager {
-       function __construct( $article, $orderType ) {
-               $this->article = $article;
-               $this->orderType = $orderType;
-
-               parent::__construct();
-
-               $this->mLimit = $this->getPageLimit();
-       }
-
-       function getPageLimit() {
-               $article = $this->article;
-
-               global $wgRequest;
-               $requestedLimit = $wgRequest->getVal( 'limit', null );
-               if ( $requestedLimit ) {
-                       return $requestedLimit;
-               }
-
-               if ( $article->exists() ) {
-                       $pout = $article->getParserOutput();
-                       $setLimit = $pout->getProperty( 'lqt-page-limit' );
-                       if ( $setLimit ) return $setLimit;
-               }
-
-               global $wgLiquidThreadsDefaultPageLimit;
-               return $wgLiquidThreadsDefaultPageLimit;
-       }
-
-       function getQueryInfo() {
-               $queryInfo = array(
-                       'tables' => array( 'thread' ),
-                       'fields' => '*',
-                       'conds' => array(
-                               Threads::articleClause( $this->article ),
-                               Threads::topLevelClause(),
-                               'thread_type != ' . $this->mDb->addQuotes( 
Threads::TYPE_DELETED ),
-                       ),
-               );
-
-               return $queryInfo;
-       }
-
-       // Adapted from getBody().
-       function getRows() {
-               if ( !$this->mQueryDone ) {
-                       $this->doQuery();
-               }
-
-               # Don't use any extra rows returned by the query
-               $numRows = min( $this->mResult->numRows(), $this->mLimit );
-
-               $rows = array();
-
-               if ( $numRows ) {
-                       if ( $this->mIsBackwards ) {
-                               for ( $i = $numRows - 1; $i >= 0; $i-- ) {
-                                       $this->mResult->seek( $i );
-                                       $row = $this->mResult->fetchObject();
-                                       $rows[] = $row;
-                               }
-                       } else {
-                               $this->mResult->seek( 0 );
-                               for ( $i = 0; $i < $numRows; $i++ ) {
-                                       $row = $this->mResult->fetchObject();
-                                       $rows[] = $row;
-                               }
-                       }
-               }
-
-               return $rows;
-       }
-
-       function formatRow( $row ) {
-               // No-op, we get the list of rows from getRows()
-       }
-
-       function getIndexField() {
-               switch( $this->orderType ) {
-                       case LQT_NEWEST_CHANGES:
-                               return 'thread_sortkey';
-                       case LQT_OLDEST_THREADS:
-                       case LQT_NEWEST_THREADS:
-                               return 'thread_created';
-                       default:
-                               throw new MWException( "Unknown sort order " . 
$this->orderType );
-               }
-       }
-
-       function getDefaultDirections() {
-               switch( $this->orderType ) {
-                       case LQT_NEWEST_CHANGES:
-                       case LQT_NEWEST_THREADS:
-                               return true; // Descending
-                       case LQT_OLDEST_THREADS:
-                               return false; // Ascending
-                       default:
-                               throw new MWException( "Unknown sort order " . 
$this->orderType );
-               }
-       }
-
-       /**
-        * A navigation bar with images
-        * Stolen from TablePager because it's pretty.
-        */
-       function getNavigationBar() {
-               global $wgStylePath, $wgContLang;
-
-               if ( method_exists( $this, 'isNavigationBarShown' ) &&
-                               !$this->isNavigationBarShown() )
-                       return '';
-
-               $path = "$wgStylePath/common/images";
-               $labels = array(
-                       'first' => 'table_pager_first',
-                       'prev' => 'table_pager_prev',
-                       'next' => 'table_pager_next',
-                       'last' => 'table_pager_last',
-               );
-               $images = array(
-                       'first' => $wgContLang->isRTL() ? 'arrow_last_25.png' : 
'arrow_first_25.png',
-                       'prev' =>  $wgContLang->isRTL() ? 'arrow_right_25.png' 
: 'arrow_left_25.png',
-                       'next' =>  $wgContLang->isRTL() ? 'arrow_left_25.png' : 
'arrow_right_25.png',
-                       'last' =>  $wgContLang->isRTL() ? 'arrow_first_25.png' 
: 'arrow_last_25.png',
-               );
-               $disabledImages = array(
-                       'first' => $wgContLang->isRTL() ? 
'arrow_disabled_last_25.png' : 'arrow_disabled_first_25.png',
-                       'prev' =>  $wgContLang->isRTL() ? 
'arrow_disabled_right_25.png' : 'arrow_disabled_left_25.png',
-                       'next' =>  $wgContLang->isRTL() ? 
'arrow_disabled_left_25.png' : 'arrow_disabled_right_25.png',
-                       'last' =>  $wgContLang->isRTL() ? 
'arrow_disabled_first_25.png' : 'arrow_disabled_last_25.png',
-               );
-
-               $linkTexts = array();
-               $disabledTexts = array();
-               foreach ( $labels as $type => $label ) {
-                       $msgLabel = wfMsgHtml( $label );
-                       $linkTexts[$type] = "<img 
src=\"$path/{$images[$type]}\" alt=\"$msgLabel\"/><br />$msgLabel";
-                       $disabledTexts[$type] = "<img 
src=\"$path/{$disabledImages[$type]}\" alt=\"$msgLabel\"/><br />$msgLabel";
-               }
-               $links = $this->getPagingLinks( $linkTexts, $disabledTexts );
-
-               $navClass = htmlspecialchars( $this->getNavClass() );
-               $s = "<table class=\"$navClass\" align=\"center\" 
cellpadding=\"3\"><tr>\n";
-               $cellAttrs = 'valign="top" align="center" width="' . 100 / 
count( $links ) . '%"';
-               foreach ( $labels as $type => $label ) {
-                       $s .= "<td $cellAttrs>{$links[$type]}</td>\n";
-               }
-               $s .= "</tr></table>\n";
-               return $s;
-       }
-
-       function getNavClass() {
-               return 'TalkpagePager_nav';
-       }
-}


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to