MediaWiki  master
DatabaseLogEntry.php
Go to the documentation of this file.
1 <?php
27 
35 
43  public static function getSelectQueryData() {
44  $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
45  $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
46 
47  $tables = array_merge(
48  [ 'logging' ], $commentQuery['tables'], $actorQuery['tables'], [ 'user' ]
49  );
50  $fields = [
51  'log_id', 'log_type', 'log_action', 'log_timestamp',
52  'log_namespace', 'log_title', // unused log_page
53  'log_params', 'log_deleted',
54  'user_id', 'user_name', 'user_editcount',
55  ] + $commentQuery['fields'] + $actorQuery['fields'];
56 
57  $joins = [
58  // IPs don't have an entry in user table
59  'user' => [ 'LEFT JOIN', 'user_id=' . $actorQuery['fields']['log_user'] ],
60  ] + $commentQuery['joins'] + $actorQuery['joins'];
61 
62  return [
63  'tables' => $tables,
64  'fields' => $fields,
65  'conds' => [],
66  'options' => [],
67  'join_conds' => $joins,
68  ];
69  }
70 
78  public static function newFromRow( $row ) {
79  $row = (object)$row;
80  if ( isset( $row->rc_logid ) ) {
81  return new RCDatabaseLogEntry( $row );
82  } else {
83  return new self( $row );
84  }
85  }
86 
94  public static function newFromId( $id, IDatabase $db ) {
95  $queryInfo = self::getSelectQueryData();
96  $queryInfo['conds'] += [ 'log_id' => $id ];
97  $row = $db->selectRow(
98  $queryInfo['tables'],
99  $queryInfo['fields'],
100  $queryInfo['conds'],
101  __METHOD__,
102  $queryInfo['options'],
103  $queryInfo['join_conds']
104  );
105  if ( !$row ) {
106  return null;
107  }
108  return self::newFromRow( $row );
109  }
110 
112  protected $row;
113 
115  protected $performer;
116 
118  protected $params;
119 
121  protected $revId = null;
122 
124  protected $legacy;
125 
126  protected function __construct( $row ) {
127  $this->row = $row;
128  }
129 
135  public function getId() {
136  return (int)$this->row->log_id;
137  }
138 
144  protected function getRawParameters() {
145  return $this->row->log_params;
146  }
147 
148  public function isLegacy() {
149  // This extracts the property
150  $this->getParameters();
151  return $this->legacy;
152  }
153 
154  public function getType() {
155  return $this->row->log_type;
156  }
157 
158  public function getSubtype() {
159  return $this->row->log_action;
160  }
161 
162  public function getParameters() {
163  if ( !isset( $this->params ) ) {
164  $blob = $this->getRawParameters();
165  Wikimedia\suppressWarnings();
167  Wikimedia\restoreWarnings();
168  if ( $params !== false ) {
169  $this->params = $params;
170  $this->legacy = false;
171  } else {
172  $this->params = LogPage::extractParams( $blob );
173  $this->legacy = true;
174  }
175 
176  if ( isset( $this->params['associated_rev_id'] ) ) {
177  $this->revId = $this->params['associated_rev_id'];
178  unset( $this->params['associated_rev_id'] );
179  }
180  }
181 
182  return $this->params;
183  }
184 
185  public function getAssociatedRevId() {
186  // This extracts the property
187  $this->getParameters();
188  return $this->revId;
189  }
190 
191  public function getPerformer() {
192  if ( !$this->performer ) {
193  $actorId = isset( $this->row->log_actor ) ? (int)$this->row->log_actor : 0;
194  $userId = (int)$this->row->log_user;
195  if ( $userId !== 0 || $actorId !== 0 ) {
196  // logged-in users
197  if ( isset( $this->row->user_name ) ) {
198  $this->performer = User::newFromRow( $this->row );
199  } elseif ( $actorId !== 0 ) {
200  $this->performer = User::newFromActorId( $actorId );
201  } else {
202  $this->performer = User::newFromId( $userId );
203  }
204  } else {
205  // IP users
206  $userText = $this->row->log_user_text;
207  $this->performer = User::newFromName( $userText, false );
208  }
209  }
210 
211  return $this->performer;
212  }
213 
214  public function getTarget() {
215  $namespace = $this->row->log_namespace;
216  $page = $this->row->log_title;
217  return Title::makeTitle( $namespace, $page );
218  }
219 
220  public function getTimestamp() {
221  return wfTimestamp( TS_MW, $this->row->log_timestamp );
222  }
223 
224  public function getComment() {
225  return CommentStore::getStore()->getComment( 'log_comment', $this->row )->text;
226  }
227 
228  public function getDeleted() {
229  return $this->row->log_deleted;
230  }
231 }
static newFromId( $id, IDatabase $db)
Loads a LogEntry with the given id from database.
getTarget()
Get the target page of this action.
getSubtype()
The log subtype.
getTimestamp()
Get the timestamp when the action was executed.
A subclass of DatabaseLogEntry for objects constructed from entries in the recentchanges table (rathe...
getType()
The main log type.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newFromRow( $row)
Constructs new LogEntry from database result row.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
static newFromActorId( $id)
Static factory method for creation from a given actor ID.
Definition: User.php:633
array $params
Parameters for log entry.
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition: hooks.txt:979
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
Single row SELECT wrapper.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static newMigration()
Static constructor.
getParameters()
Get the extra parameters stored for this message.
getPerformer()
Get the user for performed this action.
bool $legacy
Whether the parameters for this log entry are stored in new or old format.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
getDeleted()
Get the access restriction.
getComment()
Get the user provided comment.
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
int $revId
A rev id associated to the log entry.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:589
static extractParams( $blob)
Extract a parameter array from a blob.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:618
getRawParameters()
Returns whatever is stored in the database field.
static getStore()
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
stdClass $row
Database result row.
Extends the LogEntry Interface with some basic functionality.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
Definition: User.php:790
getId()
Returns the unique database id.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:594
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogPage.php:427
A value class to process existing log entries.