jenkins-bot has submitted this change and it was merged.
Change subject: Record topic imports to Special:Log
......................................................................
Record topic imports to Special:Log
Bug: T87795
Change-Id: I0ce69cca9ab017fc0b9357a65245defd98c71f0f
---
M Flow.php
M autoload.php
M container.php
M i18n/en.json
M i18n/qqq.json
M includes/Import/ImportSource.php
M includes/Import/LiquidThreadsApi/Objects.php
A includes/Import/Postprocessor/SpecialLogTopic.php
R includes/Log/ActionFormatter.php
A includes/Log/LqtImportFormatter.php
M tests/phpunit/Mock/MockImportTopic.php
11 files changed, 161 insertions(+), 9 deletions(-)
Approvals:
Mattflaschen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Flow.php b/Flow.php
index f136b9e..b64bb54 100644
--- a/Flow.php
+++ b/Flow.php
@@ -240,15 +240,16 @@
// Some actions are more complex closures - to be added
manually.
if ( is_string( $log ) ) {
- $wgLogActionsHandlers["$log/flow-$action"] =
'Flow\Log\Formatter';
+ $wgLogActionsHandlers["$log/flow-$action"] =
'Flow\Log\ActionFormatter';
}
}
}
-// Manually add the more complex actions
-$wgLogActionsHandlers['delete/flow-restore-post'] = 'Flow\Log\Formatter';
-$wgLogActionsHandlers['suppress/flow-restore-post'] = 'Flow\Log\Formatter';
-$wgLogActionsHandlers['delete/flow-restore-topic'] = 'Flow\Log\Formatter';
-$wgLogActionsHandlers['suppress/flow-restore-topic'] = 'Flow\Log\Formatter';
+// Manually add that more complex actions
+$wgLogActionsHandlers['delete/flow-restore-post'] = 'Flow\Log\ActionFormatter';
+$wgLogActionsHandlers['suppress/flow-restore-post'] =
'Flow\Log\ActionFormatter';
+$wgLogActionsHandlers['delete/flow-restore-topic'] =
'Flow\Log\ActionFormatter';
+$wgLogActionsHandlers['suppress/flow-restore-topic'] =
'Flow\Log\ActionFormatter';
+$wgLogActionsHandlers['import/lqt-to-flow-topic'] =
'Flow\Log\LqtImportFormatter';
// Register URL actions
foreach( $wgFlowActions as $action => $options ) {
diff --git a/autoload.php b/autoload.php
index d947a65..5b0f6e1 100644
--- a/autoload.php
+++ b/autoload.php
@@ -214,13 +214,15 @@
'Flow\\Import\\Postprocessor\\PostprocessingException' => __DIR__ .
'/includes/Import/Postprocessor/PostprocessingException.php',
'Flow\\Import\\Postprocessor\\Postprocessor' => __DIR__ .
'/includes/Import/Postprocessor/Postprocessor.php',
'Flow\\Import\\Postprocessor\\ProcessorGroup' => __DIR__ .
'/includes/Import/Postprocessor/ProcessorGroup.php',
+ 'Flow\\Import\\Postprocessor\\SpecialLogTopic' => __DIR__ .
'/includes/Import/Postprocessor/SpecialLogTopic.php',
'Flow\\Import\\TalkpageImportOperation' => __DIR__ .
'/includes/Import/Importer.php',
'Flow\\Import\\TopicImportState' => __DIR__ .
'/includes/Import/Importer.php',
'Flow\\Import\\Wikitext\\ConversionStrategy' => __DIR__ .
'/includes/Import/Wikitext/ConversionStrategy.php',
'Flow\\Import\\Wikitext\\ImportSource' => __DIR__ .
'/includes/Import/Wikitext/ImportSource.php',
'Flow\\LinksTableUpdater' => __DIR__ .
'/includes/LinksTableUpdater.php',
- 'Flow\\Log\\Formatter' => __DIR__ . '/includes/Log/Formatter.php',
+ 'Flow\\Log\\ActionFormatter' => __DIR__ .
'/includes/Log/ActionFormatter.php',
'Flow\\Log\\Logger' => __DIR__ . '/includes/Log/Logger.php',
+ 'Flow\\Log\\LqtImportFormatter' => __DIR__ .
'/includes/Log/LqtImportFormatter.php',
'Flow\\Log\\PostModerationLogger' => __DIR__ .
'/includes/Log/PostModerationLogger.php',
'Flow\\Model\\AbstractRevision' => __DIR__ .
'/includes/Model/AbstractRevision.php',
'Flow\\Model\\AbstractSummary' => __DIR__ .
'/includes/Model/AbstractSummary.php',
diff --git a/container.php b/container.php
index 4b8d8ac..07d20bd 100644
--- a/container.php
+++ b/container.php
@@ -1130,13 +1130,19 @@
} );
$c['importer'] = $c->share( function( $c ) {
- return new Flow\Import\Importer(
+ $importer = new Flow\Import\Importer(
$c['storage'],
$c['factory.loader.workflow'],
$c['memcache.buffered'],
$c['db.factory'],
$c['deferred_queue']
);
+
+ $importer->addPostprocessor( new
Flow\Import\Postprocessor\SpecialLogTopic(
+ $c['occupation_controller']->getTalkpageManager()
+ ) );
+
+ return $importer;
} );
return $c;
diff --git a/i18n/en.json b/i18n/en.json
index 89e4c53..cf4183a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -21,6 +21,7 @@
"logentry-delete-flow-restore-topic": "$1 {{GENDER:$2|restored}} a [$4
topic] on [[$3]]",
"logentry-suppress-flow-suppress-topic": "$1 {{GENDER:$2|suppressed}} a
[$4 topic] on [[$3]]",
"logentry-suppress-flow-restore-topic": "$1 {{GENDER:$2|deleted}} a [$4
topic] on [[$3]]",
+ "logentry-import-lqt-to-flow-topic": "[[$1|$2]] on [[$3]] was imported
from LiquidThreads to Flow",
"flow-user-moderated": "Moderated user",
"flow-board-header-browse-topics-link": "Browse topics",
"flow-edit-header-link": "Edit header",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 6353546..55f9d10 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -26,6 +26,7 @@
"logentry-delete-flow-restore-topic": "Text for a deletion log entry
when a deleted topic was restored. Parameters:\n* $1 - the user: link to the
user page\n* $2 - the username. Can be used for GENDER.\n* $3 - the page where
the topic was moderated\n* $4 - permalink URL to the moderated
topic\n{{Related|Flow-logentry}}",
"logentry-suppress-flow-suppress-topic": "Text for a deletion log entry
when a topic was suppressed. Parameters:\n* $1 - the user: link to the user
page\n* $2 - the username. Can be used for GENDER.\n* $3 - the page where the
topic was moderated\n* $4 - permalink URL to the moderated
topic\n{{Related|Flow-logentry}}",
"logentry-suppress-flow-restore-topic": "Text for a deletion log entry
when a suppressed topic was restored. Parameters:\n* $1 - the user: link to the
user page\n* $2 - the username. Can be used for GENDER.\n* $3 - the page where
the topic was moderated\n* $4 - permalink URL to the moderated
topic\n{{Related|Flow-logentry}}",
+ "logentry-import-lqt-to-flow-topic": "Text for an import log entry when
a topic has been imported from LiquidThreads to Flow. Parameters:\n* $1 - The
article within the topic namespace the topic was imported to\n* $2 - The title
of the thread being imported.\n* $3 - The board that was converted from
LiquidThreads to Flow.",
"flow-user-moderated": "Name to display when the current user is not
allowed to see the users name due to moderation",
"flow-board-header-browse-topics-link": "Text to show in the board
header which links to the topics list.",
"flow-edit-header-link": "Used as text for the button that either
allows editing the header in place or brings the user to a page for editing the
header.",
diff --git a/includes/Import/ImportSource.php b/includes/Import/ImportSource.php
index cb0316b..c73bd62 100644
--- a/includes/Import/ImportSource.php
+++ b/includes/Import/ImportSource.php
@@ -62,6 +62,18 @@
* @return IImportSummary|null The summary, if any, for a topic
*/
function getTopicSummary();
+
+ /**
+ * @return string The subtype to use when logging topic imports
+ * to Special:Log. It will appear in the log as "import/$logType"
+ */
+ function getLogType();
+
+ /**
+ * @return string[string] A k/v map of strings containing additional
+ * parameters to be stored with the log about importing this topic.
+ */
+ function getLogParameters();
}
interface IImportHeader extends IRevisionableObject {
diff --git a/includes/Import/LiquidThreadsApi/Objects.php
b/includes/Import/LiquidThreadsApi/Objects.php
index 7fb0896..b198e2e 100644
--- a/includes/Import/LiquidThreadsApi/Objects.php
+++ b/includes/Import/LiquidThreadsApi/Objects.php
@@ -186,6 +186,18 @@
public function getObjectKey() {
return 'topic' . $this->importSource->getObjectKey(
'thread_id', $this->apiResponse['id'] );
}
+
+ public function getLogType() {
+ return "lqt-to-flow-topic";
+ }
+
+ public function getLogParameters() {
+ return array(
+ 'lqt_thread_id' => $this->apiResponse['id'],
+ 'lqt_orig_title' =>
$this->getTitle()->getPrefixedText(),
+ 'lqt_subject' => $this->getText(),
+ );
+ }
}
class ImportSummary extends PageRevisionedObject implements IImportSummary {
diff --git a/includes/Import/Postprocessor/SpecialLogTopic.php
b/includes/Import/Postprocessor/SpecialLogTopic.php
new file mode 100644
index 0000000..36167fc
--- /dev/null
+++ b/includes/Import/Postprocessor/SpecialLogTopic.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Flow\Import\Postprocessor;
+
+use Flow\Import\IImportHeader;
+use Flow\Import\IImportPost;
+use Flow\Import\IImportTopic;
+use Flow\Import\PageImportState;
+use Flow\Import\TopicImportState;
+use Flow\Model\UUID;
+use ManualLogEntry;
+use User;
+
+/**
+ * Records topic imports to Special:Log.
+ */
+class SpecialLogTopic implements PostProcessor {
+ /**
+ * @var bool Indicates if new posts have been seen since the last
commit operation
+ */
+ protected $newPosts = false;
+
+ /**
+ * @var User The user to attribute logs to
+ */
+ protected $user;
+
+ public function __construct( User $user ) {
+ $this->user = $user;
+ }
+
+ public function afterHeaderImported( PageImportState $state,
IImportHeader $topic ) {
+ // nothing to do
+ }
+
+ public function afterPostImported( TopicImportState $state, IImportPost
$post, UUID $newPostId ) {
+ $this->newPosts = true;
+ }
+
+ public function afterTopicImported( TopicImportState $state,
IImportTopic $topic ) {
+ if ( !$this->newPosts ) {
+ return;
+ }
+ $logEntry = new ManualLogEntry( 'import', $topic->getLogType()
);
+ $logEntry->setTarget( $state->topicWorkflow->getOwnerTitle() );
+ $logEntry->setPerformer( $this->user );
+ $logEntry->setParameters( array(
+ 'topic' =>
$state->topicWorkflow->getArticleTitle()->getPrefixedText(),
+ ) + $topic->getLogParameters() );
+ $logEntry->insert();
+
+ $this->newPosts = false;
+ }
+
+ public function importAborted() {
+ $this->newPosts = false;
+ }
+}
diff --git a/includes/Log/Formatter.php b/includes/Log/ActionFormatter.php
similarity index 98%
rename from includes/Log/Formatter.php
rename to includes/Log/ActionFormatter.php
index b4e8461..b56bb17 100644
--- a/includes/Log/Formatter.php
+++ b/includes/Log/ActionFormatter.php
@@ -6,7 +6,7 @@
use Flow\Parsoid\Utils;
use Message;
-class Formatter extends \LogFormatter {
+class ActionFormatter extends \LogFormatter {
/**
* Formats an activity log entry.
*
diff --git a/includes/Log/LqtImportFormatter.php
b/includes/Log/LqtImportFormatter.php
new file mode 100644
index 0000000..3ef5b52
--- /dev/null
+++ b/includes/Log/LqtImportFormatter.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Flow\Log;
+
+use Message;
+use Title;
+
+class LqtImportFormatter extends \LogFormatter {
+
+ public function getPreloadTitles() {
+ $titles = array( $this->entry->getTarget() );
+ $params = $this->entry->getParameters() + array(
+ 'topic' => '',
+ );
+ $topic = Title::newFromText( $params['topic'] );
+ if ( $topic ) {
+ $titles[] = $topic;
+ }
+
+ return $titles;
+ }
+
+ /**
+ * Formats an activity log entry.
+ *
+ * @return string The log entry
+ */
+ protected function getActionMessage() {
+ $board = $this->entry->getTarget();
+ $params = $this->entry->getParameters() + array(
+ 'topic' => '',
+ 'lqt_subject' => '',
+ );
+ $topic = Title::newFromText( $params['topic'] );
+
+ $message = $this->msg( "logentry-import-lqt-to-flow-topic" )
+ ->params(
+ $topic ? $topic->getPrefixedText() : '',
+ Message::plaintextParam( $params['lqt_subject']
),
+ $board->getPrefixedText()
+ );
+
+ return $this->plaintext ? $message->text() : $message->parse();
+ }
+}
diff --git a/tests/phpunit/Mock/MockImportTopic.php
b/tests/phpunit/Mock/MockImportTopic.php
index 68d31c5..7ff79a7 100644
--- a/tests/phpunit/Mock/MockImportTopic.php
+++ b/tests/phpunit/Mock/MockImportTopic.php
@@ -32,6 +32,20 @@
/**
* {@inheritDoc}
*/
+ public function getLogType() {
+ "mock-flow-topic-import";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getLogParameters() {
+ return array();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public function getObjectKey() {
return 'mock-topic:1';
}
--
To view, visit https://gerrit.wikimedia.org/r/189909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0ce69cca9ab017fc0b9357a65245defd98c71f0f
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits