MediaWiki master
PatrolLog.php
Go to the documentation of this file.
1<?php
11namespace MediaWiki\Logging;
12
17
22class PatrolLog {
23
35 public static function record( $rc, $auto, UserIdentity $user, $tags = null ) {
36 // Do not log autopatrol actions: T184485
37 if ( $auto ) {
38 return false;
39 }
40
41 if ( !$rc instanceof RecentChange ) {
43 ->getRecentChangeLookup()
44 ->getRecentChangeById( $rc );
45 if ( !$rc ) {
46 return false;
47 }
48 }
49
50 $entry = new ManualLogEntry( 'patrol', 'patrol' );
51
52 // B/C: ->getPage() on RC will return a page reference or null, reconcile this in
53 // $entry->setTarget() call so we don't throw.
54 $page = $rc->getPage() ?? PageReferenceValue::localReference( NS_SPECIAL, 'Badtitle' );
55 $entry->setTarget( $page );
56 $entry->setParameters( self::buildParams( $rc ) );
57 $entry->setPerformer( $user );
58 $entry->addTags( $tags );
59 $logid = $entry->insert();
60 $entry->publish( $logid, 'udp' );
61
62 return true;
63 }
64
71 private static function buildParams( $change ) {
72 return [
73 '4::curid' => $change->getAttribute( 'rc_this_oldid' ),
74 '5::previd' => $change->getAttribute( 'rc_last_oldid' ),
75 '6::auto' => 0
76 ];
77 }
78}
79
81class_alias( PatrolLog::class, 'PatrolLog' );
const NS_SPECIAL
Definition Defines.php:40
Class for creating new log entries and inserting them into the database.
Class containing static functions for working with logs of patrol events.
Definition PatrolLog.php:22
static record( $rc, $auto, UserIdentity $user, $tags=null)
Record a log event for a change being patrolled.
Definition PatrolLog.php:35
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Immutable value object representing a page reference.
Utility class for creating and reading rows in the recentchanges table.
Interface for objects representing user identity.