Index: branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php |
— | — | @@ -275,6 +275,7 @@ |
276 | 276 | $wgAutoloadClasses['LiquidThreadsEditForm'] = "$dir/classes/view/EditForm.php"; |
277 | 277 | $wgAutoloadClasses['LiquidThreadsNewTopicForm'] = "$dir/classes/view/NewTopicForm.php"; |
278 | 278 | $wgAutoloadClasses['LiquidThreadsReplyForm'] = "$dir/classes/view/ReplyForm.php"; |
| 279 | +$wgAutoloadClasses['LiquidThreadsPostEditForm'] = "$dir/classes/view/PostEditForm.php"; |
279 | 280 | |
280 | 281 | // Views |
281 | 282 | $wgAutoloadClasses['LiquidThreadsChannelView'] = "$dir/classes/view/ChannelView.php"; |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php |
— | — | @@ -322,6 +322,7 @@ |
323 | 323 | $this->topicID = $baseVersion->getTopicID(); |
324 | 324 | $this->parentID = $baseVersion->getParentID(); |
325 | 325 | $this->signature = $baseVersion->getSignature(); |
| 326 | + $this->postTime = $baseVersion->getPostTime(); |
326 | 327 | |
327 | 328 | global $wgUser; |
328 | 329 | $this->versionUser = $wgUser; |
Index: branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * LiquidThreadsEditForm to edit a post's contents. |
| 6 | + */ |
| 7 | +class LiquidThreadsPostEditForm extends LiquidThreadsEditForm { |
| 8 | + protected $post; |
| 9 | + |
| 10 | + /** |
| 11 | + * Initialises a LiquidThreadsPostEditForm. |
| 12 | + * @param $user The user viewing this form. |
| 13 | + * @param $post The post to be edited. |
| 14 | + */ |
| 15 | + public function __construct( $user, $post ) { |
| 16 | + parent::__construct( $user ); |
| 17 | + |
| 18 | + if ( ! $post instanceof LiquidThreadsPost ) { |
| 19 | + throw new MWException( "Invalid argument to ".__METHOD__ ); |
| 20 | + } |
| 21 | + $this->post = $post; |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Gets the HTML for the form fields, excluding buttons. |
| 26 | + */ |
| 27 | + protected function getFormFieldsHTML() { |
| 28 | + $html = ''; |
| 29 | + |
| 30 | + $html .= $this->getTextbox('lqt-edit-content', $this->post->getText() ); |
| 31 | + $html .= $this->getSignatureEditor( $this->post->getSignature() ); |
| 32 | + $html .= $this->getSummaryBox(); |
| 33 | + |
| 34 | + return $html; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns a textbox used to enter the summary for this change. |
| 39 | + */ |
| 40 | + protected function getSummaryBox() { |
| 41 | + $label = wfMsg( 'summary' ); |
| 42 | + return Xml::inputLabel( $label, 'lqt-summary', |
| 43 | + 'lqt-summary', 60, $subject ) . |
| 44 | + Xml::element( 'br' ); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Submits the form |
| 49 | + */ |
| 50 | + public function submit( $request = null ) { |
| 51 | + $text = $request->getVal('lqt-edit-content'); |
| 52 | + $sig = $request->getVal('lqt-signature'); |
| 53 | + $summary = $request->getVal('lqt-summary'); |
| 54 | + |
| 55 | + $this->post->setText( $text ); |
| 56 | + $this->post->setSignature( $sig ); |
| 57 | + $this->post->save( $summary ); |
| 58 | + |
| 59 | + return true; |
| 60 | + } |
| 61 | + |
| 62 | + public function validate( $request = null ) { |
| 63 | + return true; |
| 64 | + } |
| 65 | +} |
Index: branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php |
— | — | @@ -20,6 +20,7 @@ |
21 | 21 | $requestParams['lqt-subject'] = $params['subject']; |
22 | 22 | $requestParams['lqt-edit-content'] = $params['content']; |
23 | 23 | $requestParams['lqt-signature'] = $params['signature']; |
| 24 | + $requestParams['lqt-summary'] = $params['summary']; |
24 | 25 | |
25 | 26 | $request = new FauxRequest( $requestParams ); |
26 | 27 | |
— | — | @@ -51,6 +52,7 @@ |
52 | 53 | return array( |
53 | 54 | 'new' => 'LiquidThreadsNewTopicForm', |
54 | 55 | 'reply' => 'LiquidThreadsReplyForm', |
| 56 | + 'edit' => 'LiquidThreadsPostEditForm', |
55 | 57 | ); |
56 | 58 | } |
57 | 59 | |
— | — | @@ -97,6 +99,18 @@ |
98 | 100 | } |
99 | 101 | |
100 | 102 | return new LiquidThreadsReplyForm( $wgUser, $topic, $replyPost ); |
| 103 | + } elseif ( $formName == 'edit' ) { |
| 104 | + if ( ! $params['post'] ) { |
| 105 | + $this->dieUsage( 'You must specify a post to edit' ); |
| 106 | + } |
| 107 | + |
| 108 | + try { |
| 109 | + $post = LiquidThreadsPost::newFromID( $params['post'] ); |
| 110 | + } catch ( MWException $e ) { |
| 111 | + $this->dieUsage( "Invalid post", 'invalid-param' ); |
| 112 | + } |
| 113 | + |
| 114 | + return new LiquidThreadsPostEditForm( $wgUser, $post ); |
101 | 115 | } else { |
102 | 116 | $this->dieUsage( "Not yet implemented", 'not-implemented' ); |
103 | 117 | } |
— | — | @@ -115,6 +129,9 @@ |
116 | 130 | // Parameters for reply form |
117 | 131 | 'topic' => NULL, |
118 | 132 | 'reply-post' => NULL, |
| 133 | + |
| 134 | + // Parameters for edit form |
| 135 | + 'post' => NULL, |
119 | 136 | |
120 | 137 | // Submission parameters |
121 | 138 | 'submit' => array( |
— | — | @@ -124,6 +141,7 @@ |
125 | 142 | 'subject' => NULL, |
126 | 143 | 'content' => NULL, |
127 | 144 | 'signature' => NULL, |
| 145 | + 'summary' => NULL, |
128 | 146 | |
129 | 147 | 'token' => NULL, |
130 | 148 | ); |
Index: branches/lqt-updates/extensions/LiquidThreads/lqt.js |
— | — | @@ -132,12 +132,13 @@ |
133 | 133 | e.preventDefault(); |
134 | 134 | |
135 | 135 | // Grab the container. |
136 | | - var parent = $j(this).closest('.lqt-post-wrapper'); |
| 136 | + var parent = $j(this).closest('.lqt-post-tree-wrapper'); |
137 | 137 | |
138 | 138 | var container = $j('<div/>').addClass('lqt-edit-form'); |
139 | 139 | parent.contents().fadeOut(); |
140 | 140 | parent.append(container); |
141 | | - var params = { 'method' : 'edit', 'thread' : parent.data('thread-id') }; |
| 141 | + var postID = liquidThreads.removePrefix( parent.attr('id'), 'lqt-post_' ); |
| 142 | + var params = { 'form' : 'edit', 'post' : postID }; |
142 | 143 | |
143 | 144 | liquidThreads.injectEditForm( params, container ); |
144 | 145 | }, |
— | — | @@ -921,7 +922,7 @@ |
922 | 923 | text = wikiEditorContext.$textarea.textSelection( 'getContents' ); |
923 | 924 | } |
924 | 925 | |
925 | | - var summary = editform.find('#lqt-summary').val(); |
| 926 | + var summary = editform.find('input[name=lqt-summary]').val(); |
926 | 927 | |
927 | 928 | var signature; |
928 | 929 | if ( editform.find('input[name=lqt-signature]').length ) { |
— | — | @@ -935,7 +936,7 @@ |
936 | 937 | summary = ''; |
937 | 938 | } |
938 | 939 | |
939 | | - var subject = editform.find( '#lqt-subject' ).val(); |
| 940 | + var subject = editform.find( 'input[name=lqt-subject]' ).val(); |
940 | 941 | |
941 | 942 | var spinner = $j('<div class="mw-ajax-loader"/>'); |
942 | 943 | editform.prepend(spinner); |
— | — | @@ -957,6 +958,14 @@ |
958 | 959 | liquidThreads.apiRequest( params, function() { |
959 | 960 | window.location.reload(true); |
960 | 961 | } ); |
| 962 | + } else if ( type == 'edit' ) { |
| 963 | + params.summary = summary; |
| 964 | + params.content = text; |
| 965 | + params.signature = signature; |
| 966 | + |
| 967 | + liquidThreads.apiRequest( params, function() { |
| 968 | + window.location.reload(true); |
| 969 | + } ); |
961 | 970 | } |
962 | 971 | }, |
963 | 972 | |