jenkins-bot has submitted this change and it was merged.
Change subject: Handle LQT moved thread stubs
......................................................................
Handle LQT moved thread stubs
These stubs contain only a redirect as the first reply and
are programatically generated by LQT when moving the thread.
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 i18n/en.json
M i18n/qqq.json
M includes/Import/LiquidThreadsApi/Iterators.php
M includes/Import/LiquidThreadsApi/Objects.php
M includes/Import/LiquidThreadsApi/Source.php
6 files changed, 112 insertions(+), 9 deletions(-)
Approvals:
Mattflaschen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/autoload.php b/autoload.php
index 64cae3e..96a302a 100644
--- a/autoload.php
+++ b/autoload.php
@@ -196,6 +196,9 @@
'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\\MovedImportPost' => __DIR__ .
'/includes/Import/LiquidThreadsApi/Objects.php',
+ 'Flow\\Import\\LiquidThreadsApi\\MovedImportRevision' => __DIR__ .
'/includes/Import/LiquidThreadsApi/Objects.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/i18n/en.json b/i18n/en.json
index b3938d9..89e4c53 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -382,6 +382,7 @@
"flow-topic-undo-hide": "undo hide",
"flow-topic-undo-delete": "undo delete",
"flow-topic-undo-suppress": "undo suppress",
+ "flow-importer-lqt-moved-thread-template": "LQT Moved thread stub
converted to Flow",
"flow-importer-lqt-converted-template": "LQT page converted to Flow",
"flow-importer-lqt-converted-archive-template": "Archive for converted
LQT page",
"flow-importer-wt-converted-template": "Wikitext talk page converted to
Flow",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 33904b8..6353546 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -387,6 +387,7 @@
"flow-topic-undo-hide": "Automatic moderation summary when undoing a
topic hide that was just performed.",
"flow-topic-undo-delete": "Automatic moderation summary when undoing a
topic deletion that was just performed.",
"flow-topic-undo-suppress": "Automatic moderation summary when undoing
a topic suppression that was just performed.",
+ "flow-importer-lqt-moved-thread-template": "Name of a wikitext template
that is used as the content of LQT moved thread stubs when they are imported to
Flow.",
"flow-importer-lqt-converted-template": "Name of a wikitext template
that is added to the header of Flow boards that were converted from
LiquidThreads",
"flow-importer-lqt-converted-archive-template": "Name of a wikitext
template that is added to the archived copy of a LiquidThreads page converted
to Flow.",
"flow-importer-wt-converted-template": "Name of a wikitext template
that is added to the header of a Flow boards that were converted from Wikitext",
diff --git a/includes/Import/LiquidThreadsApi/Iterators.php
b/includes/Import/LiquidThreadsApi/Iterators.php
index 44fc1eb..e86a8b5 100644
--- a/includes/Import/LiquidThreadsApi/Iterators.php
+++ b/includes/Import/LiquidThreadsApi/Iterators.php
@@ -18,9 +18,14 @@
protected $threadData;
/**
- * @var integer|false|null Id of the current topic, false if no current
topic, null if unknown.
+ * @var integer|false|null Lqt id of the current topic, false if no
current topic, null if unknown.
*/
protected $current = false;
+
+ /**
+ * @var ImportTopic The current topic.
+ */
+ protected $currentTopic = null;
/**
* @var string Name of the remote page the topics exist on
@@ -58,7 +63,7 @@
if ( $this->current === false ) {
return null;
}
- return $this->importSource->getTopic( $this->current );
+ return $this->currentTopic;
}
/**
@@ -79,10 +84,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->current = $topicId;
+ $this->currentTopic = $topic;
+ return;
}
} while( $this->loadMore() );
@@ -195,10 +210,13 @@
/** @var IImportObject **/
protected $parent;
- public function __construct( array $pageData, IImportObject $parent ) {
+ public function __construct( array $pageData, IImportObject $parent,
$factory = null ) {
$this->pageData = $pageData;
$this->pointer = 0;
$this->parent = $parent;
+ $this->factory = $factory ?: function( $data, $parent ) {
+ return new ImportRevision( $data, $parent );
+ };
}
protected function getRevisionCount() {
@@ -226,6 +244,10 @@
}
public function current() {
- return new ImportRevision(
$this->pageData['revisions'][$this->pointer], $this->parent );
+ return call_user_func(
+ $this->factory,
+ $this->pageData['revisions'][$this->pointer],
+ $this->parent
+ );
}
}
diff --git a/includes/Import/LiquidThreadsApi/Objects.php
b/includes/Import/LiquidThreadsApi/Objects.php
index ee13033..7fb0896 100644
--- a/includes/Import/LiquidThreadsApi/Objects.php
+++ b/includes/Import/LiquidThreadsApi/Objects.php
@@ -252,6 +252,55 @@
}
}
+// The Moved* series of topics handle the LQT move stubs. They need to
+// have their revision content rewriten from #REDIRECT to a template that
+// has visible output like lqt generated per-request.
+class MovedImportTopic extends ImportTopic {
+ public function getReplies() {
+ $topPost = new MovedImportPost( $this->importSource,
$this->apiResponse );
+ return new ArrayIterator( array( $topPost ) );
+ }
+}
+
+class MovedImportPost extends ImportPost {
+ public function getRevisions() {
+ $factory = function( $data, $parent ) {
+ return new MovedImportRevision( $data, $parent );
+ };
+ $pageData = $this->importSource->getPageData( $this->pageId );
+ return new RevisionIterator( $pageData, $this, $factory );
+ }
+}
+
+class MovedImportRevision extends ImportRevision {
+ /**
+ * Rewrites the '#REDIRECT [[...]]' of an autogenerated lqt moved
+ * thread stub into a template. While we don't re-write the link
+ * here, after importing the referenced thread LqtRedirector will
+ * make that Thread page a redirect to the Flow topic, essentially
+ * making these links still work.
+ */
+ public function getText() {
+ $text = parent::getText();
+ $content = \ContentHandler::makeContent( $text, null,
CONTENT_MODEL_WIKITEXT );
+ $target = $content->getRedirectTarget();
+ if ( !$target ) {
+ throw new ImportException( "Could not detect redirect
within: $text" );
+ }
+
+ // 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-template' )->inContentLanguage()->plain();
+ $arguments = implode( '|', array(
+ 'author=' . parent::getAuthor(),
+ 'date=' . MWTimestamp::getInstance(
$this->apiResponse['timestamp'] )->timestamp->format( 'Y-m-d' ),
+ 'title=' . $target->getPrefixedText(),
+ ) );
+
+ return "{{{$template}|$arguments}}";
+ }
+}
+
// Represents a revision the script makes on its own behalf, using a script
user
class ScriptedImportRevision implements IObjectRevision {
/** @var IImportObject **/
diff --git a/includes/Import/LiquidThreadsApi/Source.php
b/includes/Import/LiquidThreadsApi/Source.php
index 89cbc2f..9febcf6 100644
--- a/includes/Import/LiquidThreadsApi/Source.php
+++ b/includes/Import/LiquidThreadsApi/Source.php
@@ -19,6 +19,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
*/
@@ -69,10 +75,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: merged
Gerrit-Change-Id: I5883124f10e43bd6193f3e9d637efe827fc29e7b
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits