MediaWiki  1.23.6
LogEntry.php
Go to the documentation of this file.
1 <?php
35 interface LogEntry {
40  public function getType();
41 
46  public function getSubtype();
47 
52  public function getFullType();
53 
58  public function getParameters();
59 
64  public function getPerformer();
65 
70  public function getTarget();
71 
76  public function getTimestamp();
77 
82  public function getComment();
83 
88  public function getDeleted();
89 
94  public function isDeleted( $field );
95 }
96 
101 abstract class LogEntryBase implements LogEntry {
102  public function getFullType() {
103  return $this->getType() . '/' . $this->getSubtype();
104  }
105 
106  public function isDeleted( $field ) {
107  return ( $this->getDeleted() & $field ) === $field;
108  }
109 
115  public function isLegacy() {
116  return false;
117  }
118 }
119 
125  // Static->
126 
133  public static function getSelectQueryData() {
134  $tables = array( 'logging', 'user' );
135  $fields = array(
136  'log_id', 'log_type', 'log_action', 'log_timestamp',
137  'log_user', 'log_user_text',
138  'log_namespace', 'log_title', // unused log_page
139  'log_comment', 'log_params', 'log_deleted',
140  'user_id', 'user_name', 'user_editcount',
141  );
142 
143  $joins = array(
144  // IP's don't have an entry in user table
145  'user' => array( 'LEFT JOIN', 'log_user=user_id' ),
146  );
147 
148  return array(
149  'tables' => $tables,
150  'fields' => $fields,
151  'conds' => array(),
152  'options' => array(),
153  'join_conds' => $joins,
154  );
155  }
156 
163  public static function newFromRow( $row ) {
164  $row = (object)$row;
165  if ( isset( $row->rc_logid ) ) {
166  return new RCDatabaseLogEntry( $row );
167  } else {
168  return new self( $row );
169  }
170  }
171 
172  // Non-static->
173 
175  protected $row;
176 
178  protected $performer;
179 
183  protected $legacy;
184 
185  protected function __construct( $row ) {
186  $this->row = $row;
187  }
188 
193  public function getId() {
194  return (int)$this->row->log_id;
195  }
196 
201  protected function getRawParameters() {
202  return $this->row->log_params;
203  }
204 
205  // LogEntryBase->
206 
207  public function isLegacy() {
208  // This does the check
209  $this->getParameters();
210 
211  return $this->legacy;
212  }
213 
214  // LogEntry->
215 
216  public function getType() {
217  return $this->row->log_type;
218  }
219 
220  public function getSubtype() {
221  return $this->row->log_action;
222  }
223 
224  public function getParameters() {
225  if ( !isset( $this->params ) ) {
226  $blob = $this->getRawParameters();
228  $params = unserialize( $blob );
230  if ( $params !== false ) {
231  $this->params = $params;
232  $this->legacy = false;
233  } else {
234  $this->params = $blob === '' ? array() : explode( "\n", $blob );
235  $this->legacy = true;
236  }
237  }
238 
240  }
241 
242  public function getPerformer() {
243  if ( !$this->performer ) {
244  $userId = (int)$this->row->log_user;
245  if ( $userId !== 0 ) { // logged-in users
246  if ( isset( $this->row->user_name ) ) {
247  $this->performer = User::newFromRow( $this->row );
248  } else {
249  $this->performer = User::newFromId( $userId );
250  }
251  } else { // IP users
252  $userText = $this->row->log_user_text;
253  $this->performer = User::newFromName( $userText, false );
254  }
255  }
256 
258  }
259 
260  public function getTarget() {
261  $namespace = $this->row->log_namespace;
262  $page = $this->row->log_title;
263  $title = Title::makeTitle( $namespace, $page );
264 
265  return $title;
266  }
267 
268  public function getTimestamp() {
269  return wfTimestamp( TS_MW, $this->row->log_timestamp );
270  }
271 
272  public function getComment() {
273  return $this->row->log_comment;
274  }
275 
276  public function getDeleted() {
277  return $this->row->log_deleted;
278  }
279 }
280 
281 class RCDatabaseLogEntry extends DatabaseLogEntry {
282 
283  public function getId() {
284  return $this->row->rc_logid;
285  }
286 
287  protected function getRawParameters() {
288  return $this->row->rc_params;
289  }
290 
291  // LogEntry->
292 
293  public function getType() {
294  return $this->row->rc_log_type;
295  }
296 
297  public function getSubtype() {
298  return $this->row->rc_log_action;
299  }
300 
301  public function getPerformer() {
302  if ( !$this->performer ) {
303  $userId = (int)$this->row->rc_user;
304  if ( $userId !== 0 ) {
305  $this->performer = User::newFromId( $userId );
306  } else {
307  $userText = $this->row->rc_user_text;
308  // Might be an IP, don't validate the username
309  $this->performer = User::newFromName( $userText, false );
310  }
311  }
312 
314  }
315 
316  public function getTarget() {
317  $namespace = $this->row->rc_namespace;
318  $page = $this->row->rc_title;
319  $title = Title::makeTitle( $namespace, $page );
320 
321  return $title;
322  }
323 
324  public function getTimestamp() {
325  return wfTimestamp( TS_MW, $this->row->rc_timestamp );
326  }
327 
328  public function getComment() {
329  return $this->row->rc_comment;
330  }
331 
332  public function getDeleted() {
333  return $this->row->rc_deleted;
334  }
335 }
336 
344  protected $type;
345 
347  protected $subtype;
348 
350  protected $parameters = array();
351 
353  protected $relations = array();
354 
356  protected $performer;
357 
359  protected $target;
360 
362  protected $timestamp;
363 
365  protected $comment = '';
366 
368  protected $deleted;
369 
371  protected $id;
372 
381  public function __construct( $type, $subtype ) {
382  $this->type = $type;
383  $this->subtype = $subtype;
384  }
385 
402  public function setParameters( $parameters ) {
403  $this->parameters = $parameters;
404  }
405 
413  public function setRelations( array $relations ) {
414  $this->relations = $relations;
415  }
416 
424  public function setPerformer( User $performer ) {
425  $this->performer = $performer;
426  }
427 
435  public function setTarget( Title $target ) {
436  $this->target = $target;
437  }
438 
446  public function setTimestamp( $timestamp ) {
447  $this->timestamp = $timestamp;
448  }
449 
457  public function setComment( $comment ) {
458  $this->comment = $comment;
459  }
460 
468  public function setDeleted( $deleted ) {
469  $this->deleted = $deleted;
470  }
471 
478  public function insert( IDatabase $dbw = null ) {
480 
481  $dbw = $dbw ?: wfGetDB( DB_MASTER );
482  $id = $dbw->nextSequenceValue( 'logging_log_id_seq' );
483 
484  if ( $this->timestamp === null ) {
485  $this->timestamp = wfTimestampNow();
486  }
487 
488  # Trim spaces on user supplied text
489  $comment = trim( $this->getComment() );
490 
491  # Truncate for whole multibyte characters.
492  $comment = $wgContLang->truncate( $comment, 255 );
493 
494  $data = array(
495  'log_id' => $id,
496  'log_type' => $this->getType(),
497  'log_action' => $this->getSubtype(),
498  'log_timestamp' => $dbw->timestamp( $this->getTimestamp() ),
499  'log_user' => $this->getPerformer()->getId(),
500  'log_user_text' => $this->getPerformer()->getName(),
501  'log_namespace' => $this->getTarget()->getNamespace(),
502  'log_title' => $this->getTarget()->getDBkey(),
503  'log_page' => $this->getTarget()->getArticleID(),
504  'log_comment' => $comment,
505  'log_params' => serialize( (array)$this->getParameters() ),
506  );
507  $dbw->insert( 'logging', $data, __METHOD__ );
508  $this->id = !is_null( $id ) ? $id : $dbw->insertId();
509 
510  $rows = array();
511  foreach ( $this->relations as $tag => $values ) {
512  if ( !strlen( $tag ) ) {
513  throw new MWException( "Got empty log search tag." );
514  }
515  foreach ( $values as $value ) {
516  $rows[] = array(
517  'ls_field' => $tag,
518  'ls_value' => $value,
519  'ls_log_id' => $this->id
520  );
521  }
522  }
523  if ( count( $rows ) ) {
524  $dbw->insert( 'log_search', $rows, __METHOD__, 'IGNORE' );
525  }
526 
527  return $this->id;
528  }
529 
536  public function getRecentChange( $newId = 0 ) {
537  $formatter = LogFormatter::newFromEntry( $this );
538  $context = RequestContext::newExtraneousContext( $this->getTarget() );
539  $formatter->setContext( $context );
540 
541  $logpage = SpecialPage::getTitleFor( 'Log', $this->getType() );
542  $user = $this->getPerformer();
543  $ip = "";
544  if ( $user->isAnon() ) {
545  /*
546  * "MediaWiki default" and friends may have
547  * no IP address in their name
548  */
549  if ( IP::isIPAddress( $user->getName() ) ) {
550  $ip = $user->getName();
551  }
552  }
553 
555  $this->getTimestamp(),
556  $logpage,
557  $user,
558  $formatter->getPlainActionText(),
559  $ip,
560  $this->getType(),
561  $this->getSubtype(),
562  $this->getTarget(),
563  $this->getComment(),
564  serialize( (array)$this->getParameters() ),
565  $newId,
566  $formatter->getIRCActionComment() // Used for IRC feeds
567  );
568  }
569 
575  public function publish( $newId, $to = 'rcandudp' ) {
576  $log = new LogPage( $this->getType() );
577  if ( $log->isRestricted() ) {
578  return;
579  }
580 
581  $rc = $this->getRecentChange( $newId );
582 
583  if ( $to === 'rc' || $to === 'rcandudp' ) {
584  $rc->save( 'pleasedontudp' );
585  }
586 
587  if ( $to === 'udp' || $to === 'rcandudp' ) {
588  $rc->notifyRCFeeds();
589  }
590  }
591 
592  // LogEntry->
593 
594  public function getType() {
595  return $this->type;
596  }
597 
598  public function getSubtype() {
599  return $this->subtype;
600  }
601 
602  public function getParameters() {
604  }
605 
609  public function getPerformer() {
610  return $this->performer;
611  }
612 
616  public function getTarget() {
618  }
619 
620  public function getTimestamp() {
621  $ts = $this->timestamp !== null ? $this->timestamp : wfTimestampNow();
622 
623  return wfTimestamp( TS_MW, $ts );
624  }
625 
626  public function getComment() {
627  return $this->comment;
628  }
629 
630  public function getDeleted() {
631  return (int)$this->deleted;
632  }
633 }
ManualLogEntry\setTimestamp
setTimestamp( $timestamp)
Set the timestamp of when the logged action took place.
Definition: LogEntry.php:433
ManualLogEntry\__construct
__construct( $type, $subtype)
Constructor.
Definition: LogEntry.php:368
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
object
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 For a description of the see design txt $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
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:411
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
ManualLogEntry\getTarget
getTarget()
Definition: LogEntry.php:603
RCDatabaseLogEntry
Definition: LogEntry.php:278
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ManualLogEntry\$deleted
int $deleted
Deletion state of the log entry *.
Definition: LogEntry.php:356
ManualLogEntry\getType
getType()
The main log type.
Definition: LogEntry.php:581
$tables
namespace and then decline to actually register it RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:815
LogEntry\getTimestamp
getTimestamp()
Get the timestamp when the action was executed.
ManualLogEntry\insert
insert(IDatabase $dbw=null)
Inserts the entry into the logging table.
Definition: LogEntry.php:465
DatabaseLogEntry\getId
getId()
Returns the unique database id.
Definition: LogEntry.php:190
DatabaseLogEntry\getParameters
getParameters()
Get the extra parameters stored for this message.
Definition: LogEntry.php:221
LogEntry\getParameters
getParameters()
Get the extra parameters stored for this message.
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
LogEntry\isDeleted
isDeleted( $field)
ManualLogEntry\getParameters
getParameters()
Get the extra parameters stored for this message.
Definition: LogEntry.php:589
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2483
LogEntryBase\isLegacy
isLegacy()
Whether the parameters for this log are stored in new or old format.
Definition: LogEntry.php:115
DatabaseLogEntry\getSelectQueryData
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition: LogEntry.php:133
RCDatabaseLogEntry\getRawParameters
getRawParameters()
Returns whatever is stored in the database field.
Definition: LogEntry.php:284
RecentChange\newLogEntry
static newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
Definition: RecentChange.php:656
RCDatabaseLogEntry\getSubtype
getSubtype()
The log subtype.
Definition: LogEntry.php:294
LogEntry\getTarget
getTarget()
Get the target page of this action.
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
LogEntry\getComment
getComment()
Get the user provided comment.
$params
$params
Definition: styleTest.css.php:40
ManualLogEntry\getComment
getComment()
Get the user provided comment.
Definition: LogEntry.php:613
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
DatabaseLogEntry\getComment
getComment()
Get the user provided comment.
Definition: LogEntry.php:269
LogEntry\getFullType
getFullType()
The full logtype in format maintype/subtype.
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
ManualLogEntry\setRelations
setRelations(array $relations)
Declare arbitrary tag/value relations to this log entry.
Definition: LogEntry.php:400
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
ManualLogEntry\setTarget
setTarget(Title $target)
Set the title of the object changed.
Definition: LogEntry.php:422
User\newFromRow
static newFromRow( $row, $data=null)
Create a new user object from a user row.
Definition: User.php:470
DatabaseLogEntry\getSubtype
getSubtype()
The log subtype.
Definition: LogEntry.php:217
ManualLogEntry\getTimestamp
getTimestamp()
Get the timestamp when the action was executed.
Definition: LogEntry.php:607
DatabaseLogEntry\getTimestamp
getTimestamp()
Get the timestamp when the action was executed.
Definition: LogEntry.php:265
LogEntry\getType
getType()
The main log type.
RCDatabaseLogEntry\getId
getId()
Returns the unique database id.
Definition: LogEntry.php:280
RCDatabaseLogEntry\getTimestamp
getTimestamp()
Get the timestamp when the action was executed.
Definition: LogEntry.php:321
ManualLogEntry\$comment
string $comment
Comment for the log entry *.
Definition: LogEntry.php:354
ManualLogEntry\$parameters
array $parameters
Parameters for log entry *.
Definition: LogEntry.php:344
ManualLogEntry\getRecentChange
getRecentChange( $newId=0)
Get a RecentChanges object for the log entry.
Definition: LogEntry.php:523
RCDatabaseLogEntry\getTarget
getTarget()
Get the target page of this action.
Definition: LogEntry.php:313
MWException
MediaWiki exception.
Definition: MWException.php:26
DatabaseLogEntry\newFromRow
static newFromRow( $row)
Constructs new LogEntry from database result row.
Definition: LogEntry.php:163
ManualLogEntry\setComment
setComment( $comment)
Set a comment associated with the action being logged.
Definition: LogEntry.php:444
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
ManualLogEntry\$id
int $id
ID of the log entry *.
Definition: LogEntry.php:358
$blob
$blob
Definition: testCompression.php:61
LogEntry
Interface for log entries.
Definition: LogEntry.php:35
DatabaseLogEntry\getType
getType()
The main log type.
Definition: LogEntry.php:213
LogEntryBase\isDeleted
isDeleted( $field)
Definition: LogEntry.php:106
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:32
RequestContext\newExtraneousContext
static newExtraneousContext(Title $title, $request=array())
Create a new extraneous context.
Definition: RequestContext.php:535
RCDatabaseLogEntry\getComment
getComment()
Get the user provided comment.
Definition: LogEntry.php:325
ManualLogEntry\getSubtype
getSubtype()
The log subtype.
Definition: LogEntry.php:585
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2514
ManualLogEntry\$subtype
string $subtype
Sub type of log entry *.
Definition: LogEntry.php:342
ManualLogEntry\setParameters
setParameters( $parameters)
Set extra log parameters.
Definition: LogEntry.php:389
ManualLogEntry\publish
publish( $newId, $to='rcandudp')
Publishes the log entry.
Definition: LogEntry.php:562
ManualLogEntry\$relations
array $relations
Definition: LogEntry.php:346
LogEntryBase
Extends the LogEntryInterface with some basic functionality.
Definition: LogEntry.php:101
LogEntry\getDeleted
getDeleted()
Get the access restriction.
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2431
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$value
$value
Definition: styleTest.css.php:45
ManualLogEntry\setDeleted
setDeleted( $deleted)
TODO: document.
Definition: LogEntry.php:455
DatabaseLogEntry\getPerformer
getPerformer()
Get the user for performed this action.
Definition: LogEntry.php:239
ManualLogEntry\$timestamp
string $timestamp
Timestamp of creation of the log entry *.
Definition: LogEntry.php:352
LogEntryBase\getFullType
getFullType()
The full logtype in format maintype/subtype.
Definition: LogEntry.php:102
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
IDatabase
Interface for classes that implement or wrap DatabaseBase.
Definition: Database.php:212
RCDatabaseLogEntry\getType
getType()
The main log type.
Definition: LogEntry.php:290
LogEntry\getSubtype
getSubtype()
The log subtype.
ManualLogEntry\getPerformer
getPerformer()
Definition: LogEntry.php:596
Title
Represents a title within MediaWiki.
Definition: Title.php:35
type
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition: postgres.txt:22
ManualLogEntry\setPerformer
setPerformer(User $performer)
Set the user that performed the action being logged.
Definition: LogEntry.php:411
DatabaseLogEntry\__construct
__construct( $row)
Definition: LogEntry.php:182
DatabaseLogEntry\$legacy
bool $legacy
Whether the parameters for this log entry are stored in new or old format.
Definition: LogEntry.php:180
ManualLogEntry\getDeleted
getDeleted()
Get the access restriction.
Definition: LogEntry.php:617
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
DatabaseLogEntry
This class wraps around database result row.
Definition: LogEntry.php:124
DatabaseLogEntry\isLegacy
isLegacy()
Whether the parameters for this log are stored in new or old format.
Definition: LogEntry.php:204
ManualLogEntry\$target
Title $target
Target title for the log entry *.
Definition: LogEntry.php:350
ManualLogEntry
Class for creating log entries manually, for example to inject them into the database.
Definition: LogEntry.php:339
RCDatabaseLogEntry\getPerformer
getPerformer()
Get the user for performed this action.
Definition: LogEntry.php:298
DatabaseLogEntry\getTarget
getTarget()
Get the target page of this action.
Definition: LogEntry.php:257
DatabaseLogEntry\$row
stdClass $row
Database result row.
Definition: LogEntry.php:174
RCDatabaseLogEntry\getDeleted
getDeleted()
Get the access restriction.
Definition: LogEntry.php:329
DatabaseLogEntry\getDeleted
getDeleted()
Get the access restriction.
Definition: LogEntry.php:273
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
LogEntry\getPerformer
getPerformer()
Get the user for performed this action.
DatabaseLogEntry\$performer
User $performer
Definition: LogEntry.php:176
DatabaseLogEntry\getRawParameters
getRawParameters()
Returns whatever is stored in the database field.
Definition: LogEntry.php:198
ManualLogEntry\$type
string $type
Type of log entry *.
Definition: LogEntry.php:340
if
if(!function_exists('version_compare')||version_compare(phpversion(), '5.3.2')< 0)
Definition: api.php:37
ManualLogEntry\$performer
User $performer
Performer of the action for the log entry *.
Definition: LogEntry.php:348
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:74
LogFormatter\newFromEntry
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Definition: LogFormatter.php:45