EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92454
Change subject: Post topic without comment
......................................................................
Post topic without comment
Allows creation of new topic without creating a related first post
Change-Id: I6b37cb130bff14d94303f545d38fe1676776ff02
---
M includes/Block/Topic.php
M includes/Block/TopicList.php
M includes/Notifications/Controller.php
M modules/discussion/forms.js
4 files changed, 25 insertions(+), 24 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/54/92454/1
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index f4ea2db..10d5043 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -144,7 +144,7 @@
$this->errors['replyTo'] = wfMessage(
'flow-error-invalid-replyto' );
} elseif ( !$this->permissions->isAllowed( $post,
'reply' ) ) {
// Or should the check be rolled into the
!$post condition?
- $this->errors['permissions'] = wfMessage(
'flow-error-not-allowed' );
+ $this->errors['permissions'] = wfMessage( 'wtf'
); //wfMessage( 'flow-error-not-allowed' );
} else {
// TODO: assert post belongs to this tree?
Does it really matter?
// answer: might not belong, and probably does
matter due to inter-wiki interaction
diff --git a/includes/Block/TopicList.php b/includes/Block/TopicList.php
index c9bffa1..7e8ed3d 100644
--- a/includes/Block/TopicList.php
+++ b/includes/Block/TopicList.php
@@ -34,9 +34,6 @@
if ( !isset( $this->submitted['topic'] ) ) {
$this->errors['topic'] = wfMessage(
'flow-error-missing-title' );
}
- if ( !isset( $this->submitted['content'] ) ) {
- $this->errors['content'] = wfMessage(
'flow-error-missing-content' );
- }
}
public function commit() {
@@ -56,14 +53,21 @@
// Should we really have a top level post for the topic title?
Simplifies allowing
// a revisioned title.
$topicPost = PostRevision::create( $topicWorkflow,
$this->submitted['topic'] );
- $firstPost = $topicPost->reply( $this->user,
$this->submitted['content'] );
+ $topicChildren = array();
+ $firstPost = null;
+ if ( !empty( $this->submitted['content'] ) ) {
+ $firstPost = $topicPost->reply( $this->user,
$this->submitted['content'] );
+ $firstPost->setChildren( array() );
+ $topicChildren[] = $firstPost;
+ }
$topicListEntry = TopicListEntry::create( $this->workflow,
$topicWorkflow );
- $topicPost->setChildren( array( $firstPost ) );
- $firstPost->setChildren( array() );
+ $topicPost->setChildren( $topicChildren );
$storage->put( $topicWorkflow );
$storage->put( $topicPost );
- $storage->put( $firstPost );
+ if ( $firstPost !== null ) {
+ $storage->put( $firstPost );
+ }
$storage->put( $topicListEntry );
$this->notificationController->notifyNewTopic( array(
@@ -78,7 +82,7 @@
$notificationController = $this->notificationController;
$output = array(
'created-topic-id' => $topicWorkflow->getId(),
- 'created-post-id' => $firstPost->getRevisionId(),
+ 'created-post-id' => $firstPost ?
$firstPost->getRevisionId() : null,
'render-function' => function( $templating )
use ( $topicWorkflow, $firstPost,
$topicPost, $storage, $user, $notificationController )
{
diff --git a/includes/Notifications/Controller.php
b/includes/Notifications/Controller.php
index 8abc2e5..7ca9da0 100644
--- a/includes/Notifications/Controller.php
+++ b/includes/Notifications/Controller.php
@@ -125,7 +125,7 @@
* * topic-workflow: Workflow object for the new Topic.
* * title-post: PostRevision object for the "topic post", containing
the
* title.
- * * first-post: PostRevision object for the first post.
+ * * first-post: PostRevision object for the first post, or null when
no first post.
* * user: The User who created the topic.
* @return array Array of created EchoEvent objects.
*/
@@ -148,9 +148,9 @@
'extra' => array(
'board-workflow' => $boardWorkflow->getId(),
'topic-workflow' => $topicWorkflow->getId(),
- 'post-id' => $firstPost->getRevisionId(),
+ 'post-id' => $firstPost ?
$firstPost->getRevisionId() : null,
'topic-title' => $topicPost->getContentRaw(),
- 'content' => $firstPost->getContent(),
+ 'content' => $firstPost ?
$firstPost->getContent() : null,
)
) );
@@ -185,16 +185,16 @@
$topicWorkflow = $data['topic-workflow'];
$events = array();
- $mentionedUsers = $this->getMentionedUsers( $newRevision,
$title );
+ $mentionedUsers = $newRevision ? $this->getMentionedUsers(
$newRevision, $title ) : array();
if ( count( $mentionedUsers ) ) {
$events[] = EchoEvent::create( array(
'type' => 'flow-mention',
'title' => $title,
'extra' => array(
- 'content' => $newRevision->getContent(),
+ 'content' => $newRevision ?
$newRevision->getContent() : null,
'topic-title' => $data['topic-title'],
- 'post-id' => $newRevision->getPostId(),
+ 'post-id' => $newRevision ?
$newRevision->getPostId() : null,
'mentioned-users' => $mentionedUsers,
'topic-workflow' =>
$topicWorkflow->getId(),
),
@@ -377,7 +377,7 @@
protected static function getCreatorsFromPostIDs( array $posts ) {
$users = array();
$container = Container::getContainer();
-
+
foreach ( $posts as $postId ) {
$post = $container['storage']->find(
'PostRevision',
@@ -403,5 +403,5 @@
}
return $users;
- }
-}
\ No newline at end of file
+ }
+}
diff --git a/modules/discussion/forms.js b/modules/discussion/forms.js
index 2ee3544..50b0da4 100644
--- a/modules/discussion/forms.js
+++ b/modules/discussion/forms.js
@@ -7,15 +7,12 @@
);
$( 'form.flow-newtopic-form' ).flow( 'setupEmptyDisabler',
- [
- '.flow-newtopic-title',
- '.flow-newtopic-content'
- ],
+ [ '.flow-newtopic-title' ],
'.flow-newtopic-submit'
);
$container.find( 'form.flow-topic-reply-form' ).flow(
'setupEmptyDisabler',
- ['.flow-topic-reply-content'],
+ [ '.flow-topic-reply-content' ],
'.flow-topic-reply-submit'
);
@@ -32,7 +29,7 @@
return [ workflowParam, title, content ];
},
function ( workflowParam, title, content ) {
- return title && content;
+ return !!title;
},
function ( promise ) {
promise
--
To view, visit https://gerrit.wikimedia.org/r/92454
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b37cb130bff14d94303f545d38fe1676776ff02
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits