95668884049d78bce10eab842f57a11123681f49
[lhc/web/wiklou.git] / includes / 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 */
9 class PatrolLog {
10
11 /**
12 * Record a log event for a change being patrolled
13 *
14 * @param mixed $change Change identifier or RecentChange object
15 * @param bool $auto Was this patrol event automatic?
16 */
17 public static function record( $rc, $auto = false ) {
18 if( !( $rc instanceof RecentChange ) ) {
19 $rc = RecentChange::newFromId( $rc );
20 if( !is_object( $rc ) )
21 return false;
22 }
23 $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
24 if( is_object( $title ) ) {
25 $params = self::buildParams( $rc, $auto );
26 $log = new LogPage( 'patrol', false ); # False suppresses RC entries
27 $log->addEntry( 'patrol', $title, '', $params );
28 # Notify external application via UDP.
29 # We send this to IRC but do not want to add it the RC table.
30 global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
31 if( $wgRC2UDPAddress && ( !$rc->getAttribute('rc_bot') || !$wgRC2UDPOmitBots ) ) {
32 self::sendToUDP( $rc->getIRCLine() );
33 }
34 return true;
35 }
36 return false;
37 }
38
39 /**
40 * Generate the log action text corresponding to a patrol log item
41 *
42 * @param Title $title Title of the page that was patrolled
43 * @param array $params Log parameters (from logging.log_params)
44 * @param Skin $skin Skin to use for building links, etc.
45 * @return string
46 */
47 public static function makeActionText( $title, $params, $skin ) {
48 # This is a bit of a hack, but...if $skin is not a Skin, then *do nothing*
49 # -- this is fine, because the action text we would be queried for under
50 # these conditions would have gone into recentchanges, which we aren't
51 # supposed to be updating
52 if( is_object( $skin ) ) {
53 list( $cur, /* $prev */, $auto ) = $params;
54 # Standard link to the page in question
55 $link = $skin->makeLinkObj( $title );
56 if( $title->exists() ) {
57 # Generate a diff link
58 $bits[] = 'oldid=' . urlencode( $cur );
59 $bits[] = 'diff=prev';
60 $bits = implode( '&', $bits );
61 $diff = $skin->makeKnownLinkObj( $title, htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits );
62 } else {
63 # Don't bother with a diff link, it's useless
64 $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
65 }
66 # Indicate whether or not the patrolling was automatic
67 $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
68 # Put it all together
69 return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
70 } else {
71 return '';
72 }
73 }
74
75 /**
76 * Prepare log parameters for a patrolled change
77 *
78 * @param RecentChange $change RecentChange to represent
79 * @param bool $auto Whether the patrol event was automatic
80 * @return array
81 */
82 private static function buildParams( $change, $auto ) {
83 return array(
84 $change->getAttribute( 'rc_this_oldid' ),
85 $change->getAttribute( 'rc_last_oldid' ),
86 (int)$auto
87 );
88 }
89 }