MediaWiki REL1_35
DatabaseLogEntry.php
Go to the documentation of this file.
1<?php
27
37
45 public static function getSelectQueryData() {
46 $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
47 $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
48
49 $tables = array_merge(
50 [ 'logging' ], $commentQuery['tables'], $actorQuery['tables'], [ 'user' ]
51 );
52 $fields = [
53 'log_id', 'log_type', 'log_action', 'log_timestamp',
54 'log_namespace', 'log_title', // unused log_page
55 'log_params', 'log_deleted',
56 'user_id', 'user_name', 'user_editcount',
57 ] + $commentQuery['fields'] + $actorQuery['fields'];
58
59 $joins = [
60 // IPs don't have an entry in user table
61 'user' => [ 'LEFT JOIN', 'user_id=' . $actorQuery['fields']['log_user'] ],
62 ] + $commentQuery['joins'] + $actorQuery['joins'];
63
64 return [
65 'tables' => $tables,
66 'fields' => $fields,
67 'conds' => [],
68 'options' => [],
69 'join_conds' => $joins,
70 ];
71 }
72
80 public static function newFromRow( $row ) {
81 $row = (object)$row;
82 if ( isset( $row->rc_logid ) ) {
83 return new RCDatabaseLogEntry( $row );
84 } else {
85 return new self( $row );
86 }
87 }
88
96 public static function newFromId( $id, IDatabase $db ) {
97 $queryInfo = self::getSelectQueryData();
98 $queryInfo['conds'] += [ 'log_id' => $id ];
99 $row = $db->selectRow(
100 $queryInfo['tables'],
101 $queryInfo['fields'],
102 $queryInfo['conds'],
103 __METHOD__,
104 $queryInfo['options'],
105 $queryInfo['join_conds']
106 );
107 if ( !$row ) {
108 return null;
109 }
110 return self::newFromRow( $row );
111 }
112
114 protected $row;
115
117 protected $performer;
118
120 protected $params;
121
123 protected $revId = null;
124
126 protected $legacy;
127
128 protected function __construct( $row ) {
129 $this->row = $row;
130 }
131
137 public function getId() {
138 return (int)$this->row->log_id;
139 }
140
146 protected function getRawParameters() {
147 return $this->row->log_params;
148 }
149
150 public function isLegacy() {
151 // This extracts the property
152 $this->getParameters();
153 return $this->legacy;
154 }
155
156 public function getType() {
157 return $this->row->log_type;
158 }
159
160 public function getSubtype() {
161 return $this->row->log_action;
162 }
163
164 public function getParameters() {
165 if ( !isset( $this->params ) ) {
166 $blob = $this->getRawParameters();
167 Wikimedia\suppressWarnings();
169 Wikimedia\restoreWarnings();
170 if ( $params !== false ) {
171 $this->params = $params;
172 $this->legacy = false;
173 } else {
174 $this->params = LogPage::extractParams( $blob );
175 $this->legacy = true;
176 }
177
178 if ( isset( $this->params['associated_rev_id'] ) ) {
179 $this->revId = $this->params['associated_rev_id'];
180 unset( $this->params['associated_rev_id'] );
181 }
182 }
183
184 return $this->params;
185 }
186
187 public function getAssociatedRevId() {
188 // This extracts the property
189 $this->getParameters();
190 return $this->revId;
191 }
192
193 public function getPerformer() {
194 if ( !$this->performer ) {
195 $actorId = isset( $this->row->log_actor ) ? (int)$this->row->log_actor : 0;
196 $userId = (int)$this->row->log_user;
197 if ( $userId !== 0 || $actorId !== 0 ) {
198 // logged-in users
199 if ( isset( $this->row->user_name ) ) {
200 $this->performer = User::newFromRow( $this->row );
201 } elseif ( $actorId !== 0 ) {
202 $this->performer = User::newFromActorId( $actorId );
203 } else {
204 $this->performer = User::newFromId( $userId );
205 }
206 } else {
207 // IP users
208 $userText = $this->row->log_user_text;
209 $this->performer = User::newFromName( $userText, false );
210 }
211 }
212
213 return $this->performer;
214 }
215
216 public function getTarget() {
217 $namespace = $this->row->log_namespace;
218 $page = $this->row->log_title;
219 return Title::makeTitle( $namespace, $page );
220 }
221
222 public function getTimestamp() {
223 return wfTimestamp( TS_MW, $this->row->log_timestamp );
224 }
225
226 public function getComment() {
227 return CommentStore::getStore()->getComment( 'log_comment', $this->row )->text;
228 }
229
230 public function getDeleted() {
231 return $this->row->log_deleted;
232 }
233}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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.
getPerformer()
Get the user who performed this action.
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:426
A subclass of DatabaseLogEntry for objects constructed from entries in the recentchanges table (rathe...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:541
static newFromRow( $row, $data=null)
Create a new user object from a user row.
Definition User.php:717
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:565
static newFromActorId( $id)
Static factory method for creation from a given actor ID.
Definition User.php:580
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Wrapper to IDatabase::select() that only fetches one row (via LIMIT)