Matthias Mullie has uploaded a new change for review.

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

Change subject: Accept preload & preloadtitle params
......................................................................

Accept preload & preloadtitle params

These are similar to action=edit&section=new params, but with topiclist_
prefix.
Similar to new-section, preload will take the name of a page, of which
the content will be loaded; preloadtitle will just accept the title text.

Change-Id: I0f6d9d3db4f07df6729bb34bf1660a8c3be73a0a
---
M includes/Block/TopicList.php
1 file changed, 31 insertions(+), 1 deletion(-)


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

diff --git a/includes/Block/TopicList.php b/includes/Block/TopicList.php
index 26ebfe9..085f2e7 100644
--- a/includes/Block/TopicList.php
+++ b/includes/Block/TopicList.php
@@ -132,7 +132,6 @@
                        $topicTitle->setChildren( array( $firstPost ) );
                }
 
-
                return array( $topicWorkflow, $topicListEntry, $topicTitle, 
$firstPost );
        }
 
@@ -170,6 +169,8 @@
        }
 
        public function renderApi( array $options ) {
+               $options = $this->preloadTexts( $options );
+
                $response = array(
                        'submitted' => $this->wasSubmitted() ? $this->submitted 
: $options,
                        'errors' => $this->errors,
@@ -233,6 +234,35 @@
                return $response + $serializer->formatApi( $this->workflow, 
$workflows, $found, $page, $this->context );
        }
 
+       /**
+        * Transforms preload params into proper options we can assign to 
template.
+        *
+        * @param array $options
+        * @return array
+        * @throws \MWException
+        */
+       protected function preloadTexts( $options ) {
+               if ( isset( $options['preload'] ) ) {
+                       $title = \Title::newFromText( $options['preload'] );
+                       $page = \WikiPage::factory( $title );
+                       if ( $page->isRedirect() ) {
+                               $title = $page->getRedirectTarget();
+                               $page = \WikiPage::factory( $title );
+                       }
+
+                       if ( $page->exists() ) {
+                               $content = $page->getContent( \Revision::RAW );
+                               $options['content'] = $content->serialize();
+                       }
+               }
+
+               if ( isset( $options['preloadtitle'] ) ) {
+                       $options['topic'] = $options['preloadtitle'];
+               }
+
+               return $options;
+       }
+
        public function getName() {
                return 'topiclist';
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0f6d9d3db4f07df6729bb34bf1660a8c3be73a0a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

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

Reply via email to