65c523d61484007ae62bd41b1dc66673204ce5f3
[lhc/web/wiklou.git] / includes / logging / PatrolLog.php
1 <?php
2
3 /**
4 * Class containing static functions for working with
5 * logs of patrol events
6 *
7 * @author Rob Church <robchur@gmail.com>
8 * @author Niklas Laxström
9 */
10 class PatrolLog {
11
12 /**
13 * Record a log event for a change being patrolled
14 *
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
18 *
19 * @return bool
20 */
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;
26 }
27 }
28
29 $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
30 if( $title ) {
31 if ( !$user ) {
32 global $wgUser;
33 $user = $wgUser;
34 }
35
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' );
43 }
44 return true;
45 }
46 return false;
47 }
48
49 /**
50 * Prepare log parameters for a patrolled change
51 *
52 * @param $change RecentChange to represent
53 * @param $auto Boolean: whether the patrol event was automatic
54 * @return Array
55 */
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
61 );
62 }
63
64 }