r96326 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96325‎ | r96326 | r96327 >
Date:13:14, 6 September 2011
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads 3.0: Implement editing of posts
Modified paths:
  • /branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/api/ApiLqtForm.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php (modified) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/classes/view/PostEditForm.php (added) (history)
  • /branches/lqt-updates/extensions/LiquidThreads/lqt.js (modified) (history)

Diff [purge]

Index: branches/lqt-updates/extensions/LiquidThreads/LiquidThreads.php
@@ -275,6 +275,7 @@
276276 $wgAutoloadClasses['LiquidThreadsEditForm'] = "$dir/classes/view/EditForm.php";
277277 $wgAutoloadClasses['LiquidThreadsNewTopicForm'] = "$dir/classes/view/NewTopicForm.php";
278278 $wgAutoloadClasses['LiquidThreadsReplyForm'] = "$dir/classes/view/ReplyForm.php";
 279+$wgAutoloadClasses['LiquidThreadsPostEditForm'] = "$dir/classes/view/PostEditForm.php";
279280
280281 // Views
281282 $wgAutoloadClasses['LiquidThreadsChannelView'] = "$dir/classes/view/ChannelView.php";
Index: branches/lqt-updates/extensions/LiquidThreads/classes/model/PostVersion.php
@@ -322,6 +322,7 @@
323323 $this->topicID = $baseVersion->getTopicID();
324324 $this->parentID = $baseVersion->getParentID();
325325 $this->signature = $baseVersion->getSignature();
 326+ $this->postTime = $baseVersion->getPostTime();
326327
327328 global $wgUser;
328329 $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 @@
2121 $requestParams['lqt-subject'] = $params['subject'];
2222 $requestParams['lqt-edit-content'] = $params['content'];
2323 $requestParams['lqt-signature'] = $params['signature'];
 24+ $requestParams['lqt-summary'] = $params['summary'];
2425
2526 $request = new FauxRequest( $requestParams );
2627
@@ -51,6 +52,7 @@
5253 return array(
5354 'new' => 'LiquidThreadsNewTopicForm',
5455 'reply' => 'LiquidThreadsReplyForm',
 56+ 'edit' => 'LiquidThreadsPostEditForm',
5557 );
5658 }
5759
@@ -97,6 +99,18 @@
98100 }
99101
100102 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 );
101115 } else {
102116 $this->dieUsage( "Not yet implemented", 'not-implemented' );
103117 }
@@ -115,6 +129,9 @@
116130 // Parameters for reply form
117131 'topic' => NULL,
118132 'reply-post' => NULL,
 133+
 134+ // Parameters for edit form
 135+ 'post' => NULL,
119136
120137 // Submission parameters
121138 'submit' => array(
@@ -124,6 +141,7 @@
125142 'subject' => NULL,
126143 'content' => NULL,
127144 'signature' => NULL,
 145+ 'summary' => NULL,
128146
129147 'token' => NULL,
130148 );
Index: branches/lqt-updates/extensions/LiquidThreads/lqt.js
@@ -132,12 +132,13 @@
133133 e.preventDefault();
134134
135135 // Grab the container.
136 - var parent = $j(this).closest('.lqt-post-wrapper');
 136+ var parent = $j(this).closest('.lqt-post-tree-wrapper');
137137
138138 var container = $j('<div/>').addClass('lqt-edit-form');
139139 parent.contents().fadeOut();
140140 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 };
142143
143144 liquidThreads.injectEditForm( params, container );
144145 },
@@ -921,7 +922,7 @@
922923 text = wikiEditorContext.$textarea.textSelection( 'getContents' );
923924 }
924925
925 - var summary = editform.find('#lqt-summary').val();
 926+ var summary = editform.find('input[name=lqt-summary]').val();
926927
927928 var signature;
928929 if ( editform.find('input[name=lqt-signature]').length ) {
@@ -935,7 +936,7 @@
936937 summary = '';
937938 }
938939
939 - var subject = editform.find( '#lqt-subject' ).val();
 940+ var subject = editform.find( 'input[name=lqt-subject]' ).val();
940941
941942 var spinner = $j('<div class="mw-ajax-loader"/>');
942943 editform.prepend(spinner);
@@ -957,6 +958,14 @@
958959 liquidThreads.apiRequest( params, function() {
959960 window.location.reload(true);
960961 } );
 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+ } );
961970 }
962971 },
963972

Status & tagging log