Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PatrolLog | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
record | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
buildParams | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
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 | use MediaWiki\User\UserIdentity; |
26 | |
27 | /** |
28 | * Class containing static functions for working with |
29 | * logs of patrol events |
30 | */ |
31 | class PatrolLog { |
32 | |
33 | /** |
34 | * Record a log event for a change being patrolled |
35 | * |
36 | * @param int|RecentChange $rc Change identifier or RecentChange object |
37 | * @param bool $auto Was this patrol event automatic? |
38 | * @param UserIdentity $user User performing the action |
39 | * @param string|string[]|null $tags Change tags to add to the patrol log entry |
40 | * ($user should be able to add the specified tags before this is called) |
41 | * |
42 | * @return bool |
43 | */ |
44 | public static function record( $rc, $auto, UserIdentity $user, $tags = null ) { |
45 | // Do not log autopatrol actions: T184485 |
46 | if ( $auto ) { |
47 | return false; |
48 | } |
49 | |
50 | if ( !$rc instanceof RecentChange ) { |
51 | $rc = RecentChange::newFromId( $rc ); |
52 | if ( !is_object( $rc ) ) { |
53 | return false; |
54 | } |
55 | } |
56 | |
57 | $entry = new ManualLogEntry( 'patrol', 'patrol' ); |
58 | $entry->setTarget( $rc->getTitle() ); |
59 | $entry->setParameters( self::buildParams( $rc ) ); |
60 | $entry->setPerformer( $user ); |
61 | $entry->addTags( $tags ); |
62 | $logid = $entry->insert(); |
63 | $entry->publish( $logid, 'udp' ); |
64 | |
65 | return true; |
66 | } |
67 | |
68 | /** |
69 | * Prepare log parameters for a patrolled change |
70 | * |
71 | * @param RecentChange $change RecentChange to represent |
72 | * @return array |
73 | */ |
74 | private static function buildParams( $change ) { |
75 | return [ |
76 | '4::curid' => $change->getAttribute( 'rc_this_oldid' ), |
77 | '5::previd' => $change->getAttribute( 'rc_last_oldid' ), |
78 | '6::auto' => 0 |
79 | ]; |
80 | } |
81 | } |