EBernhardson (WMF) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/79023


Change subject: Permalink to Comment
......................................................................

Permalink to Comment

Allows very basic permalink directly to comment by its postId

Change-Id: Ib55b8961a675c2398f9353c1bf44ca0906c6454a
---
M includes/Block/Topic.php
M templates/topic.html.php
2 files changed, 35 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/23/79023/1

diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 7b5dcdc..fd9500a 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -245,10 +245,29 @@
 
                $templating->getOutput()->addModules( 'ext.flow.base' );
 
+               $root = $this->loadRootPost();
+               if ( isset( $options['postId'] ) ) {
+                       $stack = array( $root );
+                       $found = false;
+                       while( $stack ) {
+                               $post = array_pop( $stack );
+                               if ( $post->getPostId()->getHex() === 
$options['postId'] ) {
+                                       $found = true;
+                                       break;
+                               }
+                               foreach ( $post->getChildren() as $child ) {
+                                       $stack[] = $child;
+                               }
+                       }
+                       if ( $found === false ) {
+                               throw new \Exception( 'Requested postId is not 
available within post tree' );
+                       }
+                       $root = $post;
+               }
                return $templating->render( "flow:topic.html.php", array(
                        'block' => $this,
                        'topic' => $this->workflow,
-                       'root' => $this->loadRootPost(),
+                       'root' => $root,
                        'user' => $this->user,
                ), $return );
        }
@@ -417,7 +436,7 @@
 
        // The prefix used for form data
        public function getName() {
-               return 'topic_list';
+               return 'topic';
        }
 
 }
diff --git a/templates/topic.html.php b/templates/topic.html.php
index 2ae7044..d659a55 100644
--- a/templates/topic.html.php
+++ b/templates/topic.html.php
@@ -11,7 +11,7 @@
        // also, CSRF?
        echo '<li>' . Html::openElement( 'form', array(
                'method' => 'POST',
-               'action' => $self->generateUrl( $root->getPostId(), $action )
+               'action' => $self->generateUrl( $block->getWorkflowId(), 
$action )
        ) );
        echo Html::element( 'input', array( 'type' => 'hidden', 'name' => 
'wpEditToken', 'value' => $editToken) );
        foreach ( $data as $name => $value ) {
@@ -36,7 +36,7 @@
                        . '<ul>';
                $postAction( 'restore-post', array( 'postId' => 
$post->getPostId()->getHex() ) );
                echo '<li>' . Html::element( 'a', array(
-                       'href' => $self->generateUrl( $root->getPostId(), 
'post-history', array(
+                       'href' => $self->generateUrl( $block->getWorkflowId(), 
'post-history', array(
                                $block->getName() . '[postId]' => 
$post->getPostId()->getHex(),
                        ) ),
                ), wfMessage( 'flow-post-action-history' )->plain() ) . '</li>';
@@ -49,7 +49,7 @@
                        . '<ul>';
                $postAction( 'delete-post', array( 'postId' => 
$post->getPostId()->getHex() ) );
                echo '<li>' . Html::element( 'a', array(
-                       'href' => $self->generateUrl( $root->getPostId(), 
'post-history', array(
+                       'href' => $self->generateUrl( $block->getWorkflowId(), 
'post-history', array(
                                $block->getName() . '[postId]' => 
$post->getPostId()->getHex(),
                        ) ),
                ), wfMessage( 'flow-post-action-history' )->plain() ) . '<li>';
@@ -57,7 +57,7 @@
                        . Html::openElement( 'form', array(
                                'method' => 'POST',
                                // root post id is same as topic workflow id
-                               'action' => $self->generateUrl( 
$root->getPostId(), 'reply' ),
+                               'action' => $self->generateUrl( 
$block->getWorkflowId(), 'reply' ),
                        ) );
                        echo Html::element( 'input', array( 'type' => 'hidden', 
'name' => 'wpEditToken', 'value' => $editToken) );
                if ( $block->getHexRepliedTo() === $post->getPostId()->getHex() 
) {
@@ -83,11 +83,15 @@
        echo '</div>';
 };
 
-echo Html::element( 'h4', array(), $root->getContent() ),
-       Html::rawElement( 'a', array(
-               'href' => $this->generateUrl( $root->getPostId(), 'edit-title' )
-       ), wfMessage( 'flow-action-edit-title' ) );
+if ( $root->isTopicTitle() ) {
+       echo Html::element( 'h4', array(), $root->getContent() ),
+               Html::rawElement( 'a', array(
+                       'href' => $this->generateUrl( $block->getWorkflowId(), 
'edit-title' )
+               ), wfMessage( 'flow-action-edit-title' ) );
 
-foreach( $root->getChildren() as $child ) {
-       $renderPost( $child );
+       foreach( $root->getChildren() as $child ) {
+               $renderPost( $child );
+       }
+} else {
+       $renderPost( $root );
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/79023
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib55b8961a675c2398f9353c1bf44ca0906c6454a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson (WMF) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to