Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
RCDatabaseLogEntry
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 12
342
0.00% covered (danger)
0.00%
0 / 1
 newFromId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSelectQueryData
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRawParameters
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAssociatedRevId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSubtype
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPerformerIdentity
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
56
 getTarget
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getTimestamp
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getComment
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getDeleted
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Contains a class for dealing with recent changes database log entries
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Niklas Laxström
22 * @license GPL-2.0-or-later
23 * @since 1.19
24 */
25
26use MediaWiki\Logger\LoggerFactory;
27use MediaWiki\MediaWikiServices;
28use MediaWiki\Title\Title;
29use MediaWiki\User\UserIdentity;
30use Wikimedia\Rdbms\IReadableDatabase;
31
32/**
33 * A subclass of DatabaseLogEntry for objects constructed from entries in the
34 * recentchanges table (rather than the logging table).
35 *
36 * This class should only be used in context of the LogFormatter class.
37 */
38class RCDatabaseLogEntry extends DatabaseLogEntry {
39
40    public static function newFromId( $id, IReadableDatabase $db ) {
41        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
42        // Make the LSP violation explicit to prevent sneaky failures
43        throw new LogicException( 'Not implemented!' );
44    }
45
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!' );
50    }
51
52    public function getId() {
53        return $this->row->rc_logid;
54    }
55
56    protected function getRawParameters() {
57        return $this->row->rc_params;
58    }
59
60    public function getAssociatedRevId() {
61        return $this->row->rc_this_oldid;
62    }
63
64    public function getType() {
65        return $this->row->rc_log_type;
66    }
67
68    public function getSubtype() {
69        return $this->row->rc_log_action;
70    }
71
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 ) ) {
77                try {
78                    $this->performer = $actorStore->newActorFromRowFields(
79                        $this->row->rc_user ?? 0,
80                        $this->row->rc_user_text,
81                        $this->row->rc_actor
82                    );
83                } catch ( InvalidArgumentException $e ) {
84                    $this->performer = $actorStore->getUnknownActor();
85                    LoggerFactory::getInstance( 'logentry' )->warning(
86                        'Failed to instantiate RC log entry performer', [
87                            'exception' => $e,
88                            'log_id' => $this->getId()
89                        ]
90                    );
91                }
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 );
96                if ( $user ) {
97                    $this->performer = $user->getUser();
98                } else {
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()
104                        ]
105                    );
106                }
107            }
108        }
109        return $this->performer;
110    }
111
112    public function getTarget() {
113        $namespace = $this->row->rc_namespace;
114        $page = $this->row->rc_title;
115        return Title::makeTitle( $namespace, $page );
116    }
117
118    public function getTimestamp() {
119        return wfTimestamp( TS_MW, $this->row->rc_timestamp );
120    }
121
122    public function getComment() {
123        $services = MediaWikiServices::getInstance();
124
125        return $services->getCommentStore()
126            // Legacy because the row may have used RecentChange::selectFields()
127            ->getCommentLegacy(
128                $services->getConnectionProvider()->getReplicaDatabase(),
129                'rc_comment',
130                $this->row
131            )->text;
132    }
133
134    public function getDeleted() {
135        return $this->row->rc_deleted;
136    }
137}