Remove hard-deprecated LogEntry::getPerformer
Change-Id: Ia2c4819848f5d23d5ceb74aae9c6c5920b8851ba
This commit is contained in:
parent
4afd20e1ba
commit
1782bc7fd4
7 changed files with 82 additions and 45 deletions
|
|
@ -297,6 +297,8 @@ because of Phabricator reports.
|
|||
- ::loadRevisionFromTitle,
|
||||
- ::loadRevisionFromTimestamp,
|
||||
- ::listRevisionSizes
|
||||
* LogEntry::getPerformer, deprecated since 1.36, was removed along with methods
|
||||
in subclasses: DatabaseLogEntry, ManualLogEntry, RCDatabaseLogEntry.
|
||||
* …
|
||||
|
||||
=== Deprecations in 1.37 ===
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
* @since 1.19
|
||||
*/
|
||||
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
|
@ -129,7 +130,7 @@ class DatabaseLogEntry extends LogEntryBase {
|
|||
/** @var stdClass Database result row. */
|
||||
protected $row;
|
||||
|
||||
/** @var User */
|
||||
/** @var UserIdentity */
|
||||
protected $performer;
|
||||
|
||||
/** @var array Parameters for log entry */
|
||||
|
|
@ -151,7 +152,7 @@ class DatabaseLogEntry extends LogEntryBase {
|
|||
* @return int
|
||||
*/
|
||||
public function getId() {
|
||||
return (int)$this->row->log_id;
|
||||
return (int)( $this->row->log_id ?? 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -206,26 +207,26 @@ class DatabaseLogEntry extends LogEntryBase {
|
|||
return $this->revId;
|
||||
}
|
||||
|
||||
protected function getPerformerUser(): User {
|
||||
if ( !$this->performer ) {
|
||||
$this->performer = MediaWikiServices::getInstance()->getUserFactory()
|
||||
->newFromAnyId(
|
||||
$this->row->user_id ?? 0, // left join failure means anonymous
|
||||
$this->row->log_user_text,
|
||||
$this->row->log_actor
|
||||
);
|
||||
}
|
||||
|
||||
return $this->performer;
|
||||
}
|
||||
|
||||
public function getPerformer() {
|
||||
wfDeprecated( __METHOD__, '1.36' );
|
||||
return $this->getPerformerUser();
|
||||
}
|
||||
|
||||
public function getPerformerIdentity(): UserIdentity {
|
||||
return $this->getPerformerUser();
|
||||
if ( !$this->performer ) {
|
||||
$actorStore = MediaWikiServices::getInstance()->getActorStore();
|
||||
try {
|
||||
$this->performer = $actorStore->newActorFromRowFields(
|
||||
$this->row->user_id ?? 0,
|
||||
$this->row->log_user_text ?? null,
|
||||
$this->row->log_actor ?? null
|
||||
);
|
||||
} catch ( InvalidArgumentException $e ) {
|
||||
LoggerFactory::getInstance( 'logentry' )->warning(
|
||||
'Failed to instantiate log entry performer', [
|
||||
'exception' => $e,
|
||||
'log_id' => $this->getId()
|
||||
]
|
||||
);
|
||||
$this->performer = $actorStore->getUnknownActor();
|
||||
}
|
||||
}
|
||||
return $this->performer;
|
||||
}
|
||||
|
||||
public function getTarget() {
|
||||
|
|
|
|||
|
|
@ -61,13 +61,6 @@ interface LogEntry {
|
|||
*/
|
||||
public function getParameters();
|
||||
|
||||
/**
|
||||
* Get the user who performed this action.
|
||||
* @deprecated since 1.36 use ::getPerformerIdentity instead
|
||||
* @return User
|
||||
*/
|
||||
public function getPerformer();
|
||||
|
||||
/**
|
||||
* @since 1.36
|
||||
* @return UserIdentity
|
||||
|
|
|
|||
|
|
@ -455,14 +455,6 @@ class ManualLogEntry extends LogEntryBase implements Taggable {
|
|||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getPerformer() {
|
||||
wfDeprecated( __METHOD__, '1.36' );
|
||||
return User::newFromIdentity( $this->performer );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserIdentity
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@
|
|||
* @since 1.19
|
||||
*/
|
||||
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
/**
|
||||
|
|
@ -64,15 +66,25 @@ class RCDatabaseLogEntry extends DatabaseLogEntry {
|
|||
return $this->row->rc_log_action;
|
||||
}
|
||||
|
||||
protected function getPerformerUser(): User {
|
||||
public function getPerformerIdentity(): UserIdentity {
|
||||
if ( !$this->performer ) {
|
||||
$this->performer = MediaWikiServices::getInstance()->getUserFactory()->newFromAnyId(
|
||||
$actorStore = MediaWikiServices::getInstance()->getActorStore();
|
||||
try {
|
||||
$this->performer = $actorStore->newActorFromRowFields(
|
||||
$this->row->rc_user ?? 0,
|
||||
$this->row->rc_user_text,
|
||||
$this->row->rc_actor ?? null
|
||||
);
|
||||
} catch ( InvalidArgumentException $e ) {
|
||||
LoggerFactory::getInstance( 'logentry' )->warning(
|
||||
'Failed to instantiate RC log entry performer', [
|
||||
'exception' => $e,
|
||||
'log_id' => $this->getId()
|
||||
]
|
||||
);
|
||||
$this->performer = $actorStore->getUnknownActor();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->performer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\ActorStore;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MediaWiki\User\UserIdentityValue;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
class DatabaseLogEntryTest extends MediaWikiIntegrationTestCase {
|
||||
|
|
@ -124,4 +127,38 @@ class DatabaseLogEntryTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function provideGetPerformerIdentity() {
|
||||
yield 'registered actor' => [
|
||||
'actor_row_fields' => [
|
||||
'user_id' => 42,
|
||||
'log_user_text' => 'Testing',
|
||||
'log_actor' => 24,
|
||||
],
|
||||
UserIdentityValue::newRegistered( 42, 'Testing' ),
|
||||
];
|
||||
yield 'anon actor' => [
|
||||
'actor_row_fields' => [
|
||||
'log_user_text' => '127.0.0.1',
|
||||
'log_actor' => 24,
|
||||
],
|
||||
UserIdentityValue::newAnonymous( '127.0.0.1' ),
|
||||
];
|
||||
yield 'unknown actor' => [
|
||||
'actor_row_fields' => [],
|
||||
new UserIdentityValue( 0, ActorStore::UNKNOWN_USER_NAME ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideGetPerformerIdentity
|
||||
* @covers DatabaseLogEntry::getPerformerIdentity
|
||||
*/
|
||||
public function testGetPerformer( array $actorRowFields, UserIdentity $expected ) {
|
||||
$logEntry = DatabaseLogEntry::newFromRow( [
|
||||
'log_id' => 1,
|
||||
] + $actorRowFields );
|
||||
$performer = $logEntry->getPerformerIdentity();
|
||||
$this->assertTrue( $expected->equals( $performer ) );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ abstract class LogFormatterTestCase extends MediaWikiLangTestCase {
|
|||
'log_type' => $data['type'],
|
||||
'log_action' => $data['action'],
|
||||
'log_timestamp' => $data['timestamp'] ?? wfTimestampNow(),
|
||||
'log_user' => $data['user'] ?? 0,
|
||||
'log_user' => $data['user'] ?? 42,
|
||||
'log_user_text' => $data['user_text'] ?? 'User',
|
||||
'log_actor' => $data['actor'] ?? 0,
|
||||
'log_actor' => $data['actor'] ?? 24,
|
||||
'log_namespace' => $data['namespace'] ?? NS_MAIN,
|
||||
'log_title' => $data['title'] ?? 'Main_Page',
|
||||
'log_page' => $data['page'] ?? 0,
|
||||
|
|
|
|||
Loading…
Reference in a new issue