3 class JSONRCFeedFormatter
implements RCFeedFormatter
{
5 * Generates a notification that can be easily interpreted by a machine.
6 * @see RCFeedFormatter::getLine
8 public function getLine( array $feed, RecentChange
$rc, $actionComment ) {
9 global $wgCanonicalServer, $wgScriptPath, $wgDBname;
10 $attrib = $rc->getAttributes();
13 // Usually, RC ID is exposed only for patrolling purposes,
14 // but there is no real reason not to expose it in other cases,
15 // and I can see how this may be potentially useful for clients.
16 'id' => $attrib['rc_id'],
17 'type' => $attrib['rc_type'],
18 'namespace' => $rc->getTitle()->getNamespace(),
19 'title' => $rc->getTitle()->getPrefixedText(),
20 'comment' => $attrib['rc_comment'],
21 'timestamp' => (int)wfTimestamp( TS_UNIX
, $attrib['rc_timestamp'] ),
22 'user' => $attrib['rc_user_text'],
23 'bot' => (bool)$attrib['rc_bot'],
26 if ( isset( $feed['channel'] ) ) {
27 $packet['channel'] = $feed['channel'];
30 $type = $attrib['rc_type'];
31 if ( $type == RC_EDIT ||
$type == RC_NEW
) {
32 global $wgUseRCPatrol, $wgUseNPPatrol;
34 $packet['minor'] = $attrib['rc_minor'];
35 if ( $wgUseRCPatrol ||
( $type == RC_NEW
&& $wgUseNPPatrol ) ) {
36 $packet['patrolled'] = $attrib['rc_patrolled'];
42 $packet['length'] = array( 'old' => $attrib['rc_old_len'], 'new' => $attrib['rc_new_len'] );
43 $packet['revision'] = array( 'old' => $attrib['rc_last_oldid'], 'new' => $attrib['rc_this_oldid'] );
47 $packet['length'] = array( 'old' => NULL, 'new' => $attrib['rc_new_len'] );
48 $packet['revision'] = array( 'old' => NULL, 'new' => $attrib['rc_this_oldid'] );
52 $packet['log_type'] = $attrib['rc_log_type'];
53 $packet['log_action'] = $attrib['rc_log_action'];
54 if ( $attrib['rc_params'] ) {
56 $params = unserialize( $attrib['rc_params'] );
59 // If it's an actual serialised false...
60 $attrib['rc_params'] == serialize( false ) ||
61 // Or if we did not get false back when trying to unserialise
64 // From ApiQueryLogEvents::addLogParams
66 // Keys like "4::paramname" can't be used for output so we change them to "paramname"
67 foreach ( $params as $key => $value ) {
68 if ( strpos( $key, ':' ) === false ) {
69 $logParams[$key] = $value;
72 $logParam = explode( ':', $key, 3 );
73 $logParams[$logParam[2]] = $value;
75 $packet['log_params'] = $logParams;
77 $packet['log_params'] = explode( "\n", $attrib['rc_params'] );
80 $packet['log_action_comment'] = $actionComment;
84 $packet['server_url'] = $wgCanonicalServer;
85 $packet['server_script_path'] = $wgScriptPath ?
: '/';
86 $packet['wiki'] = $wgDBname;
88 return FormatJson
::encode( $packet );