No more undefined usage of rev{Start,End}Id warnings
[mediawiki.git] / includes / logging / PatrolLog.php
blob65c523d61484007ae62bd41b1dc66673204ce5f3
1 <?php
3 /**
4 * Class containing static functions for working with
5 * logs of patrol events
7 * @author Rob Church <robchur@gmail.com>
8 * @author Niklas Laxström
9 */
10 class PatrolLog {
12 /**
13 * Record a log event for a change being patrolled
15 * @param $rc Mixed: change identifier or RecentChange object
16 * @param $auto Boolean: was this patrol event automatic?
17 * @param $performer User: user performing the action or null to use $wgUser
19 * @return bool
21 public static function record( $rc, $auto = false, User $user = null ) {
22 if ( !$rc instanceof RecentChange ) {
23 $rc = RecentChange::newFromId( $rc );
24 if ( !is_object( $rc ) ) {
25 return false;
29 $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
30 if( $title ) {
31 if ( !$user ) {
32 global $wgUser;
33 $user = $wgUser;
36 $entry = new ManualLogEntry( 'patrol', 'patrol' );
37 $entry->setTarget( $title );
38 $entry->setParameters( self::buildParams( $rc, $auto ) );
39 $entry->setPerformer( $user );
40 $logid = $entry->insert();
41 if ( !$auto ) {
42 $entry->publish( $logid, 'udp' );
44 return true;
46 return false;
49 /**
50 * Prepare log parameters for a patrolled change
52 * @param $change RecentChange to represent
53 * @param $auto Boolean: whether the patrol event was automatic
54 * @return Array
56 private static function buildParams( $change, $auto ) {
57 return array(
58 '4::curid' => $change->getAttribute( 'rc_this_oldid' ),
59 '5::previd' => $change->getAttribute( 'rc_last_oldid' ),
60 '6::auto' => (int)$auto