Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/EditForm.php |
— | — | @@ -195,5 +195,11 @@ |
196 | 196 | |
197 | 197 | return $signatureEditor; |
198 | 198 | } |
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(); |
200 | 206 | } |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/NewTopicForm.php |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | class LiquidThreadsNewTopicForm extends LiquidThreadsEditForm { |
8 | 8 | |
9 | 9 | protected $channel; |
| 10 | + protected $object; |
10 | 11 | |
11 | 12 | /** |
12 | 13 | * Initialises a LiquidThreadsNewTopicForm. |
— | — | @@ -54,6 +55,8 @@ |
55 | 56 | |
56 | 57 | $post->save(); |
57 | 58 | |
| 59 | + $this->object = $topic; |
| 60 | + |
58 | 61 | return true; |
59 | 62 | } |
60 | 63 | |
— | — | @@ -68,4 +71,8 @@ |
69 | 72 | |
70 | 73 | return true; |
71 | 74 | } |
| 75 | + |
| 76 | + public function getModifiedObject() { |
| 77 | + return $this->object; |
| 78 | + } |
72 | 79 | } |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php |
— | — | @@ -61,4 +61,8 @@ |
62 | 62 | public function validate( $request = null ) { |
63 | 63 | return true; |
64 | 64 | } |
| 65 | + |
| 66 | + public function getModifiedObject() { |
| 67 | + return $this->post; |
| 68 | + } |
65 | 69 | } |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/ReplyForm.php |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | class LiquidThreadsReplyForm extends LiquidThreadsEditForm { |
8 | 8 | |
9 | 9 | protected $topic; |
| 10 | + protected $object; |
10 | 11 | |
11 | 12 | /** |
12 | 13 | * Initialises a LiquidThreadsNewTopicForm. |
— | — | @@ -48,6 +49,8 @@ |
49 | 50 | |
50 | 51 | $post->save(); |
51 | 52 | |
| 53 | + $this->object = $post; |
| 54 | + |
52 | 55 | return true; |
53 | 56 | } |
54 | 57 | |
— | — | @@ -58,4 +61,8 @@ |
59 | 62 | |
60 | 63 | return true; |
61 | 64 | } |
| 65 | + |
| 66 | + public function getModifiedObject() { |
| 67 | + return $this->object; |
| 68 | + } |
62 | 69 | } |
Index: branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php |
— | — | @@ -33,6 +33,9 @@ |
34 | 34 | if ( $formResult ) { |
35 | 35 | $formOutput = array( 'submit' => 'success' ); |
36 | 36 | |
| 37 | + $object = $form->getModifiedObject(); |
| 38 | + $formOutput['object'] = $object->getUniqueIdentifier(); |
| 39 | + |
37 | 40 | $result->addValue( null, 'form', $formOutput ); |
38 | 41 | } |
39 | 42 | } else { |
— | — | @@ -71,7 +74,8 @@ |
72 | 75 | } |
73 | 76 | |
74 | 77 | try { |
75 | | - $channel = LiquidThreadsChannel::newFromID( $params['channel'] ); |
| 78 | + $id = $params['channel']; |
| 79 | + $channel = self::getObject( $id, 'LiquidThreadsChannel' ); |
76 | 80 | } catch ( MWException $excep ) { |
77 | 81 | $this->dieUsage( "You must specify a valid channel", 'invalid-param' ); |
78 | 82 | } |
— | — | @@ -85,14 +89,16 @@ |
86 | 90 | $replyPost = null; |
87 | 91 | |
88 | 92 | try { |
89 | | - $topic = LiquidThreadsTopic::newFromID( $params['topic'] ); |
| 93 | + $topicID = $params['topic']; |
| 94 | + $topic = self::getObject( $topicID, 'LiquidThreadsTopic' ); |
90 | 95 | } catch ( MWException $e ) { |
91 | 96 | $this->dieUsage( "You must specify a valid topic", 'invalid-param' ); |
92 | 97 | } |
93 | 98 | |
94 | 99 | if ( $params['reply-post'] ) { |
| 100 | + $replyPostID = $params['reply-post']; |
95 | 101 | try { |
96 | | - $replyPost = LiquidThreadsPost::newFromID( $params['reply-post'] ); |
| 102 | + $replyPost = self::getObject( $replyPostID, 'LiquidThreadsPost' ); |
97 | 103 | } catch ( MWException $e ) { |
98 | 104 | $this->dieUsage( "Invalid reply-post", 'invalid-param' ); |
99 | 105 | } |
— | — | @@ -105,7 +111,7 @@ |
106 | 112 | } |
107 | 113 | |
108 | 114 | try { |
109 | | - $post = LiquidThreadsPost::newFromID( $params['post'] ); |
| 115 | + $post = self::getObject( $params['post'], 'LiquidThreadsPost' ); |
110 | 116 | } catch ( MWException $e ) { |
111 | 117 | $this->dieUsage( "Invalid post", 'invalid-param' ); |
112 | 118 | } |
— | — | @@ -116,6 +122,27 @@ |
117 | 123 | } |
118 | 124 | } |
119 | 125 | |
| 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 | + |
120 | 147 | public function getAllowedParams() { |
121 | 148 | return array( |
122 | 149 | 'form' => array( |
Index: branches/lqt-updates/extensions/LiquidThreads/lqt.js |
— | — | @@ -948,27 +948,79 @@ |
949 | 949 | params.content = text; |
950 | 950 | params.signature = signature; |
951 | 951 | |
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 | + } ); |
954 | 965 | } ); |
955 | 966 | } else if ( type == 'reply' ) { |
956 | 967 | params.content = text; |
957 | 968 | params.signature = signature; |
958 | 969 | |
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 | + } ); |
961 | 987 | } ); |
962 | 988 | } else if ( type == 'edit' ) { |
963 | 989 | params.summary = summary; |
964 | 990 | params.content = text; |
965 | 991 | params.signature = signature; |
966 | 992 | |
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 | + } ); |
969 | 1006 | } ); |
970 | 1007 | } |
971 | 1008 | }, |
| 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; |
972 | 1017 | |
| 1018 | + liquidThreads.apiRequest( params, function(data) { |
| 1019 | + var html = data.formatter.html; |
| 1020 | + var $formatted = $(html); |
| 1021 | + callback($formatted); |
| 1022 | + } ); |
| 1023 | + }, |
| 1024 | + |
973 | 1025 | 'reloadTOC' : function() { |
974 | 1026 | var toc = $j('.lqt_toc'); |
975 | 1027 | |