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