Merge "Remove old hacks in StringUtils::isUtf8()"
[lhc/web/wiklou.git] / includes / logging / PatrolLog.php
1 <?php
2 /**
3 * Specific methods for the patrol log.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Rob Church <robchur@gmail.com>
22 * @author Niklas Laxström
23 */
24
25 /**
26 * Class containing static functions for working with
27 * logs of patrol events
28 */
29 class PatrolLog {
30 /**
31 * Record a log event for a change being patrolled
32 *
33 * @param int|RecentChange $rc Change identifier or RecentChange object
34 * @param bool $auto Was this patrol event automatic?
35 * @param User $user User performing the action or null to use $wgUser
36 * @param string|string[] $tags Change tags to add to the patrol log entry
37 * ($user should be able to add the specified tags before this is called)
38 *
39 * @return bool
40 */
41 public static function record( $rc, $auto = false, User $user = null, $tags = null ) {
42 global $wgLogAutopatrol;
43
44 // do not log autopatrolled edits if setting disables it
45 if ( $auto && !$wgLogAutopatrol ) {
46 return false;
47 }
48
49 if ( !$rc instanceof RecentChange ) {
50 $rc = RecentChange::newFromId( $rc );
51 if ( !is_object( $rc ) ) {
52 return false;
53 }
54 }
55
56 if ( !$user ) {
57 global $wgUser;
58 $user = $wgUser;
59 }
60
61 $action = $auto ? 'autopatrol' : 'patrol';
62
63 $entry = new ManualLogEntry( 'patrol', $action );
64 $entry->setTarget( $rc->getTitle() );
65 $entry->setParameters( self::buildParams( $rc, $auto ) );
66 $entry->setPerformer( $user );
67 $entry->setTags( $tags );
68 $logid = $entry->insert();
69 if ( !$auto ) {
70 $entry->publish( $logid, 'udp' );
71 }
72
73 return true;
74 }
75
76 /**
77 * Prepare log parameters for a patrolled change
78 *
79 * @param RecentChange $change RecentChange to represent
80 * @param bool $auto Whether the patrol event was automatic
81 * @return array
82 */
83 private static function buildParams( $change, $auto ) {
84 return [
85 '4::curid' => $change->getAttribute( 'rc_this_oldid' ),
86 '5::previd' => $change->getAttribute( 'rc_last_oldid' ),
87 '6::auto' => (int)$auto
88 ];
89 }
90 }