(Bug 15936) New page's patrol button should always be visible
[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 return true;
29 }
30 return false;
31 }
32
33 /**
34 * Generate the log action text corresponding to a patrol log item
35 *
36 * @param Title $title Title of the page that was patrolled
37 * @param array $params Log parameters (from logging.log_params)
38 * @param Skin $skin Skin to use for building links, etc.
39 * @return string
40 */
41 public static function makeActionText( $title, $params, $skin ) {
42 # This is a bit of a hack, but...if $skin is not a Skin, then *do nothing*
43 # -- this is fine, because the action text we would be queried for under
44 # these conditions would have gone into recentchanges, which we aren't
45 # supposed to be updating
46 if( is_object( $skin ) ) {
47 list( $cur, /* $prev */, $auto ) = $params;
48 # Standard link to the page in question
49 $link = $skin->makeLinkObj( $title );
50 if( $title->exists() ) {
51 # Generate a diff link
52 $bits[] = 'oldid=' . urlencode( $cur );
53 $bits[] = 'diff=prev';
54 $bits = implode( '&', $bits );
55 $diff = $skin->makeKnownLinkObj( $title, htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits );
56 } else {
57 # Don't bother with a diff link, it's useless
58 $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
59 }
60 # Indicate whether or not the patrolling was automatic
61 $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
62 # Put it all together
63 return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
64 } else {
65 return '';
66 }
67 }
68
69 /**
70 * Prepare log parameters for a patrolled change
71 *
72 * @param RecentChange $change RecentChange to represent
73 * @param bool $auto Whether the patrol event was automatic
74 * @return array
75 */
76 private static function buildParams( $change, $auto ) {
77 return array(
78 $change->getAttribute( 'rc_this_oldid' ),
79 $change->getAttribute( 'rc_last_oldid' ),
80 (int)$auto
81 );
82 }
83 }