Index: branches/robchurch/logs/includes/LogFormatter.php |
— | — | @@ -35,8 +35,8 @@ |
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | | - * Default formatter; all the standard bits, using custom |
40 | | - * action formatter if set |
| 39 | + * Default formatter; all the standard bits plus the |
| 40 | + * appropriate "appender" if set |
41 | 41 | * |
42 | 42 | * @param LogItem $item |
43 | 43 | * @param int $flags |
— | — | @@ -54,17 +54,14 @@ |
55 | 55 | $parts[] = $skin->userLink( $item->getUser()->getId(), $item->getUser()->getName() ) |
56 | 56 | . $skin->userToolLinks( $item->getUser()->getId(), $item->getUser()->getName() ); |
57 | 57 | # Action |
58 | | - if( ( $callback = self::getActionCallback( $item ) ) !== false ) { |
59 | | - # Custom action text callback |
60 | | - $parts[] = call_user_func( $callback, $item ); |
61 | | - } else { |
62 | | - # Use the message, first parameter is a link to the page |
63 | | - $parts[] = wfMsgExt( |
64 | | - $wgLogActions[ $item->getActionKey() ], |
65 | | - array( 'parseinline', 'replaceafter' ), |
66 | | - $skin->makeLinkObj( $item->getTarget() ) |
67 | | - ); |
68 | | - } |
| 58 | + $parts[] = wfMsgExt( |
| 59 | + $wgLogActions[ $item->getActionKey() ], |
| 60 | + array( 'parseinline', 'replaceafter' ), |
| 61 | + $skin->makeLinkObj( $item->getTarget() ) |
| 62 | + ); |
| 63 | + # Custom appended bits |
| 64 | + if( ( $appender = self::getAppender( $item ) ) !== false ) |
| 65 | + $parts[] .= call_user_func( $appender, $item ); |
69 | 66 | |
70 | 67 | return "<li>" . implode( ' ', $parts ) . "</li>\n"; |
71 | 68 | } |
— | — | @@ -85,16 +82,16 @@ |
86 | 83 | } |
87 | 84 | |
88 | 85 | /** |
89 | | - * Get the callback to build action text for the |
| 86 | + * Get the callback to append to the log line for |
90 | 87 | * specified log item, if there is one |
91 | 88 | * |
92 | 89 | * @param LogItem $item |
93 | 90 | * @return mixed |
94 | 91 | */ |
95 | | - private static function getActionCallback( $item ) { |
96 | | - global $wgLogActionCallbacks; |
97 | | - return isset( $wgLogActionCallbacks[ $item->getType() ] ) |
98 | | - ? $wgLogActionCallbacks[ $item->getType() ] |
| 92 | + private static function getAppender( $item ) { |
| 93 | + global $wgLogAppenders; |
| 94 | + return isset( $wgLogAppenders[ $item->getType() ] ) |
| 95 | + ? $wgLogAppenders[ $item->getType() ] |
99 | 96 | : false; |
100 | 97 | } |
101 | 98 | |
Index: branches/robchurch/logs/includes/PatrolLog.php |
— | — | @@ -33,32 +33,54 @@ |
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | | - * Generate the log action text corresponding to a patrol log item |
| 37 | + * Format a complete patrol log line |
38 | 38 | * |
39 | 39 | * @param LogItem $item |
| 40 | + * @param int $flags |
40 | 41 | * @return string |
41 | 42 | */ |
42 | | - public static function makeActionText( $item ) { |
43 | | - global $wgUser; |
| 43 | + public static function formatLine( $item, $flags ) { |
| 44 | + global $wgUser, $wgLang, $wgLogActions; |
44 | 45 | $skin = $wgUser->getSkin(); |
45 | 46 | |
46 | | - list( $cur, /* $prev */, $auto ) = $item->getParameters(); |
| 47 | + # Time |
| 48 | + $parts[] = $flags & LogFormatter::NO_DATE |
| 49 | + ? $wgLang->time( $item->getTimestamp() ) |
| 50 | + : $wgLang->timeAndDate( $item->getTimestamp() ); |
| 51 | + # User |
| 52 | + $parts[] = $skin->userLink( $item->getUser()->getId(), $item->getUser()->getName() ) |
| 53 | + . $skin->userToolLinks( $item->getUser()->getId(), $item->getUser()->getName() ); |
| 54 | + # Action |
| 55 | + $parts[] = self::makeActionText( $item->getTarget(), $item->getParameters(), $skin ); |
| 56 | + |
| 57 | + return "<li>" . implode( ' ', $parts ) . "</li>\n"; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Generate the log action text corresponding to a patrol log item |
| 62 | + * |
| 63 | + * @param Title $title Title of the page that was patrolled |
| 64 | + * @param array $params Log parameters (from logging.log_params) |
| 65 | + * @param Skin $skin Skin to use for building links, etc. |
| 66 | + * @return string |
| 67 | + */ |
| 68 | + private static function makeActionText( $title, $params, $skin ) { |
| 69 | + list( $cur, /* $prev */, $auto ) = $params; |
47 | 70 | # Standard link to the page in question |
48 | | - $link = $skin->makeLinkObj( $item->getTarget() ); |
49 | | - if( $item->getTarget()->exists() ) { |
| 71 | + $link = $skin->makeLinkObj( $title ); |
| 72 | + if( $title->exists() ) { |
50 | 73 | # Generate a diff link |
51 | 74 | $bits[] = 'oldid=' . urlencode( $cur ); |
52 | 75 | $bits[] = 'diff=prev'; |
53 | 76 | $bits = implode( '&', $bits ); |
54 | | - $diff = $skin->makeKnownLinkObj( $item->getTarget(), |
55 | | - htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits ); |
| 77 | + $diff = $skin->makeKnownLinkObj( $title, htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits ); |
56 | 78 | } else { |
57 | 79 | # Don't bother with a diff link, it's useless |
58 | 80 | $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ); |
59 | 81 | } |
60 | 82 | # Indicate whether or not the patrolling was automatic |
61 | 83 | $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : ''; |
62 | | - |
| 84 | + # Put it all together |
63 | 85 | return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto ); |
64 | 86 | } |
65 | 87 | |
Index: branches/robchurch/logs/includes/DefaultSettings.php |
— | — | @@ -2262,11 +2262,11 @@ |
2263 | 2263 | |
2264 | 2264 | /** |
2265 | 2265 | * Dictionary of callbacks for partial log formatting |
2266 | | - * purposes; if set, the output of each is used to build |
2267 | | - * the "action text" when formatting a log line |
| 2266 | + * purposes; if set, the output of each is appended to |
| 2267 | + * a log line during formatting |
2268 | 2268 | */ |
2269 | | -$wgLogActionCallbacks = array( |
2270 | | - 'patrol' => array( 'PatrolLog', 'makeActionText' ), |
| 2269 | +$wgLogFormatAppenders = array( |
| 2270 | + |
2271 | 2271 | ); |
2272 | 2272 | |
2273 | 2273 | /** |
— | — | @@ -2275,7 +2275,9 @@ |
2276 | 2276 | * LogFormatter::format() and should return a complete |
2277 | 2277 | * line including <li></li> |
2278 | 2278 | */ |
2279 | | -$wgLogFormatters = array(); |
| 2279 | +$wgLogFormatters = array( |
| 2280 | + 'patrol' => array( 'PatrolLog', 'formatLine' ), |
| 2281 | +); |
2280 | 2282 | |
2281 | 2283 | /** |
2282 | 2284 | * Experimental preview feature to fetch rendered text |