MediaWiki  master
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 }
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:562
RCDatabaseLogEntry
A subclass of DatabaseLogEntry for objects constructed from entries in the recentchanges table (rathe...
Definition: RCDatabaseLogEntry.php:34
DatabaseLogEntry\getId
getId()
Returns the unique database id.
Definition: DatabaseLogEntry.php:137
DatabaseLogEntry\$params
array $params
Parameters for log entry.
Definition: DatabaseLogEntry.php:120
LogPage\extractParams
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogPage.php:426
DatabaseLogEntry\getParameters
getParameters()
Get the extra parameters stored for this message.
Definition: DatabaseLogEntry.php:164
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1808
DatabaseLogEntry\getSelectQueryData
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition: DatabaseLogEntry.php:45
DatabaseLogEntry\newFromId
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
Definition: DatabaseLogEntry.php:96
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:538
DatabaseLogEntry\getComment
getComment()
Get the user provided comment.
Definition: DatabaseLogEntry.php:226
User\newFromRow
static newFromRow( $row, $data=null)
Create a new user object from a user row.
Definition: User.php:714
DatabaseLogEntry\getSubtype
getSubtype()
The log subtype.
Definition: DatabaseLogEntry.php:160
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:140
DatabaseLogEntry\getTimestamp
getTimestamp()
Get the timestamp when the action was executed.
Definition: DatabaseLogEntry.php:222
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:80
$blob
$blob
Definition: testCompression.php:70
DatabaseLogEntry\getType
getType()
The main log type.
Definition: DatabaseLogEntry.php:156
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
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
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:193
DatabaseLogEntry\__construct
__construct( $row)
Definition: DatabaseLogEntry.php:128
DatabaseLogEntry\$revId
int $revId
A rev id associated to the log entry.
Definition: DatabaseLogEntry.php:123
DatabaseLogEntry\$legacy
bool $legacy
Whether the parameters for this log entry are stored in new or old format.
Definition: DatabaseLogEntry.php:126
User\newFromActorId
static newFromActorId( $id)
Static factory method for creation from a given actor ID.
Definition: User.php:577
DatabaseLogEntry
A value class to process existing log entries.
Definition: DatabaseLogEntry.php:36
DatabaseLogEntry\isLegacy
isLegacy()
Whether the parameters for this log are stored in new or old format.
Definition: DatabaseLogEntry.php:150
DatabaseLogEntry\getTarget
getTarget()
Get the target page of this action.
Definition: DatabaseLogEntry.php:216
DatabaseLogEntry\$row
stdClass $row
Database result row.
Definition: DatabaseLogEntry.php:114
DatabaseLogEntry\getDeleted
getDeleted()
Get the access restriction.
Definition: DatabaseLogEntry.php:230
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:55
DatabaseLogEntry\getAssociatedRevId
getAssociatedRevId()
Definition: DatabaseLogEntry.php:187
DatabaseLogEntry\$performer
User $performer
Definition: DatabaseLogEntry.php:117
DatabaseLogEntry\getRawParameters
getRawParameters()
Returns whatever is stored in the database field.
Definition: DatabaseLogEntry.php:146