3 * Contains a class for dealing with recent changes database log entries
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @author Niklas Laxström
22 * @license GPL-2.0-or-later
26 use MediaWiki\Logger\LoggerFactory
;
27 use MediaWiki\MediaWikiServices
;
28 use MediaWiki\Title\Title
;
29 use MediaWiki\User\UserIdentity
;
30 use Wikimedia\Rdbms\IDatabase
;
33 * A subclass of DatabaseLogEntry for objects constructed from entries in the
34 * recentchanges table (rather than the logging table).
36 * This class should only be used in context of the LogFormatter class.
38 class RCDatabaseLogEntry
extends DatabaseLogEntry
{
40 public static function newFromId( $id, IDatabase
$db ) {
41 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
42 // Make the LSP violation explicit to prevent sneaky failures
43 throw new LogicException( 'Not implemented!' );
46 public static function getSelectQueryData() {
47 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
48 // Make the LSP violation explicit to prevent sneaky failures
49 throw new LogicException( 'Not implemented!' );
52 public function getId() {
53 return $this->row
->rc_logid
;
56 protected function getRawParameters() {
57 return $this->row
->rc_params
;
60 public function getAssociatedRevId() {
61 return $this->row
->rc_this_oldid
;
64 public function getType() {
65 return $this->row
->rc_log_type
;
68 public function getSubtype() {
69 return $this->row
->rc_log_action
;
72 public function getPerformerIdentity(): UserIdentity
{
73 if ( !$this->performer
) {
74 $actorStore = MediaWikiServices
::getInstance()->getActorStore();
75 $userFactory = MediaWikiServices
::getInstance()->getUserFactory();
76 if ( isset( $this->row
->rc_actor
) ) {
78 $this->performer
= $actorStore->newActorFromRowFields(
79 $this->row
->rc_user ??
0,
80 $this->row
->rc_user_text
,
83 } catch ( InvalidArgumentException
$e ) {
84 $this->performer
= $actorStore->getUnknownActor();
85 LoggerFactory
::getInstance( 'logentry' )->warning(
86 'Failed to instantiate RC log entry performer', [
88 'log_id' => $this->getId()
92 } elseif ( isset( $this->row
->rc_user
) ) {
93 $this->performer
= $userFactory->newFromId( $this->row
->rc_user
)->getUser();
94 } elseif ( isset( $this->row
->rc_user_text
) ) {
95 $user = $userFactory->newFromName( $this->row
->rc_user_text
);
97 $this->performer
= $user->getUser();
99 $this->performer
= $actorStore->getUnknownActor();
100 LoggerFactory
::getInstance( 'logentry' )->warning(
101 'Failed to instantiate RC log entry performer', [
102 'rc_user_text' => $this->row
->rc_user_text
,
103 'log_id' => $this->getId()
109 return $this->performer
;
112 public function getTarget() {
113 $namespace = $this->row
->rc_namespace
;
114 $page = $this->row
->rc_title
;
115 return Title
::makeTitle( $namespace, $page );
118 public function getTimestamp() {
119 return wfTimestamp( TS_MW
, $this->row
->rc_timestamp
);
122 public function getComment() {
123 return MediaWikiServices
::getInstance()->getCommentStore()
124 // Legacy because the row may have used RecentChange::selectFields()
125 ->getCommentLegacy( wfGetDB( DB_REPLICA
), 'rc_comment', $this->row
)->text
;
128 public function getDeleted() {
129 return $this->row
->rc_deleted
;