r97236 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97235‎ | r97236 | r97237 >
Date:06:11, 16 September 2011
Author:werdna
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/view/ReplyForm.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/lqt.js (modified) (history)

Diff [purge]

Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php
@@ -195,5 +195,11 @@
196196
197197 return $signatureEditor;
198198 }
199 -
 199+
 200+
 201+ /**
 202+ * Call after submit() to get the object that you created or modified
 203+ * @return LiquidThreadsObject: The object created/modified
 204+ */
 205+ public abstract function getModifiedObject();
200206 }
Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php
@@ -6,6 +6,7 @@
77 class LiquidThreadsNewTopicForm extends LiquidThreadsEditForm {
88
99 protected $channel;
 10+ protected $object;
1011
1112 /**
1213 * Initialises a LiquidThreadsNewTopicForm.
@@ -54,6 +55,8 @@
5556
5657 $post->save();
5758
 59+ $this->object = $topic;
 60+
5861 return true;
5962 }
6063
@@ -68,4 +71,8 @@
6972
7073 return true;
7174 }
 75+
 76+ public function getModifiedObject() {
 77+ return $this->object;
 78+ }
7279 }
Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php
@@ -61,4 +61,8 @@
6262 public function validate( $request = null ) {
6363 return true;
6464 }
 65+
 66+ public function getModifiedObject() {
 67+ return $this->post;
 68+ }
6569 }
Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/ReplyForm.php
@@ -6,6 +6,7 @@
77 class LiquidThreadsReplyForm extends LiquidThreadsEditForm {
88
99 protected $topic;
 10+ protected $object;
1011
1112 /**
1213 * Initialises a LiquidThreadsNewTopicForm.
@@ -48,6 +49,8 @@
4950
5051 $post->save();
5152
 53+ $this->object = $post;
 54+
5255 return true;
5356 }
5457
@@ -58,4 +61,8 @@
5962
6063 return true;
6164 }
 65+
 66+ public function getModifiedObject() {
 67+ return $this->object;
 68+ }
6269 }
Index: branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php
@@ -33,6 +33,9 @@
3434 if ( $formResult ) {
3535 $formOutput = array( 'submit' => 'success' );
3636
 37+ $object = $form->getModifiedObject();
 38+ $formOutput['object'] = $object->getUniqueIdentifier();
 39+
3740 $result->addValue( null, 'form', $formOutput );
3841 }
3942 } else {
@@ -71,7 +74,8 @@
7275 }
7376
7477 try {
75 - $channel = LiquidThreadsChannel::newFromID( $params['channel'] );
 78+ $id = $params['channel'];
 79+ $channel = self::getObject( $id, 'LiquidThreadsChannel' );
7680 } catch ( MWException $excep ) {
7781 $this->dieUsage( "You must specify a valid channel", 'invalid-param' );
7882 }
@@ -85,14 +89,16 @@
8690 $replyPost = null;
8791
8892 try {
89 - $topic = LiquidThreadsTopic::newFromID( $params['topic'] );
 93+ $topicID = $params['topic'];
 94+ $topic = self::getObject( $topicID, 'LiquidThreadsTopic' );
9095 } catch ( MWException $e ) {
9196 $this->dieUsage( "You must specify a valid topic", 'invalid-param' );
9297 }
9398
9499 if ( $params['reply-post'] ) {
 100+ $replyPostID = $params['reply-post'];
95101 try {
96 - $replyPost = LiquidThreadsPost::newFromID( $params['reply-post'] );
 102+ $replyPost = self::getObject( $replyPostID, 'LiquidThreadsPost' );
97103 } catch ( MWException $e ) {
98104 $this->dieUsage( "Invalid reply-post", 'invalid-param' );
99105 }
@@ -105,7 +111,7 @@
106112 }
107113
108114 try {
109 - $post = LiquidThreadsPost::newFromID( $params['post'] );
 115+ $post = self::getObject( $params['post'], 'LiquidThreadsPost' );
110116 } catch ( MWException $e ) {
111117 $this->dieUsage( "Invalid post", 'invalid-param' );
112118 }
@@ -116,6 +122,27 @@
117123 }
118124 }
119125
 126+ /**
 127+ * Retrieves an object by user-supplied ID
 128+ * @param $id The object ID, may be either an integer ID specific
 129+ * to the given class or a LiquidThreads unique identifier suitable for
 130+ * passing to LiquidThreadsObject::retrieve()
 131+ * @param $class The class of object to retrieve.
 132+ */
 133+ protected static function getObject( $id, $class ) {
 134+ if ( is_numeric($id) ) {
 135+ $object = $class::newFromId( $id );
 136+ } else {
 137+ $object = LiquidThreadsObject::retrieve($id);
 138+
 139+ if ( ! $object instanceof $class ) {
 140+ throw new MWException( "$id does not represent a $class" );
 141+ }
 142+ }
 143+
 144+ return $object;
 145+ }
 146+
120147 public function getAllowedParams() {
121148 return array(
122149 'form' => array(
Index: branches/lqt-updates/extensions/LiquidThreads/lqt.js
@@ -948,27 +948,79 @@
949949 params.content = text;
950950 params.signature = signature;
951951
952 - liquidThreads.apiRequest( params, function() {
953 - window.location.reload(true);
 952+ liquidThreads.apiRequest( params, function(data) {
 953+ var params = {
 954+ 'formatter' : 'topic',
 955+ 'object' : data.form.object
 956+ };
 957+ liquidThreads.loadFormattedObject( params, function($obj) {
 958+ editform.closest('.lqt-threads').prepend($obj);
 959+ editform.remove();
 960+ $obj.find('.lqt-post-wrapper').each( function() {
 961+ liquidThreads.setupThread( this );
 962+ } );
 963+ liquidThreads.reloadTOC();
 964+ } );
954965 } );
955966 } else if ( type == 'reply' ) {
956967 params.content = text;
957968 params.signature = signature;
958969
959 - liquidThreads.apiRequest( params, function() {
960 - window.location.reload(true);
 970+ liquidThreads.apiRequest( params, function(data) {
 971+ var params = {
 972+ 'formatter' : 'post',
 973+ 'object' : data.form.object
 974+ };
 975+ liquidThreads.loadFormattedObject( params, function($obj) {
 976+ editform.closest('div.lqt-reply-form')
 977+ .after($obj)
 978+ .remove();
 979+ $obj.closest('.lqt-post-tree-wrapper')
 980+ .removeClass('lqt-post-without-replies')
 981+ .addClass('lqt-post-with-replies');
 982+ $obj.find('.lqt-post-wrapper').each( function() {
 983+ liquidThreads.setupThread( this );
 984+ } );
 985+ liquidThreads.reloadTOC();
 986+ } );
961987 } );
962988 } else if ( type == 'edit' ) {
963989 params.summary = summary;
964990 params.content = text;
965991 params.signature = signature;
966992
967 - liquidThreads.apiRequest( params, function() {
968 - window.location.reload(true);
 993+ liquidThreads.apiRequest( params, function(data) {
 994+ var params = {
 995+ 'formatter' : 'post',
 996+ 'object' : data.form.object
 997+ };
 998+ liquidThreads.loadFormattedObject( params, function($obj) {
 999+ editform.closest('.lqt-post-tree-wrapper')
 1000+ .replaceWith($obj);
 1001+ $obj.find('.lqt-post-wrapper').each( function() {
 1002+ liquidThreads.setupThread( this );
 1003+ } );
 1004+ liquidThreads.reloadTOC();
 1005+ } );
9691006 } );
9701007 }
9711008 },
 1009+
 1010+ // Formats an object into a jQuery object and calls the callback with that
 1011+ // as a parameter.
 1012+ 'loadFormattedObject' : function( params, callback ) {
 1013+ params = $.extend( {}, params );
 1014+
 1015+ params.action = 'lqtformat';
 1016+ params['base-url'] = window.location.href;
9721017
 1018+ liquidThreads.apiRequest( params, function(data) {
 1019+ var html = data.formatter.html;
 1020+ var $formatted = $(html);
 1021+ callback($formatted);
 1022+ } );
 1023+ },
 1024+
9731025 'reloadTOC' : function() {
9741026 var toc = $j('.lqt_toc');
9751027

Status & tagging log