MediaWiki  master
DatabaseLogEntry.php
Go to the documentation of this file.
1 <?php
29 use Wikimedia\AtEase\AtEase;
31 
41 
53  public static function getSelectQueryData() {
54  $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
55 
56  $tables = array_merge(
57  [
58  'logging',
59  'logging_actor' => 'actor',
60  'user'
61  ],
62  $commentQuery['tables']
63  );
64  $fields = [
65  'log_id', 'log_type', 'log_action', 'log_timestamp',
66  'log_namespace', 'log_title', // unused log_page
67  'log_params', 'log_deleted',
68  'user_id',
69  'user_name',
70  'log_actor',
71  'log_user' => 'logging_actor.actor_user',
72  'log_user_text' => 'logging_actor.actor_name'
73  ] + $commentQuery['fields'];
74 
75  $joins = [
76  'logging_actor' => [ 'JOIN', 'actor_id=log_actor' ],
77  // IPs don't have an entry in user table
78  'user' => [ 'LEFT JOIN', 'user_id=logging_actor.actor_user' ],
79  ] + $commentQuery['joins'];
80 
81  return [
82  'tables' => $tables,
83  'fields' => $fields,
84  'conds' => [],
85  'options' => [],
86  'join_conds' => $joins,
87  ];
88  }
89 
97  public static function newFromRow( $row ) {
98  $row = (object)$row;
99  if ( isset( $row->rc_logid ) ) {
100  return new RCDatabaseLogEntry( $row );
101  } else {
102  return new self( $row );
103  }
104  }
105 
113  public static function newFromId( $id, IDatabase $db ) {
114  $queryInfo = self::getSelectQueryData();
115  $queryInfo['conds'] += [ 'log_id' => $id ];
116  $row = $db->selectRow(
117  $queryInfo['tables'],
118  $queryInfo['fields'],
119  $queryInfo['conds'],
120  __METHOD__,
121  $queryInfo['options'],
122  $queryInfo['join_conds']
123  );
124  if ( !$row ) {
125  return null;
126  }
127  return self::newFromRow( $row );
128  }
129 
131  protected $row;
132 
134  protected $performer;
135 
137  protected $params;
138 
140  protected $revId = null;
141 
143  protected $legacy;
144 
145  protected function __construct( $row ) {
146  $this->row = $row;
147  }
148 
154  public function getId() {
155  return (int)( $this->row->log_id ?? 0 );
156  }
157 
163  protected function getRawParameters() {
164  return $this->row->log_params;
165  }
166 
167  public function isLegacy() {
168  // This extracts the property
169  $this->getParameters();
170  return $this->legacy;
171  }
172 
173  public function getType() {
174  return $this->row->log_type;
175  }
176 
177  public function getSubtype() {
178  return $this->row->log_action;
179  }
180 
181  public function getParameters() {
182  if ( !isset( $this->params ) ) {
183  $blob = $this->getRawParameters();
184  AtEase::suppressWarnings();
186  AtEase::restoreWarnings();
187  if ( $params !== false ) {
188  $this->params = $params;
189  $this->legacy = false;
190  } else {
191  $this->params = LogPage::extractParams( $blob );
192  $this->legacy = true;
193  }
194 
195  if ( isset( $this->params['associated_rev_id'] ) ) {
196  $this->revId = $this->params['associated_rev_id'];
197  unset( $this->params['associated_rev_id'] );
198  }
199  }
200 
201  return $this->params;
202  }
203 
204  public function getAssociatedRevId() {
205  // This extracts the property
206  $this->getParameters();
207  return $this->revId;
208  }
209 
210  public function getPerformerIdentity(): UserIdentity {
211  if ( !$this->performer ) {
212  $actorStore = MediaWikiServices::getInstance()->getActorStore();
213  try {
214  $this->performer = $actorStore->newActorFromRowFields(
215  $this->row->user_id ?? 0,
216  $this->row->log_user_text ?? null,
217  $this->row->log_actor ?? null
218  );
219  } catch ( InvalidArgumentException $e ) {
220  LoggerFactory::getInstance( 'logentry' )->warning(
221  'Failed to instantiate log entry performer', [
222  'exception' => $e,
223  'log_id' => $this->getId()
224  ]
225  );
226  $this->performer = $actorStore->getUnknownActor();
227  }
228  }
229  return $this->performer;
230  }
231 
232  public function getTarget() {
233  $namespace = $this->row->log_namespace;
234  $page = $this->row->log_title;
235  return Title::makeTitle( $namespace, $page );
236  }
237 
238  public function getTimestamp() {
239  return wfTimestamp( TS_MW, $this->row->log_timestamp );
240  }
241 
242  public function getComment() {
243  return CommentStore::getStore()->getComment( 'log_comment', $this->row )->text;
244  }
245 
246  public function getDeleted() {
247  return $this->row->log_deleted;
248  }
249 }
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition: WebStart.php:82
static getStore()
A value class to process existing log entries.
getParameters()
Get the extra parameters stored for this message.
isLegacy()
Whether the parameters for this log are stored in new or old format.
array $params
Parameters for log entry.
getSubtype()
The log subtype.
getDeleted()
Get the access restriction.
static newFromRow( $row)
Constructs new LogEntry from database result row.
getComment()
Get the user provided comment.
bool $legacy
Whether the parameters for this log entry are stored in new or old format.
int $revId
A rev id associated to the log entry.
getRawParameters()
Returns whatever is stored in the database field.
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
stdClass $row
Database result row.
getId()
Returns the unique database id.
UserIdentity $performer
getTarget()
Get the target page of this action.
getType()
The main log type.
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
getTimestamp()
Get the timestamp when the action was executed.
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:428
PSR-3 logger instance factory.
Service locator for MediaWiki core services.
A subclass of DatabaseLogEntry for objects constructed from entries in the recentchanges table (rathe...
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:638
Interface for objects representing user identity.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:39
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Wrapper to IDatabase::select() that only fetches one row (via LIMIT)