EBernhardson has uploaded a new change for review.

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

Change subject: Handle LQT moved thread stubs
......................................................................

Handle LQT moved thread stubs

This is a minimal implementation, rewriting the redirect into
a template so we can output something.   Prior to this patch
parsoid renders the '#REDIRECT ...' into a <link> element and
nothing is displayed.

Change-Id: I5883124f10e43bd6193f3e9d637efe827fc29e7b
---
M autoload.php
M includes/Import/LiquidThreadsApi/Iterators.php
M includes/Import/LiquidThreadsApi/Objects.php
M includes/Import/LiquidThreadsApi/Source.php
4 files changed, 72 insertions(+), 8 deletions(-)


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

diff --git a/autoload.php b/autoload.php
index d58e32d..3479984 100644
--- a/autoload.php
+++ b/autoload.php
@@ -195,6 +195,7 @@
        'Flow\\Import\\LiquidThreadsApi\\ImportSummary' => __DIR__ . 
'/includes/Import/LiquidThreadsApi/Objects.php',
        'Flow\\Import\\LiquidThreadsApi\\ImportTopic' => __DIR__ . 
'/includes/Import/LiquidThreadsApi/Objects.php',
        'Flow\\Import\\LiquidThreadsApi\\LocalApiBackend' => __DIR__ . 
'/includes/Import/LiquidThreadsApi/Source.php',
+       'Flow\\Import\\LiquidThreadsApi\\MovedImportTopic' => __DIR__ . 
'/includes/Import/LiquidThreadsApi/Objects.php',
        'Flow\\Import\\LiquidThreadsApi\\PageRevisionedObject' => __DIR__ . 
'/includes/Import/LiquidThreadsApi/Objects.php',
        'Flow\\Import\\LiquidThreadsApi\\RemoteApiBackend' => __DIR__ . 
'/includes/Import/LiquidThreadsApi/Source.php',
        'Flow\\Import\\LiquidThreadsApi\\ReplyIterator' => __DIR__ . 
'/includes/Import/LiquidThreadsApi/Iterators.php',
diff --git a/includes/Import/LiquidThreadsApi/Iterators.php 
b/includes/Import/LiquidThreadsApi/Iterators.php
index 972e45d..4d3ae74 100644
--- a/includes/Import/LiquidThreadsApi/Iterators.php
+++ b/includes/Import/LiquidThreadsApi/Iterators.php
@@ -19,9 +19,14 @@
        protected $threadData;
 
        /**
-        * @var integer|false|null Id of the current topic, false if no current 
topic, null if unknown.
+        * @var ImportTopic|false|null Obj of the current topic, false if no 
current topic, null if unknown.
         */
        protected $current = false;
+
+       /**
+        * @var int Id of the current topic.
+        */
+       protected $currentId = 0;
 
        /**
         * @var string Name of the remote page the topics exist on
@@ -59,14 +64,14 @@
                if ( $this->current === false ) {
                        return null;
                }
-               return $this->importSource->getTopic( $this->current );
+               return $this->current;
        }
 
        /**
         * @return integer
         */
        public function key() {
-               return $this->current;
+               return $this->currentId;
        }
 
        public function next() {
@@ -80,10 +85,20 @@
                                $topicId = $this->topicIdIterator->current();
                                $this->topicIdIterator->next();
 
-                               if ( $topicId > $lastOffset ) {
-                                       $this->current = $topicId;
-                                       return;
+                               // this topic id has been seen before.
+                               if ( $topicId < $lastOffset ) {
+                                       continue;
                                }
+
+                               // hidden and deleted threads come back as null
+                               $topic = $this->importSource->getTopic( 
$topicId );
+                               if ( $topic === null ) {
+                                       continue;
+                               }
+
+                               $this->currentId = $topicId;
+                               $this->current = $topic;
+                               return;
                        }
                } while( $this->loadMore() );
 
diff --git a/includes/Import/LiquidThreadsApi/Objects.php 
b/includes/Import/LiquidThreadsApi/Objects.php
index ee13033..7cf2766 100644
--- a/includes/Import/LiquidThreadsApi/Objects.php
+++ b/includes/Import/LiquidThreadsApi/Objects.php
@@ -188,6 +188,27 @@
        }
 }
 
+class MovedImportTopic extends ImportTopic {
+       public function getText() {
+               $content = \ContentHandler::makeContent( parent::getText(), 
null, CONTENT_MODEL_WIKITEXT );
+               $target = $content->getRedirectTarget();
+               if ( !$target ) {
+                       throw new ImportException( '...' );
+               }
+
+               // To get the new talk page that this belongs to we would need 
to query the api
+               // for the new topic, for now not bothering.
+               $template = wfMessage( 'flow-importer-lqt-moved-thread' 
)->inContentLanguage()->plain();
+               $arguments = implode( '|', array(
+                       'author=' . parent::getAuthor(),
+                       'date=' . MWTimestamp::getInstance( 
$this->apiResponse['created'] )->timestamp->format( 'Y-m-d' ),
+                       'title=' . $target->getPrefixedText(),
+               ) );
+
+               return "{{{$template}|$arguments}}";
+       }
+}
+
 class ImportSummary extends PageRevisionedObject implements IImportSummary {
        /** @var ImportSource **/
        protected $source;
diff --git a/includes/Import/LiquidThreadsApi/Source.php 
b/includes/Import/LiquidThreadsApi/Source.php
index b8cab8c..d1706b5 100644
--- a/includes/Import/LiquidThreadsApi/Source.php
+++ b/includes/Import/LiquidThreadsApi/Source.php
@@ -20,6 +20,12 @@
 use User;
 
 class ImportSource implements IImportSource {
+       // Thread types defined by LQT which are returned via api
+       const THREAD_TYPE_NORMAL = 0;
+       const THREAD_TYPE_MOVED = 1;
+       const THREAD_TYPE_DELETED = 2;
+       const THREAD_TYPE_HIDDEN = 4;
+
        /**
         * @var ApiBackend
         */
@@ -70,10 +76,31 @@
 
        /**
         * @param integer $id
-        * @return ImportTopic
+        * @return ImportTopic|null
         */
        public function getTopic( $id ) {
-               return new ImportTopic( $this, $this->threadData->get( $id ) );
+               $data = $this->threadData->get( $id );
+               switch ( $data['type'] ) {
+               // Standard thread
+               case self::THREAD_TYPE_NORMAL:
+                       return new ImportTopic( $this, $data );
+
+               // The topic no longer exists at the queried location, but
+               // a stub was left behind pointing to it. This modified
+               // version of ImportTopic gracefully adjusts the #REDIRECT
+               // into a template to keep a similar output to lqt.
+               case self::THREAD_TYPE_MOVED:
+                       return new MovedImportTopic( $this, $data );
+
+               // To get these back from the api we would have to send the 
`showdeleted`
+               // query param.  As we are not requesting them, just ignore for 
now.
+               case self::THREAD_TYPE_DELETED:
+                       return null;
+
+               // Was assigned but never used by LQT.
+               case self::THREAD_TYPE_HIDDEN:
+                       return null;
+               }
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5883124f10e43bd6193f3e9d637efe827fc29e7b
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

Reply via email to