MediaWiki  master
DatabaseLogEntry.php
Go to the documentation of this file.
1 <?php
29 
39 
51  public static function getSelectQueryData() {
52  $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
53 
54  $tables = array_merge(
55  [
56  'logging',
57  'logging_actor' => 'actor',
58  'user'
59  ],
60  $commentQuery['tables']
61  );
62  $fields = [
63  'log_id', 'log_type', 'log_action', 'log_timestamp',
64  'log_namespace', 'log_title', // unused log_page
65  'log_params', 'log_deleted',
66  'user_id',
67  'user_name',
68  'user_editcount',
69  'log_actor',
70  'log_user' => 'logging_actor.actor_user',
71  'log_user_text' => 'logging_actor.actor_name'
72  ] + $commentQuery['fields'];
73 
74  $joins = [
75  'logging_actor' => [ 'JOIN', 'actor_id=log_actor' ],
76  // IPs don't have an entry in user table
77  'user' => [ 'LEFT JOIN', 'user_id=logging_actor.actor_user' ],
78  ] + $commentQuery['joins'];
79 
80  return [
81  'tables' => $tables,
82  'fields' => $fields,
83  'conds' => [],
84  'options' => [],
85  'join_conds' => $joins,
86  ];
87  }
88 
96  public static function newFromRow( $row ) {
97  $row = (object)$row;
98  if ( isset( $row->rc_logid ) ) {
99  return new RCDatabaseLogEntry( $row );
100  } else {
101  return new self( $row );
102  }
103  }
104 
112  public static function newFromId( $id, IDatabase $db ) {
113  $queryInfo = self::getSelectQueryData();
114  $queryInfo['conds'] += [ 'log_id' => $id ];
115  $row = $db->selectRow(
116  $queryInfo['tables'],
117  $queryInfo['fields'],
118  $queryInfo['conds'],
119  __METHOD__,
120  $queryInfo['options'],
121  $queryInfo['join_conds']
122  );
123  if ( !$row ) {
124  return null;
125  }
126  return self::newFromRow( $row );
127  }
128 
130  protected $row;
131 
133  protected $performer;
134 
136  protected $params;
137 
139  protected $revId = null;
140 
142  protected $legacy;
143 
144  protected function __construct( $row ) {
145  $this->row = $row;
146  }
147 
153  public function getId() {
154  return (int)$this->row->log_id;
155  }
156 
162  protected function getRawParameters() {
163  return $this->row->log_params;
164  }
165 
166  public function isLegacy() {
167  // This extracts the property
168  $this->getParameters();
169  return $this->legacy;
170  }
171 
172  public function getType() {
173  return $this->row->log_type;
174  }
175 
176  public function getSubtype() {
177  return $this->row->log_action;
178  }
179 
180  public function getParameters() {
181  if ( !isset( $this->params ) ) {
182  $blob = $this->getRawParameters();
183  Wikimedia\suppressWarnings();
185  Wikimedia\restoreWarnings();
186  if ( $params !== false ) {
187  $this->params = $params;
188  $this->legacy = false;
189  } else {
190  $this->params = LogPage::extractParams( $blob );
191  $this->legacy = true;
192  }
193 
194  if ( isset( $this->params['associated_rev_id'] ) ) {
195  $this->revId = $this->params['associated_rev_id'];
196  unset( $this->params['associated_rev_id'] );
197  }
198  }
199 
200  return $this->params;
201  }
202 
203  public function getAssociatedRevId() {
204  // This extracts the property
205  $this->getParameters();
206  return $this->revId;
207  }
208 
209  protected function getPerformerUser(): User {
210  if ( !$this->performer ) {
211  $this->performer = MediaWikiServices::getInstance()->getUserFactory()
212  ->newFromAnyId(
213  $this->row->user_id ?? 0, // left join failure means anonymous
214  $this->row->log_user_text,
215  $this->row->log_actor
216  );
217  }
218 
219  return $this->performer;
220  }
221 
222  public function getPerformer() {
223  wfDeprecated( __METHOD__, '1.36' );
224  return $this->getPerformerUser();
225  }
226 
227  public function getPerformerIdentity(): UserIdentity {
228  return $this->getPerformerUser();
229  }
230 
231  public function getTarget() {
232  $namespace = $this->row->log_namespace;
233  $page = $this->row->log_title;
234  return Title::makeTitle( $namespace, $page );
235  }
236 
237  public function getTimestamp() {
238  return wfTimestamp( TS_MW, $this->row->log_timestamp );
239  }
240 
241  public function getComment() {
242  return CommentStore::getStore()->getComment( 'log_comment', $this->row )->text;
243  }
244 
245  public function getDeleted() {
246  return $this->row->log_deleted;
247  }
248 }
RCDatabaseLogEntry
A subclass of DatabaseLogEntry for objects constructed from entries in the recentchanges table (rathe...
Definition: RCDatabaseLogEntry.php:35
DatabaseLogEntry\getId
getId()
Returns the unique database id.
Definition: DatabaseLogEntry.php:153
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:180
DatabaseLogEntry\$params
array $params
Parameters for log entry.
Definition: DatabaseLogEntry.php:136
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:180
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1692
DatabaseLogEntry\getSelectQueryData
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition: DatabaseLogEntry.php:51
DatabaseLogEntry\newFromId
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
Definition: DatabaseLogEntry.php:112
DatabaseLogEntry\getComment
getComment()
Get the user provided comment.
Definition: DatabaseLogEntry.php:241
DatabaseLogEntry\getSubtype
getSubtype()
The log subtype.
Definition: DatabaseLogEntry.php:176
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:237
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:96
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:996
$blob
$blob
Definition: testCompression.php:70
DatabaseLogEntry\getType
getType()
The main log type.
Definition: DatabaseLogEntry.php:172
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
User\newFromAnyId
static newFromAnyId( $userId, $userName, $actorId, $dbDomain=false)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:695
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:227
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\getPerformer
getPerformer()
Get the user who performed this action.
Definition: DatabaseLogEntry.php:222
DatabaseLogEntry\__construct
__construct( $row)
Definition: DatabaseLogEntry.php:144
DatabaseLogEntry\$revId
int $revId
A rev id associated to the log entry.
Definition: DatabaseLogEntry.php:139
DatabaseLogEntry\$legacy
bool $legacy
Whether the parameters for this log entry are stored in new or old format.
Definition: DatabaseLogEntry.php:142
DatabaseLogEntry
A value class to process existing log entries.
Definition: DatabaseLogEntry.php:38
DatabaseLogEntry\isLegacy
isLegacy()
Whether the parameters for this log are stored in new or old format.
Definition: DatabaseLogEntry.php:166
DatabaseLogEntry\getTarget
getTarget()
Get the target page of this action.
Definition: DatabaseLogEntry.php:231
DatabaseLogEntry\$row
stdClass $row
Database result row.
Definition: DatabaseLogEntry.php:130
DatabaseLogEntry\getPerformerUser
getPerformerUser()
Definition: DatabaseLogEntry.php:209
DatabaseLogEntry\getDeleted
getDeleted()
Get the access restriction.
Definition: DatabaseLogEntry.php:245
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:67
DatabaseLogEntry\getAssociatedRevId
getAssociatedRevId()
Definition: DatabaseLogEntry.php:203
DatabaseLogEntry\$performer
User $performer
Definition: DatabaseLogEntry.php:133
DatabaseLogEntry\getRawParameters
getRawParameters()
Returns whatever is stored in the database field.
Definition: DatabaseLogEntry.php:162