Mattflaschen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/259892
Change subject: Include Flow topics in Nuke
......................................................................
Include Flow topics in Nuke
Bug: T115695
Change-Id: I09aeb876066554496fc7f533e60bd0cea842777b
Depends-On: Ia9dc16b3a4a623ef213adbcf18f44b497f2d9f27
---
M Flow.php
M Hooks.php
2 files changed, 170 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/92/259892/1
diff --git a/Flow.php b/Flow.php
index 000d7be..8c0308c 100644
--- a/Flow.php
+++ b/Flow.php
@@ -173,6 +173,10 @@
$wgHooks['GetBetaFeaturePreferences'][] =
'FlowHooks::onGetBetaFeaturePreferences';
$wgHooks['UserSaveOptions'][] = 'FlowHooks::onUserSaveOptions';
+// Nuke
+$wgHooks['NukeGetNewPages'][] = 'FlowHooks::onNukeGetNewPages';
+$wgHooks['NukeDeletePage'][] = 'FlowHooks::onNukeDeletePage';
+
// Extension initialization
$wgExtensionFunctions[] = 'FlowHooks::initFlowExtension';
diff --git a/Hooks.php b/Hooks.php
index 4aa7289..a42167d 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -11,6 +11,7 @@
use Flow\OccupationController;
use Flow\SpamFilter\AbuseFilter;
use Flow\TalkpageManager;
+use Flow\WorkflowLoader;
use Flow\WorkflowLoaderFactory;
use Flow\Data\Listener\RecentChangesListener;
@@ -1825,4 +1826,169 @@
return true;
}
+
+ public static function onNukeGetNewPages( $username, $pattern,
$namespace, $limit, &$pages ) {
+ if ( $namespace && $namespace !== NS_TOPIC ) {
+ // not interested in any Topics
+ return true;
+ }
+
+ // Remove any pre-existing Topic pages.
+ // They are coming from the recentchanges table.
+ // Most likely the filters were not applied correctly.
+ $pages = array_filter( $pages, function( $entry ) {
+ /** @var Title $title */
+ $title = $entry[0];
+ return $title->getNamespace() !== NS_TOPIC;
+ } );
+
+ if ( $pattern ) {
+ // pattern is not supported
+ return true;
+ }
+
+ if ( !RequestContext::getMain()->getUser()->isAllowed(
'flow-delete' ) ) {
+ // there's no point adding topics since the current
user won't be allowed to delete them
+ return true;
+ }
+
+ // how many are we allowed to retrieve now
+ $newLimit = $limit - count( $pages );
+ if ( $newLimit > 0 ) {
+
+ $dbr = wfGetDB( DB_SLAVE );
+
+ $userSelect = array( 'username' =>
"IFNULL(tree_orig_user_ip, user_name)" );
+ $userWhere = array();
+ if ( $username ) {
+ $userSelect = array();
+ $user = User::newFromName( $username );
+ if ( $user ) {
+ $userWhere = array( 'tree_orig_user_id'
=> $user->getId() );
+ } else {
+ $userWhere = array( 'tree_orig_user_ip'
=> $username );
+ }
+ }
+
+ // limit results to the range of RC
+ global $wgRCMaxAge;
+ $rcTimeLimit = UUID::getComparisonUUID(
strtotime("-$wgRCMaxAge seconds") );
+
+ // get latest revision id for each topic
+ // by the specified user (optional)
+ $result = $dbr->select(
+ array(
+ 'r' => 'flow_revision',
+ 'flow_tree_revision',
+ 'flow_workflow',
+ 'user'
+ ),
+ array_merge( array(
+ 'revId' => 'MAX(r.rev_id)'
+ ), $userSelect ),
+ array_merge( array(
+ 'tree_parent_id' => null,
+ 'r.rev_type' => 'post',
+ 'workflow_wiki' => wfWikiId(),
+ 'workflow_id > ' . $dbr->addQuotes(
$rcTimeLimit->getBinary() )
+ ), $userWhere ),
+ __METHOD__,
+ array(
+ 'GROUP BY' => 'r.rev_type_id'
+ ),
+ array(
+ 'flow_tree_revision' => array( 'INNER
JOIN', 'r.rev_type_id=tree_rev_descendant_id' ),
+ 'flow_workflow' => array( 'INNER JOIN',
'r.rev_type_id=workflow_id' ),
+ 'user' => array( 'LEFT JOIN',
'user_id=tree_orig_user_id' )
+ )
+ );
+
+ $revIds = array();
+ foreach( $result as $r ) {
+ $revIds[$r->revId] = $username === '' ?
$r->username : false;
+ }
+
+ // get non-moderated revisions
+ $result = $dbr->select(
+ 'flow_revision',
+ array(
+ 'topicId' => 'rev_type_id',
+ 'revId' => 'rev_id'
+ ),
+ array(
+ 'rev_mod_state' => '',
+ 'rev_id' => array_keys( $revIds )
+ ),
+ __METHOD__,
+ array(
+ 'LIMIT' => $newLimit,
+ 'ORDER BY' => 'rev_type_id DESC'
+ )
+ );
+
+ foreach( $result as $r ) {
+ $topicTitle = Title::makeTitle( NS_TOPIC,
UUID::create( $r->topicId )->getAlphadecimal() );
+ $creatorUsername = $revIds[$r->revId];
+ $pages[] = array( $topicTitle, $creatorUsername
);
+ }
+
+ }
+
+ return true;
+ }
+
+ public static function onNukeDeletePage( Title $title, $reason,
&$deletionResult ) {
+ if ( $title->getNamespace() !== NS_TOPIC ) {
+ // we don't handle it
+ return true;
+ }
+
+ $action = 'moderate-topic';
+ $params = array(
+ 'topic' => array(
+ 'moderationState' => 'delete',
+ 'reason' => $reason,
+ 'page' => $title->getPrefixedText()
+ ),
+ );
+
+ /** @var WorkflowLoaderFactory $factory */
+ $factory = Container::get( 'factory.loader.workflow' );
+
+ $workflowId = WorkflowLoaderFactory::uuidFromTitle( $title );
+ /** @var WorkflowLoader $loader */
+ $loader = $factory->createWorkflowLoader( $title, $workflowId );
+
+ $blocks = $loader->getBlocks();
+
+ $blocksToCommit = $loader->handleSubmit(
+ RequestContext::getMain(),
+ $action,
+ $params
+ );
+
+ $result = true;
+ $errors = array();
+ foreach ( $blocks as $block ) {
+ if ( $block->hasErrors() ) {
+ $result = false;
+ $errorKeys = $block->getErrors();
+ foreach ( $errorKeys as $errorKey ) {
+ $errors[] = $block->getErrorMessage(
$errorKey );
+ }
+ }
+ }
+
+ if ( $result ) {
+ $loader->commit( $blocksToCommit );
+ $deletionResult = true;
+ } else {
+ $deletionResult = false;
+ $msg = "Failed to delete {$title->getPrefixedText()}.
Errors: " . implode( '. ', $errors );
+ wfLogWarning( $msg );
+ }
+
+ // we've handled the deletion, abort the hook
+ return false;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/259892
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I09aeb876066554496fc7f533e60bd0cea842777b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: wmf/1.27.0-wmf.9
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits