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

Revision: 97236
Author:   werdna
Date:     2011-09-16 06:11:12 +0000 (Fri, 16 Sep 2011)
Log Message:
-----------
LiquidThreads: instead of reloading the page, actually show changes in-place. 
TODO: replies currently show up threaded before refresh, but that does not 
reflect current behaviour

Modified Paths:
--------------
    branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php
    branches/lqt-updates/extensions/LiquidThreads/classes/view/ReplyForm.php
    branches/lqt-updates/extensions/LiquidThreads/lqt.js

Modified: branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php    
2011-09-16 06:05:39 UTC (rev 97235)
+++ branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php    
2011-09-16 06:11:12 UTC (rev 97236)
@@ -33,6 +33,9 @@
                        if ( $formResult ) {
                                $formOutput = array( 'submit' => 'success' );
                                
+                               $object = $form->getModifiedObject();
+                               $formOutput['object'] = 
$object->getUniqueIdentifier();
+                               
                                $result->addValue( null, 'form', $formOutput );
                        }
                } else {
@@ -71,7 +74,8 @@
                        }
                        
                        try {
-                               $channel = LiquidThreadsChannel::newFromID( 
$params['channel'] );
+                               $id = $params['channel'];
+                               $channel = self::getObject( $id, 
'LiquidThreadsChannel' );
                        } catch ( MWException $excep ) {
                                $this->dieUsage( "You must specify a valid 
channel", 'invalid-param' );
                        }
@@ -85,14 +89,16 @@
                        $replyPost = null;
                        
                        try {
-                               $topic = LiquidThreadsTopic::newFromID( 
$params['topic'] );
+                               $topicID = $params['topic'];
+                               $topic = self::getObject( $topicID, 
'LiquidThreadsTopic' );
                        } catch ( MWException $e ) {
                                $this->dieUsage( "You must specify a valid 
topic", 'invalid-param' );
                        }
                        
                        if ( $params['reply-post'] ) {
+                               $replyPostID = $params['reply-post'];
                                try {
-                                       $replyPost = 
LiquidThreadsPost::newFromID( $params['reply-post'] );
+                                       $replyPost = self::getObject( 
$replyPostID, 'LiquidThreadsPost' );
                                } catch ( MWException $e ) {
                                        $this->dieUsage( "Invalid reply-post", 
'invalid-param' );
                                }
@@ -105,7 +111,7 @@
                        }
                        
                        try {
-                               $post = LiquidThreadsPost::newFromID( 
$params['post'] );
+                               $post = self::getObject( $params['post'], 
'LiquidThreadsPost' );
                        } catch ( MWException $e ) {
                                $this->dieUsage( "Invalid post", 
'invalid-param' );
                        }
@@ -116,6 +122,27 @@
                }
        }
        
+       /**
+        * Retrieves an object by user-supplied ID
+        * @param $id The object ID, may be either an integer ID specific
+        * to the given class or a LiquidThreads unique identifier suitable for
+        * passing to LiquidThreadsObject::retrieve()
+        * @param $class The class of object to retrieve.
+        */
+       protected static function getObject( $id, $class ) {
+               if ( is_numeric($id) ) {
+                       $object = $class::newFromId( $id );
+               } else {
+                       $object = LiquidThreadsObject::retrieve($id);
+                       
+                       if ( ! $object instanceof $class ) {
+                               throw new MWException( "$id does not represent 
a $class" );
+                       }
+               }
+               
+               return $object;
+       }
+       
        public function getAllowedParams() {
                return array(
                        'form' => array(

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php     
2011-09-16 06:05:39 UTC (rev 97235)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php     
2011-09-16 06:11:12 UTC (rev 97236)
@@ -195,5 +195,11 @@
 
                return $signatureEditor;
        }
-        
+       
+       
+       /**
+        * Call after submit() to get the object that you created or modified
+        * @return LiquidThreadsObject: The object created/modified
+        */
+       public abstract function getModifiedObject();
 }

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php 
2011-09-16 06:05:39 UTC (rev 97235)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php 
2011-09-16 06:11:12 UTC (rev 97236)
@@ -6,6 +6,7 @@
 class LiquidThreadsNewTopicForm extends LiquidThreadsEditForm {
 
        protected $channel;
+       protected $object;
 
        /**
         * Initialises a LiquidThreadsNewTopicForm.
@@ -54,6 +55,8 @@
                
                $post->save();
                
+               $this->object = $topic;
+               
                return true;
        }
        
@@ -68,4 +71,8 @@
                
                return true;
        }
+       
+       public function getModifiedObject() {
+               return $this->object;
+       }
 }

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php 
2011-09-16 06:05:39 UTC (rev 97235)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php 
2011-09-16 06:11:12 UTC (rev 97236)
@@ -61,4 +61,8 @@
        public function validate( $request = null ) {
                return true;
        }
+       
+       public function getModifiedObject() {
+               return $this->post;
+       }
 }

Modified: 
branches/lqt-updates/extensions/LiquidThreads/classes/view/ReplyForm.php
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/classes/view/ReplyForm.php    
2011-09-16 06:05:39 UTC (rev 97235)
+++ branches/lqt-updates/extensions/LiquidThreads/classes/view/ReplyForm.php    
2011-09-16 06:11:12 UTC (rev 97236)
@@ -6,6 +6,7 @@
 class LiquidThreadsReplyForm extends LiquidThreadsEditForm {
 
        protected $topic;
+       protected $object;
 
        /**
         * Initialises a LiquidThreadsNewTopicForm.
@@ -48,6 +49,8 @@
                
                $post->save();
                
+               $this->object = $post;
+               
                return true;
        }
        
@@ -58,4 +61,8 @@
                
                return true;
        }
+       
+       public function getModifiedObject() {
+               return $this->object;
+       }
 }

Modified: branches/lqt-updates/extensions/LiquidThreads/lqt.js
===================================================================
--- branches/lqt-updates/extensions/LiquidThreads/lqt.js        2011-09-16 
06:05:39 UTC (rev 97235)
+++ branches/lqt-updates/extensions/LiquidThreads/lqt.js        2011-09-16 
06:11:12 UTC (rev 97236)
@@ -948,27 +948,79 @@
                        params.content = text;
                        params.signature = signature;
                        
-                       liquidThreads.apiRequest( params, function() {
-                               window.location.reload(true);
+                       liquidThreads.apiRequest( params, function(data) {
+                               var params = {
+                                       'formatter' : 'topic',
+                                       'object' : data.form.object
+                               };
+                               liquidThreads.loadFormattedObject( params, 
function($obj) {
+                                       
editform.closest('.lqt-threads').prepend($obj);
+                                       editform.remove();
+                                       $obj.find('.lqt-post-wrapper').each( 
function() {
+                                               liquidThreads.setupThread( this 
);
+                                       } );
+                                       liquidThreads.reloadTOC();
+                               } );
                        } );
                } else if ( type == 'reply' ) {
                        params.content = text;
                        params.signature = signature;
                        
-                       liquidThreads.apiRequest( params, function() {
-                               window.location.reload(true);
+                       liquidThreads.apiRequest( params, function(data) {
+                               var params = {
+                                       'formatter' : 'post',
+                                       'object' : data.form.object
+                               };
+                               liquidThreads.loadFormattedObject( params, 
function($obj) {
+                                       editform.closest('div.lqt-reply-form')
+                                               .after($obj)
+                                               .remove();
+                                       $obj.closest('.lqt-post-tree-wrapper')
+                                               
.removeClass('lqt-post-without-replies')
+                                               
.addClass('lqt-post-with-replies');
+                                       $obj.find('.lqt-post-wrapper').each( 
function() {
+                                               liquidThreads.setupThread( this 
);
+                                       } );
+                                       liquidThreads.reloadTOC();
+                               } );
                        } );
                } else if ( type == 'edit' ) {
                        params.summary = summary;
                        params.content = text;
                        params.signature = signature;
                        
-                       liquidThreads.apiRequest( params, function() {
-                               window.location.reload(true);
+                       liquidThreads.apiRequest( params, function(data) {
+                               var params = {
+                                       'formatter' : 'post',
+                                       'object' : data.form.object
+                               };
+                               liquidThreads.loadFormattedObject( params, 
function($obj) {
+                                       
editform.closest('.lqt-post-tree-wrapper')
+                                               .replaceWith($obj);
+                                       $obj.find('.lqt-post-wrapper').each( 
function() {
+                                               liquidThreads.setupThread( this 
);
+                                       } );
+                                       liquidThreads.reloadTOC();
+                               } );
                        } );
                }
        },
+       
+       // Formats an object into a jQuery object and calls the callback with 
that
+       // as a parameter.
+       'loadFormattedObject' : function( params, callback ) {
+               params = $.extend( {}, params );
+               
+               params.action = 'lqtformat';
+               params['base-url'] = window.location.href;
 
+               liquidThreads.apiRequest( params, function(data) { 
+                       var html = data.formatter.html;
+                       var $formatted = $(html);
+                       callback($formatted);
+               } );
+       },
+
        'reloadTOC' : function() {
                var toc = $j('.lqt_toc');
 


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

Reply via email to