MediaWiki REL1_30
LogEntry.php
Go to the documentation of this file.
1<?php
32
38interface LogEntry {
39
45 public function getType();
46
52 public function getSubtype();
53
59 public function getFullType();
60
66 public function getParameters();
67
73 public function getPerformer();
74
80 public function getTarget();
81
87 public function getTimestamp();
88
94 public function getComment();
95
101 public function getDeleted();
102
107 public function isDeleted( $field );
108}
109
115abstract class LogEntryBase implements LogEntry {
116
117 public function getFullType() {
118 return $this->getType() . '/' . $this->getSubtype();
119 }
120
121 public function isDeleted( $field ) {
122 return ( $this->getDeleted() & $field ) === $field;
123 }
124
131 public function isLegacy() {
132 return false;
133 }
134
142 public static function makeParamBlob( $params ) {
143 return serialize( (array)$params );
144 }
145
153 public static function extractParams( $blob ) {
154 return unserialize( $blob );
155 }
156}
157
164
172 public static function getSelectQueryData() {
173 $commentQuery = CommentStore::newKey( 'log_comment' )->getJoin();
174
175 $tables = [ 'logging', 'user' ] + $commentQuery['tables'];
176 $fields = [
177 'log_id', 'log_type', 'log_action', 'log_timestamp',
178 'log_user', 'log_user_text',
179 'log_namespace', 'log_title', // unused log_page
180 'log_params', 'log_deleted',
181 'user_id', 'user_name', 'user_editcount',
182 ] + $commentQuery['fields'];
183
184 $joins = [
185 // IPs don't have an entry in user table
186 'user' => [ 'LEFT JOIN', 'log_user=user_id' ],
187 ] + $commentQuery['joins'];
188
189 return [
190 'tables' => $tables,
191 'fields' => $fields,
192 'conds' => [],
193 'options' => [],
194 'join_conds' => $joins,
195 ];
196 }
197
205 public static function newFromRow( $row ) {
206 $row = (object)$row;
207 if ( isset( $row->rc_logid ) ) {
208 return new RCDatabaseLogEntry( $row );
209 } else {
210 return new self( $row );
211 }
212 }
213
215 protected $row;
216
218 protected $performer;
219
221 protected $params;
222
224 protected $revId = null;
225
227 protected $legacy;
228
229 protected function __construct( $row ) {
230 $this->row = $row;
231 }
232
238 public function getId() {
239 return (int)$this->row->log_id;
240 }
241
247 protected function getRawParameters() {
248 return $this->row->log_params;
249 }
250
251 public function isLegacy() {
252 // This extracts the property
253 $this->getParameters();
254 return $this->legacy;
255 }
256
257 public function getType() {
258 return $this->row->log_type;
259 }
260
261 public function getSubtype() {
262 return $this->row->log_action;
263 }
264
265 public function getParameters() {
266 if ( !isset( $this->params ) ) {
267 $blob = $this->getRawParameters();
268 MediaWiki\suppressWarnings();
270 MediaWiki\restoreWarnings();
271 if ( $params !== false ) {
272 $this->params = $params;
273 $this->legacy = false;
274 } else {
275 $this->params = LogPage::extractParams( $blob );
276 $this->legacy = true;
277 }
278
279 if ( isset( $this->params['associated_rev_id'] ) ) {
280 $this->revId = $this->params['associated_rev_id'];
281 unset( $this->params['associated_rev_id'] );
282 }
283 }
284
285 return $this->params;
286 }
287
288 public function getAssociatedRevId() {
289 // This extracts the property
290 $this->getParameters();
291 return $this->revId;
292 }
293
294 public function getPerformer() {
295 if ( !$this->performer ) {
296 $userId = (int)$this->row->log_user;
297 if ( $userId !== 0 ) {
298 // logged-in users
299 if ( isset( $this->row->user_name ) ) {
300 $this->performer = User::newFromRow( $this->row );
301 } else {
302 $this->performer = User::newFromId( $userId );
303 }
304 } else {
305 // IP users
306 $userText = $this->row->log_user_text;
307 $this->performer = User::newFromName( $userText, false );
308 }
309 }
310
311 return $this->performer;
312 }
313
314 public function getTarget() {
315 $namespace = $this->row->log_namespace;
316 $page = $this->row->log_title;
317 $title = Title::makeTitle( $namespace, $page );
318
319 return $title;
320 }
321
322 public function getTimestamp() {
323 return wfTimestamp( TS_MW, $this->row->log_timestamp );
324 }
325
326 public function getComment() {
327 return CommentStore::newKey( 'log_comment' )->getComment( $this->row )->text;
328 }
329
330 public function getDeleted() {
331 return $this->row->log_deleted;
332 }
333}
334
336
337 public function getId() {
338 return $this->row->rc_logid;
339 }
340
341 protected function getRawParameters() {
342 return $this->row->rc_params;
343 }
344
345 public function getAssociatedRevId() {
346 return $this->row->rc_this_oldid;
347 }
348
349 public function getType() {
350 return $this->row->rc_log_type;
351 }
352
353 public function getSubtype() {
354 return $this->row->rc_log_action;
355 }
356
357 public function getPerformer() {
358 if ( !$this->performer ) {
359 $userId = (int)$this->row->rc_user;
360 if ( $userId !== 0 ) {
361 $this->performer = User::newFromId( $userId );
362 } else {
363 $userText = $this->row->rc_user_text;
364 // Might be an IP, don't validate the username
365 $this->performer = User::newFromName( $userText, false );
366 }
367 }
368
369 return $this->performer;
370 }
371
372 public function getTarget() {
373 $namespace = $this->row->rc_namespace;
374 $page = $this->row->rc_title;
375 $title = Title::makeTitle( $namespace, $page );
376
377 return $title;
378 }
379
380 public function getTimestamp() {
381 return wfTimestamp( TS_MW, $this->row->rc_timestamp );
382 }
383
384 public function getComment() {
385 return CommentStore::newKey( 'rc_comment' )
386 // Legacy because the row probably used RecentChange::selectFields()
387 ->getCommentLegacy( wfGetDB( DB_REPLICA ), $this->row )->text;
388 }
389
390 public function getDeleted() {
391 return $this->row->rc_deleted;
392 }
393}
394
402 protected $type;
403
405 protected $subtype;
406
408 protected $parameters = [];
409
411 protected $relations = [];
412
414 protected $performer;
415
417 protected $target;
418
420 protected $timestamp;
421
423 protected $comment = '';
424
426 protected $revId = 0;
427
429 protected $tags = null;
430
432 protected $deleted;
433
435 protected $id;
436
438 protected $isPatrollable = false;
439
441 protected $legacy = false;
442
448 public function __construct( $type, $subtype ) {
449 $this->type = $type;
450 $this->subtype = $subtype;
451 }
452
474 public function setParameters( $parameters ) {
475 $this->parameters = $parameters;
476 }
477
485 public function setRelations( array $relations ) {
486 $this->relations = $relations;
487 }
488
495 public function setPerformer( User $performer ) {
496 $this->performer = $performer;
497 }
498
505 public function setTarget( Title $target ) {
506 $this->target = $target;
507 }
508
515 public function setTimestamp( $timestamp ) {
516 $this->timestamp = $timestamp;
517 }
518
525 public function setComment( $comment ) {
526 $this->comment = $comment;
527 }
528
538 public function setAssociatedRevId( $revId ) {
539 $this->revId = $revId;
540 }
541
548 public function setTags( $tags ) {
549 if ( is_string( $tags ) ) {
550 $tags = [ $tags ];
551 }
552 $this->tags = $tags;
553 }
554
564 public function setIsPatrollable( $patrollable ) {
565 $this->isPatrollable = (bool)$patrollable;
566 }
567
574 public function setLegacy( $legacy ) {
575 $this->legacy = $legacy;
576 }
577
584 public function setDeleted( $deleted ) {
585 $this->deleted = $deleted;
586 }
587
595 public function insert( IDatabase $dbw = null ) {
596 $dbw = $dbw ?: wfGetDB( DB_MASTER );
597
598 if ( $this->timestamp === null ) {
599 $this->timestamp = wfTimestampNow();
600 }
601
602 // Trim spaces on user supplied text
603 $comment = trim( $this->getComment() );
604
605 $params = $this->getParameters();
607
608 // Additional fields for which there's no space in the database table schema
609 $revId = $this->getAssociatedRevId();
610 if ( $revId ) {
611 $params['associated_rev_id'] = $revId;
612 $relations['associated_rev_id'] = $revId;
613 }
614
615 $data = [
616 'log_type' => $this->getType(),
617 'log_action' => $this->getSubtype(),
618 'log_timestamp' => $dbw->timestamp( $this->getTimestamp() ),
619 'log_user' => $this->getPerformer()->getId(),
620 'log_user_text' => $this->getPerformer()->getName(),
621 'log_namespace' => $this->getTarget()->getNamespace(),
622 'log_title' => $this->getTarget()->getDBkey(),
623 'log_page' => $this->getTarget()->getArticleID(),
624 'log_params' => LogEntryBase::makeParamBlob( $params ),
625 ];
626 if ( isset( $this->deleted ) ) {
627 $data['log_deleted'] = $this->deleted;
628 }
629 $data += CommentStore::newKey( 'log_comment' )->insert( $dbw, $comment );
630
631 $dbw->insert( 'logging', $data, __METHOD__ );
632 $this->id = $dbw->insertId();
633
634 $rows = [];
635 foreach ( $relations as $tag => $values ) {
636 if ( !strlen( $tag ) ) {
637 throw new MWException( "Got empty log search tag." );
638 }
639
640 if ( !is_array( $values ) ) {
641 $values = [ $values ];
642 }
643
644 foreach ( $values as $value ) {
645 $rows[] = [
646 'ls_field' => $tag,
647 'ls_value' => $value,
648 'ls_log_id' => $this->id
649 ];
650 }
651 }
652 if ( count( $rows ) ) {
653 $dbw->insert( 'log_search', $rows, __METHOD__, 'IGNORE' );
654 }
655
656 return $this->id;
657 }
658
666 public function getRecentChange( $newId = 0 ) {
667 $formatter = LogFormatter::newFromEntry( $this );
669 $formatter->setContext( $context );
670
671 $logpage = SpecialPage::getTitleFor( 'Log', $this->getType() );
672 $user = $this->getPerformer();
673 $ip = "";
674 if ( $user->isAnon() ) {
675 // "MediaWiki default" and friends may have
676 // no IP address in their name
677 if ( IP::isIPAddress( $user->getName() ) ) {
678 $ip = $user->getName();
679 }
680 }
681
683 $this->getTimestamp(),
684 $logpage,
685 $user,
686 $formatter->getPlainActionText(),
687 $ip,
688 $this->getType(),
689 $this->getSubtype(),
690 $this->getTarget(),
691 $this->getComment(),
692 LogEntryBase::makeParamBlob( $this->getParameters() ),
693 $newId,
694 $formatter->getIRCActionComment(), // Used for IRC feeds
695 $this->getAssociatedRevId(), // Used for e.g. moves and uploads
696 $this->getIsPatrollable()
697 );
698 }
699
706 public function publish( $newId, $to = 'rcandudp' ) {
707 DeferredUpdates::addCallableUpdate(
708 function () use ( $newId, $to ) {
709 $log = new LogPage( $this->getType() );
710 if ( !$log->isRestricted() ) {
711 $rc = $this->getRecentChange( $newId );
712
713 if ( $to === 'rc' || $to === 'rcandudp' ) {
714 // save RC, passing tags so they are applied there
715 $tags = $this->getTags();
716 if ( is_null( $tags ) ) {
717 $tags = [];
718 }
719 $rc->addTags( $tags );
720 $rc->save( 'pleasedontudp' );
721 }
722
723 if ( $to === 'udp' || $to === 'rcandudp' ) {
724 $rc->notifyRCFeeds();
725 }
726
727 // Log the autopatrol if the log entry is patrollable
728 if ( $this->getIsPatrollable() &&
729 $rc->getAttribute( 'rc_patrolled' ) === 1
730 ) {
731 PatrolLog::record( $rc, true, $this->getPerformer() );
732 }
733 }
734 },
735 DeferredUpdates::POSTSEND,
737 );
738 }
739
740 public function getType() {
741 return $this->type;
742 }
743
744 public function getSubtype() {
745 return $this->subtype;
746 }
747
748 public function getParameters() {
749 return $this->parameters;
750 }
751
755 public function getPerformer() {
756 return $this->performer;
757 }
758
762 public function getTarget() {
763 return $this->target;
764 }
765
766 public function getTimestamp() {
767 $ts = $this->timestamp !== null ? $this->timestamp : wfTimestampNow();
768
769 return wfTimestamp( TS_MW, $ts );
770 }
771
772 public function getComment() {
773 return $this->comment;
774 }
775
780 public function getAssociatedRevId() {
781 return $this->revId;
782 }
783
788 public function getTags() {
789 return $this->tags;
790 }
791
798 public function getIsPatrollable() {
800 }
801
806 public function isLegacy() {
807 return $this->legacy;
808 }
809
810 public function getDeleted() {
811 return (int)$this->deleted;
812 }
813}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
serialize()
unserialize( $serialized)
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static newKey( $key)
Static constructor for easier chaining.
This class wraps around database result row.
Definition LogEntry.php:163
getParameters()
Get the extra parameters stored for this message.
Definition LogEntry.php:265
isLegacy()
Whether the parameters for this log are stored in new or old format.
Definition LogEntry.php:251
array $params
Parameters for log entry.
Definition LogEntry.php:221
getSubtype()
The log subtype.
Definition LogEntry.php:261
getDeleted()
Get the access restriction.
Definition LogEntry.php:330
static newFromRow( $row)
Constructs new LogEntry from database result row.
Definition LogEntry.php:205
getComment()
Get the user provided comment.
Definition LogEntry.php:326
bool $legacy
Whether the parameters for this log entry are stored in new or old format.
Definition LogEntry.php:227
int $revId
A rev id associated to the log entry.
Definition LogEntry.php:224
getRawParameters()
Returns whatever is stored in the database field.
Definition LogEntry.php:247
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition LogEntry.php:172
stdClass $row
Database result row.
Definition LogEntry.php:215
getId()
Returns the unique database id.
Definition LogEntry.php:238
getPerformer()
Get the user for performed this action.
Definition LogEntry.php:294
getTarget()
Get the target page of this action.
Definition LogEntry.php:314
getType()
The main log type.
Definition LogEntry.php:257
getTimestamp()
Get the timestamp when the action was executed.
Definition LogEntry.php:322
Extends the LogEntryInterface with some basic functionality.
Definition LogEntry.php:115
isDeleted( $field)
Definition LogEntry.php:121
isLegacy()
Whether the parameters for this log are stored in new or old format.
Definition LogEntry.php:131
static extractParams( $blob)
Extract a parameter array from a blob.
Definition LogEntry.php:153
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition LogEntry.php:142
getFullType()
The full logtype in format maintype/subtype.
Definition LogEntry.php:117
static newFromEntry(LogEntry $entry)
Constructs a new formatter suitable for given entry.
Class to simplify the use of log pages.
Definition LogPage.php:31
static extractParams( $blob)
Extract a parameter array from a blob.
Definition LogPage.php:419
MediaWiki exception.
Class for creating log entries manually, to inject them into the database.
Definition LogEntry.php:400
getDeleted()
Get the access restriction.
Definition LogEntry.php:810
getIsPatrollable()
Whether this log entry is patrollable.
Definition LogEntry.php:798
setDeleted( $deleted)
Set the 'deleted' flag.
Definition LogEntry.php:584
string $subtype
Sub type of log entry.
Definition LogEntry.php:405
int $id
ID of the log entry.
Definition LogEntry.php:435
string $type
Type of log entry.
Definition LogEntry.php:402
setTarget(Title $target)
Set the title of the object changed.
Definition LogEntry.php:505
setAssociatedRevId( $revId)
Set an associated revision id.
Definition LogEntry.php:538
insert(IDatabase $dbw=null)
Insert the entry into the logging table.
Definition LogEntry.php:595
string $comment
Comment for the log entry.
Definition LogEntry.php:423
setTimestamp( $timestamp)
Set the timestamp of when the logged action took place.
Definition LogEntry.php:515
array $parameters
Parameters for log entry.
Definition LogEntry.php:408
getTimestamp()
Get the timestamp when the action was executed.
Definition LogEntry.php:766
int $revId
A rev id associated to the log entry.
Definition LogEntry.php:426
setComment( $comment)
Set a comment associated with the action being logged.
Definition LogEntry.php:525
setParameters( $parameters)
Set extra log parameters.
Definition LogEntry.php:474
getComment()
Get the user provided comment.
Definition LogEntry.php:772
bool $isPatrollable
Can this log entry be patrolled?
Definition LogEntry.php:438
getType()
The main log type.
Definition LogEntry.php:740
Title $target
Target title for the log entry.
Definition LogEntry.php:417
int $deleted
Deletion state of the log entry.
Definition LogEntry.php:432
setLegacy( $legacy)
Set the 'legacy' flag.
Definition LogEntry.php:574
setIsPatrollable( $patrollable)
Set whether this log entry should be made patrollable This shouldn't depend on config,...
Definition LogEntry.php:564
getParameters()
Get the extra parameters stored for this message.
Definition LogEntry.php:748
bool $legacy
Whether this is a legacy log entry.
Definition LogEntry.php:441
string $timestamp
Timestamp of creation of the log entry.
Definition LogEntry.php:420
getRecentChange( $newId=0)
Get a RecentChanges object for the log entry.
Definition LogEntry.php:666
User $performer
Performer of the action for the log entry.
Definition LogEntry.php:414
setRelations(array $relations)
Declare arbitrary tag/value relations to this log entry.
Definition LogEntry.php:485
setPerformer(User $performer)
Set the user that performed the action being logged.
Definition LogEntry.php:495
__construct( $type, $subtype)
Definition LogEntry.php:448
setTags( $tags)
Set change tags for the log entry.
Definition LogEntry.php:548
array $tags
Change tags add to the log entry.
Definition LogEntry.php:429
publish( $newId, $to='rcandudp')
Publish the log entry.
Definition LogEntry.php:706
getSubtype()
The log subtype.
Definition LogEntry.php:744
static record( $rc, $auto=false, User $user=null, $tags=null)
Record a log event for a change being patrolled.
Definition PatrolLog.php:41
getTimestamp()
Get the timestamp when the action was executed.
Definition LogEntry.php:380
getTarget()
Get the target page of this action.
Definition LogEntry.php:372
getSubtype()
The log subtype.
Definition LogEntry.php:353
getComment()
Get the user provided comment.
Definition LogEntry.php:384
getDeleted()
Get the access restriction.
Definition LogEntry.php:390
getRawParameters()
Returns whatever is stored in the database field.
Definition LogEntry.php:341
getId()
Returns the unique database id.
Definition LogEntry.php:337
getPerformer()
Get the user for performed this action.
Definition LogEntry.php:357
getType()
The main log type.
Definition LogEntry.php:349
static newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
static newExtraneousContext(Title $title, $request=[])
Create a new extraneous context.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Represents a title within MediaWiki.
Definition Title.php:39
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
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
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:64
the array() calling protocol came about after MediaWiki 1.4rc1.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition hooks.txt:2746
this hook is for auditing only RecentChangesLinked and Watchlist 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:1013
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:962
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 local account $user
Definition hooks.txt:247
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:37
Interface for log entries.
Definition LogEntry.php:38
isDeleted( $field)
getParameters()
Get the extra parameters stored for this message.
getTimestamp()
Get the timestamp when the action was executed.
getTarget()
Get the target page of this action.
getSubtype()
The log subtype.
getDeleted()
Get the access restriction.
getComment()
Get the user provided comment.
getFullType()
The full logtype in format maintype/subtype.
getPerformer()
Get the user for performed this action.
getType()
The main log type.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
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:36
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26
$params