MediaWiki master
DatabaseLogEntry.php
Go to the documentation of this file.
1<?php
26namespace MediaWiki\Logging;
27
28use InvalidArgumentException;
32use stdClass;
33use Wikimedia\AtEase\AtEase;
35
45
59 public static function getSelectQueryData() {
60 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'log_comment' );
61
62 $tables = array_merge(
63 [
64 'logging',
65 'logging_actor' => 'actor',
66 'user'
67 ],
68 $commentQuery['tables']
69 );
70 $fields = [
71 'log_id', 'log_type', 'log_action', 'log_timestamp',
72 'log_namespace', 'log_title', // unused log_page
73 'log_params', 'log_deleted',
74 'user_id',
75 'user_name',
76 'log_actor',
77 'log_user' => 'logging_actor.actor_user',
78 'log_user_text' => 'logging_actor.actor_name'
79 ] + $commentQuery['fields'];
80
81 $joins = [
82 'logging_actor' => [ 'JOIN', 'actor_id=log_actor' ],
83 // IPs don't have an entry in user table
84 'user' => [ 'LEFT JOIN', 'user_id=logging_actor.actor_user' ],
85 ] + $commentQuery['joins'];
86
87 return [
88 'tables' => $tables,
89 'fields' => $fields,
90 'conds' => [],
91 'options' => [],
92 'join_conds' => $joins,
93 ];
94 }
95
96 public static function newSelectQueryBuilder( IReadableDatabase $db ) {
97 return new LoggingSelectQueryBuilder( $db );
98 }
99
107 public static function newFromRow( $row ) {
108 $row = (object)$row;
109 if ( isset( $row->rc_logid ) ) {
110 return new RCDatabaseLogEntry( $row );
111 }
112
113 return new self( $row );
114 }
115
123 public static function newFromId( $id, IReadableDatabase $db ) {
125 ->where( [ 'log_id' => $id ] )
126 ->caller( __METHOD__ )->fetchRow();
127 if ( !$row ) {
128 return null;
129 }
130 return self::newFromRow( $row );
131 }
132
134 protected $row;
135
137 protected $performer;
138
140 protected $params;
141
143 protected $revId = null;
144
146 protected $legacy;
147
148 protected function __construct( $row ) {
149 $this->row = $row;
150 }
151
157 public function getId() {
158 return (int)( $this->row->log_id ?? 0 );
159 }
160
167 protected function getRawParameters() {
168 return $this->row->log_params;
169 }
170
171 public function isLegacy() {
172 // This extracts the property
173 $this->getParameters();
174 return $this->legacy;
175 }
176
177 public function getType() {
178 return $this->row->log_type;
179 }
180
181 public function getSubtype() {
182 return $this->row->log_action;
183 }
184
185 public function getParameters() {
186 if ( $this->params === null ) {
187 $blob = $this->getRawParameters();
188 AtEase::suppressWarnings();
190 AtEase::restoreWarnings();
191 if ( $params !== false ) {
192 $this->params = $params;
193 $this->legacy = false;
194 } else {
195 $this->params = LogPage::extractParams( $blob );
196 $this->legacy = true;
197 }
198
199 if ( isset( $this->params['associated_rev_id'] ) ) {
200 $this->revId = $this->params['associated_rev_id'];
201 unset( $this->params['associated_rev_id'] );
202 }
203 }
204
205 return $this->params;
206 }
207
208 public function getAssociatedRevId() {
209 // This extracts the property
210 $this->getParameters();
211 return $this->revId;
212 }
213
215 if ( !$this->performer ) {
216 $actorStore = MediaWikiServices::getInstance()->getActorStore();
217 try {
218 $this->performer = $actorStore->newActorFromRowFields(
219 $this->row->user_id ?? 0,
220 $this->row->log_user_text ?? null,
221 $this->row->log_actor ?? null
222 );
223 } catch ( InvalidArgumentException $e ) {
224 LoggerFactory::getInstance( 'logentry' )->warning(
225 'Failed to instantiate log entry performer', [
226 'exception' => $e,
227 'log_id' => $this->getId()
228 ]
229 );
230 $this->performer = $actorStore->getUnknownActor();
231 }
232 }
233 return $this->performer;
234 }
235
236 public function getTarget() {
237 $namespace = $this->row->log_namespace;
238 $page = $this->row->log_title;
239 return MediaWikiServices::getInstance()->getTitleFactory()->makeTitle( $namespace, $page );
240 }
241
242 public function getTimestamp() {
243 return wfTimestamp( TS_MW, $this->row->log_timestamp );
244 }
245
246 public function getComment() {
247 return MediaWikiServices::getInstance()->getCommentStore()
248 ->getComment( 'log_comment', $this->row )->text;
249 }
250
251 public function getDeleted() {
252 return $this->row->log_deleted;
253 }
254}
255
257class_alias( DatabaseLogEntry::class, 'DatabaseLogEntry' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
Create PSR-3 logger objects.
A value class to process existing log entries.
static newFromId( $id, IReadableDatabase $db)
Loads a LogEntry with the given id from database.
static newFromRow( $row)
Constructs new LogEntry from database result row.
getDeleted()
Get the access restriction.
getTimestamp()
Get the timestamp when the action was executed.
getId()
Returns the unique database id.
getComment()
Get the user provided comment.
getParameters()
Get the extra parameters stored for this message.
getTarget()
Get the target page of this action.
getRawParameters()
Returns whatever is stored in the database field (typically a serialized associative array but very o...
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
int $revId
A rev id associated to the log entry.
isLegacy()
Whether the parameters for this log are stored in new or old format.
array null $params
Parameters for log entry.
stdClass $row
Database result row.
bool $legacy
Whether the parameters for this log entry are stored in new or old format.
static newSelectQueryBuilder(IReadableDatabase $db)
Extends the LogEntry Interface with some basic functionality.
static extractParams( $blob)
Extract a parameter array from a blob.
static extractParams( $blob)
Extract a parameter array from a blob.
Definition LogPage.php:406
Help and centralize querying logging table.
A subclass of DatabaseLogEntry for objects constructed from entries in the recentchanges table (rathe...
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Interface for objects representing user identity.
A database connection without write operations.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...