MediaWiki  master
DatabaseLogEntry.php
Go to the documentation of this file.
1 <?php
30 
40 
52  public static function getSelectQueryData() {
53  $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
54 
55  $tables = array_merge(
56  [
57  'logging',
58  'logging_actor' => 'actor',
59  'user'
60  ],
61  $commentQuery['tables']
62  );
63  $fields = [
64  'log_id', 'log_type', 'log_action', 'log_timestamp',
65  'log_namespace', 'log_title', // unused log_page
66  'log_params', 'log_deleted',
67  'user_id',
68  'user_name',
69  'user_editcount',
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  Wikimedia\suppressWarnings();
186  Wikimedia\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 }
RCDatabaseLogEntry
A subclass of DatabaseLogEntry for objects constructed from entries in the recentchanges table (rathe...
Definition: RCDatabaseLogEntry.php:37
DatabaseLogEntry\getId
getId()
Returns the unique database id.
Definition: DatabaseLogEntry.php:154
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:193
DatabaseLogEntry\$params
array $params
Parameters for log entry.
Definition: DatabaseLogEntry.php:137
LogPage\extractParams
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogPage.php:427
DatabaseLogEntry\getParameters
getParameters()
Get the extra parameters stored for this message.
Definition: DatabaseLogEntry.php:181
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1668
DatabaseLogEntry\getSelectQueryData
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition: DatabaseLogEntry.php:52
DatabaseLogEntry\newFromId
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
Definition: DatabaseLogEntry.php:113
DatabaseLogEntry\getComment
getComment()
Get the user provided comment.
Definition: DatabaseLogEntry.php:242
DatabaseLogEntry\getSubtype
getSubtype()
The log subtype.
Definition: DatabaseLogEntry.php:177
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
DatabaseLogEntry\getTimestamp
getTimestamp()
Get the timestamp when the action was executed.
Definition: DatabaseLogEntry.php:238
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
DatabaseLogEntry\newFromRow
static newFromRow( $row)
Constructs new LogEntry from database result row.
Definition: DatabaseLogEntry.php:97
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
DatabaseLogEntry\$performer
UserIdentity $performer
Definition: DatabaseLogEntry.php:134
$blob
$blob
Definition: testCompression.php:70
DatabaseLogEntry\getType
getType()
The main log type.
Definition: DatabaseLogEntry.php:173
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:651
LogEntryBase
Extends the LogEntry Interface with some basic functionality.
Definition: LogEntryBase.php:31
LogEntryBase\extractParams
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogEntryBase.php:69
DatabaseLogEntry\getPerformerIdentity
getPerformerIdentity()
Definition: DatabaseLogEntry.php:210
Wikimedia\Rdbms\IDatabase\selectRow
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Wrapper to IDatabase::select() that only fetches one row (via LIMIT)
DatabaseLogEntry\__construct
__construct( $row)
Definition: DatabaseLogEntry.php:145
DatabaseLogEntry\$revId
int $revId
A rev id associated to the log entry.
Definition: DatabaseLogEntry.php:140
DatabaseLogEntry\$legacy
bool $legacy
Whether the parameters for this log entry are stored in new or old format.
Definition: DatabaseLogEntry.php:143
DatabaseLogEntry
A value class to process existing log entries.
Definition: DatabaseLogEntry.php:39
DatabaseLogEntry\isLegacy
isLegacy()
Whether the parameters for this log are stored in new or old format.
Definition: DatabaseLogEntry.php:167
DatabaseLogEntry\getTarget
getTarget()
Get the target page of this action.
Definition: DatabaseLogEntry.php:232
DatabaseLogEntry\$row
stdClass $row
Database result row.
Definition: DatabaseLogEntry.php:131
DatabaseLogEntry\getDeleted
getDeleted()
Get the access restriction.
Definition: DatabaseLogEntry.php:246
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
DatabaseLogEntry\getAssociatedRevId
getAssociatedRevId()
Definition: DatabaseLogEntry.php:204
DatabaseLogEntry\getRawParameters
getRawParameters()
Returns whatever is stored in the database field.
Definition: DatabaseLogEntry.php:163