MediaWiki master
PatrolLog.php
Go to the documentation of this file.
1<?php
25namespace MediaWiki\Logging;
26
30
35class PatrolLog {
36
48 public static function record( $rc, $auto, UserIdentity $user, $tags = null ) {
49 // Do not log autopatrol actions: T184485
50 if ( $auto ) {
51 return false;
52 }
53
54 if ( !$rc instanceof RecentChange ) {
55 $rc = RecentChange::newFromId( $rc );
56 if ( !is_object( $rc ) ) {
57 return false;
58 }
59 }
60
61 $entry = new ManualLogEntry( 'patrol', 'patrol' );
62
63 // B/C: ->getPage() on RC will return a page reference or null, reconcile this in
64 // $entry->setTarget() call so we don't throw.
65 $page = $rc->getPage() ?? PageReferenceValue::localReference( NS_SPECIAL, 'Badtitle' );
66 $entry->setTarget( $page );
67 $entry->setParameters( self::buildParams( $rc ) );
68 $entry->setPerformer( $user );
69 $entry->addTags( $tags );
70 $logid = $entry->insert();
71 $entry->publish( $logid, 'udp' );
72
73 return true;
74 }
75
82 private static function buildParams( $change ) {
83 return [
84 '4::curid' => $change->getAttribute( 'rc_this_oldid' ),
85 '5::previd' => $change->getAttribute( 'rc_last_oldid' ),
86 '6::auto' => 0
87 ];
88 }
89}
90
92class_alias( PatrolLog::class, 'PatrolLog' );
const NS_SPECIAL
Definition Defines.php:54
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:35
static record( $rc, $auto, UserIdentity $user, $tags=null)
Record a log event for a change being patrolled.
Definition PatrolLog.php:48
Immutable value object representing a page reference.
Utility class for creating and reading rows in the recentchanges table.
Interface for objects representing user identity.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...