From 2daec3b97084ef2d06f4360106185253866c144b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Sat, 23 Nov 2024 11:23:34 +0100 Subject: [PATCH] Clean up dead or unnecessarily complex code Change-Id: I94d25adb5b6c6b4f82a6458828d6dbb8fc88c4c3 --- includes/DiscussionParser.php | 13 +++---------- includes/Model/Notification.php | 7 ++----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php index 0f8cdd667..5c48fce53 100644 --- a/includes/DiscussionParser.php +++ b/includes/DiscussionParser.php @@ -115,7 +115,7 @@ abstract class DiscussionParser { $notifyUser = User::newFromName( $title->getText() ); // If the recipient is a valid non-anonymous user generate a talk page post notification. if ( $notifyUser && $notifyUser->getId() ) { - $permManager = MediaWikiServices::getInstance()->getPermissionManager(); + $permManager = $services->getPermissionManager(); // If this is a minor edit, only notify if the agent doesn't have talk page minor // edit notification blocked if ( !$revision->isMinor() || !$permManager->userHasRight( $user, 'nominornewtalk' ) ) { @@ -584,7 +584,7 @@ abstract class DiscussionParser { * * @todo Expand recognisable actions. * - * @param array[] $changes Output of Event::getMachineReadableDiff + * @param array[] $changes Output of DiscussionParser::getMachineReadableDiff * @param string $username * @param Title|null $title * @return array[] Array of associative arrays. @@ -746,7 +746,7 @@ abstract class DiscussionParser { * @return array[] Converted actions */ private static function convertToUnknownSignedChanges( array $signedSections, array $actions ) { - return array_map( function ( $action ) use( $signedSections ) { + return array_map( function ( $action ) use ( $signedSections ) { if ( $action['type'] === 'unknown-change' && self::isInSignedSection( $action['right-pos'], $signedSections ) @@ -1030,11 +1030,7 @@ abstract class DiscussionParser { $output = []; - $lineNumber = 0; - foreach ( $lines as $line ) { - ++$lineNumber; - // Look for the last user link on the line. $userData = self::getUserFromLine( $line, $title ); if ( $userData === false ) { @@ -1094,9 +1090,6 @@ abstract class DiscussionParser { } elseif ( $title && $title->isSpecial( 'Contributions' ) ) { $parts = explode( '/', $title->getText(), 2 ); $usernames[] = end( $parts ); - } else { - // move on to next matched title-like excerpt - continue; } } diff --git a/includes/Model/Notification.php b/includes/Model/Notification.php index f99144635..4bd5682ff 100644 --- a/includes/Model/Notification.php +++ b/includes/Model/Notification.php @@ -87,11 +87,8 @@ class Notification extends AbstractEntity implements Bundleable { } // Notification timestamp should be the same as event timestamp - $obj->timestamp = $obj->event->getTimestamp(); - // Safe fallback - if ( !$obj->timestamp ) { - $obj->timestamp = wfTimestampNow(); - } + // Otherwise use safe fallback + $obj->timestamp = $obj->event->getTimestamp() ?: wfTimestampNow(); // @Todo - Database insert logic should not be inside the model $obj->insert();