Merge "(bug 37090) Remove Spanish gender aliases."
[mediawiki.git] / includes / logging / PatrolLog.php
blob339688d3c7a4943214c87c68205de085eff088b3
1 <?php
2 /**
3 * Specific methods for the patrol log.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Rob Church <robchur@gmail.com>
22 * @author Niklas Laxström
25 /**
26 * Class containing static functions for working with
27 * logs of patrol events
29 class PatrolLog {
31 /**
32 * Record a log event for a change being patrolled
34 * @param $rc Mixed: change identifier or RecentChange object
35 * @param $auto Boolean: was this patrol event automatic?
36 * @param $performer User: user performing the action or null to use $wgUser
38 * @return bool
40 public static function record( $rc, $auto = false, User $user = null ) {
41 if ( !$rc instanceof RecentChange ) {
42 $rc = RecentChange::newFromId( $rc );
43 if ( !is_object( $rc ) ) {
44 return false;
48 $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
49 if( $title ) {
50 if ( !$user ) {
51 global $wgUser;
52 $user = $wgUser;
55 $entry = new ManualLogEntry( 'patrol', 'patrol' );
56 $entry->setTarget( $title );
57 $entry->setParameters( self::buildParams( $rc, $auto ) );
58 $entry->setPerformer( $user );
59 $logid = $entry->insert();
60 if ( !$auto ) {
61 $entry->publish( $logid, 'udp' );
63 return true;
65 return false;
68 /**
69 * Prepare log parameters for a patrolled change
71 * @param $change RecentChange to represent
72 * @param $auto Boolean: whether the patrol event was automatic
73 * @return Array
75 private static function buildParams( $change, $auto ) {
76 return array(
77 '4::curid' => $change->getAttribute( 'rc_this_oldid' ),
78 '5::previd' => $change->getAttribute( 'rc_last_oldid' ),
79 '6::auto' => (int)$auto