Index: branches/robchurch/logs/includes/LogFormatter.php |
— | — | @@ -35,8 +35,8 @@ |
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | | - * Default formatter; all the standard bits plus the |
40 | | - * appropriate "appender" if set |
| 39 | + * Default formatter; all the standard bits, using custom |
| 40 | + * action formatter if set |
41 | 41 | * |
42 | 42 | * @param LogItem $item |
43 | 43 | * @param int $flags |
— | — | @@ -54,16 +54,32 @@ |
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 | | - $params = $item->getParameters(); |
59 | | - array_unshift( $params, $skin->makeLinkObj( $item->getTarget() ) ); |
60 | | - $parts[] = wfMsgReal( $wgLogActions[ $item->getActionKey() ], $params ); |
61 | | - # Custom appended bits |
62 | | - if( ( $appender = self::getAppender( $item ) ) !== false ) |
63 | | - $parts[] .= call_user_func( $appender, $item ); |
| 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 |
| 63 | + $params = $item->getParameters(); |
| 64 | + array_unshift( $params, $skin->makeLinkObj( $item->getTarget() ) ); |
| 65 | + $parts[] = self::getActionText( $item, $params ); |
| 66 | + } |
| 67 | + # Comment |
| 68 | + $parts[] = $skin->commentBlock( $item->getComment() ); |
64 | 69 | |
65 | 70 | return "<li>" . implode( ' ', $parts ) . "</li>\n"; |
66 | 71 | } |
67 | 72 | |
| 73 | + /** |
| 74 | + * Get the action text for a particular log item |
| 75 | + * |
| 76 | + * @param LogItem $item |
| 77 | + * @param array $params |
| 78 | + * @return string |
| 79 | + */ |
| 80 | + public static function getActionText( $item, $params ) { |
| 81 | + global $wgLogActions; |
| 82 | + return wfMsgReal( $wgLogActions[ $item->getActionKey() ], $params ); |
| 83 | + } |
68 | 84 | |
69 | 85 | /** |
70 | 86 | * Get the LogFormatter::format()-compliant callback |
— | — | @@ -80,19 +96,19 @@ |
81 | 97 | } |
82 | 98 | |
83 | 99 | /** |
84 | | - * Get the callback to append to the log line for |
| 100 | + * Get the callback to build action text for the |
85 | 101 | * specified log item, if there is one |
86 | 102 | * |
87 | 103 | * @param LogItem $item |
88 | 104 | * @return mixed |
89 | 105 | */ |
90 | | - private static function getAppender( $item ) { |
91 | | - global $wgLogFormatAppenders; |
92 | | - return isset( $wgLogFormatAppenders[ $item->getType() ] ) |
93 | | - ? $wgLogFormatAppenders[ $item->getType() ] |
| 106 | + private static function getActionCallback( $item ) { |
| 107 | + global $wgLogActionCallbacks; |
| 108 | + return isset( $wgLogActionCallbacks[ $item->getType() ] ) |
| 109 | + ? $wgLogActionCallbacks[ $item->getType() ] |
94 | 110 | : false; |
95 | 111 | } |
96 | 112 | |
97 | 113 | } |
98 | 114 | |
99 | | -?> |
\ No newline at end of file |
| 115 | +?> |
Index: branches/robchurch/logs/includes/PatrolLog.php |
— | — | @@ -33,54 +33,32 @@ |
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | | - * Format a complete patrol log line |
| 37 | + * Generate the log action text corresponding to a patrol log item |
38 | 38 | * |
39 | 39 | * @param LogItem $item |
40 | | - * @param int $flags |
41 | 40 | * @return string |
42 | 41 | */ |
43 | | - public static function formatLine( $item, $flags ) { |
44 | | - global $wgUser, $wgLang, $wgLogActions; |
| 42 | + public static function makeActionText( $item ) { |
| 43 | + global $wgUser; |
45 | 44 | $skin = $wgUser->getSkin(); |
46 | 45 | |
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; |
| 46 | + list( $cur, /* $prev */, $auto ) = $item->getParameters(); |
70 | 47 | # Standard link to the page in question |
71 | | - $link = $skin->makeLinkObj( $title ); |
72 | | - if( $title->exists() ) { |
| 48 | + $link = $skin->makeLinkObj( $item->getTarget() ); |
| 49 | + if( $item->getTarget()->exists() ) { |
73 | 50 | # Generate a diff link |
74 | 51 | $bits[] = 'oldid=' . urlencode( $cur ); |
75 | 52 | $bits[] = 'diff=prev'; |
76 | 53 | $bits = implode( '&', $bits ); |
77 | | - $diff = $skin->makeKnownLinkObj( $title, htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits ); |
| 54 | + $diff = $skin->makeKnownLinkObj( $item->getTarget(), |
| 55 | + htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ), $bits ); |
78 | 56 | } else { |
79 | 57 | # Don't bother with a diff link, it's useless |
80 | 58 | $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) ); |
81 | 59 | } |
82 | 60 | # Indicate whether or not the patrolling was automatic |
83 | 61 | $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : ''; |
84 | | - # Put it all together |
| 62 | + |
85 | 63 | return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto ); |
86 | 64 | } |
87 | 65 | |
Index: branches/robchurch/logs/includes/BlockLogFormatter.php |
— | — | @@ -15,23 +15,16 @@ |
16 | 16 | const LINK_UNBLOCK = 2; |
17 | 17 | |
18 | 18 | /** |
19 | | - * Format a complete block log item |
| 19 | + * Build the action text for a block log item |
20 | 20 | * |
21 | 21 | * @param LogItem $item |
22 | | - * @param int $flags |
23 | 22 | * @return string |
24 | 23 | */ |
25 | | - public static function formatBlock( $item, $flags ) { |
| 24 | + public static function makeActionText( $item ) { |
26 | 25 | global $wgUser, $wgLang, $wgLogActions; |
27 | 26 | $skin = $wgUser->getSkin(); |
28 | 27 | $data = $item->getParameters(); |
29 | 28 | |
30 | | - $parts[] = $flags & LogFormatter::NO_DATE |
31 | | - ? $wgLang->time( $item->getTimestamp() ) |
32 | | - : $wgLang->timeAndDate( $item->getTimestamp() ); |
33 | | - $parts[] = $skin->userLink( $item->getUser()->getId(), $item->getUser()->getName() ) |
34 | | - . $skin->userToolLinks( $item->getUser()->getId(), $item->getUser()->getName() ); |
35 | | - |
36 | 29 | # Target link |
37 | 30 | $link = $item->getAction() == 'block' ? self::LINK_BLOCK : self::LINK_UNBLOCK; |
38 | 31 | $params[] = self::formatTarget( $item->getTarget(), $link ); |
— | — | @@ -42,8 +35,7 @@ |
43 | 36 | $params[] = ( isset( $data[1] ) ? self::formatBlockFlags( $data[1] ) : '' ); |
44 | 37 | } |
45 | 38 | |
46 | | - $parts[] = wfMsgReal( $wgLogActions[ $item->getActionKey() ], $params ); |
47 | | - return "<li>" . implode( ' ', $parts ) . "</li>\n"; |
| 39 | + return LogFormatter::getActionText( $item, $params ); |
48 | 40 | } |
49 | 41 | |
50 | 42 | /** |
Index: branches/robchurch/logs/includes/DefaultSettings.php |
— | — | @@ -2262,10 +2262,12 @@ |
2263 | 2263 | |
2264 | 2264 | /** |
2265 | 2265 | * Dictionary of callbacks for partial log formatting |
2266 | | - * purposes; if set, the output of each is appended to |
2267 | | - * a log line during formatting |
| 2266 | + * purposes; if set, the output of each is used to build |
| 2267 | + * the "action text" when formatting a log line |
2268 | 2268 | */ |
2269 | | -$wgLogFormatAppenders = array( |
| 2269 | +$wgLogActionCallbacks = array( |
| 2270 | + 'block' => array( 'BlockLogFormatter', 'makeActionText' ), |
| 2271 | + 'patrol' => array( 'PatrolLog', 'makeActionText' ), |
2270 | 2272 | ); |
2271 | 2273 | |
2272 | 2274 | /** |
— | — | @@ -2275,8 +2277,6 @@ |
2276 | 2278 | * line including <li></li> |
2277 | 2279 | */ |
2278 | 2280 | $wgLogFormatters = array( |
2279 | | - 'block' => array( 'BlockLogFormatter', 'formatBlock' ), |
2280 | | - 'patrol' => array( 'PatrolLog', 'formatLine' ), |
2281 | 2281 | ); |
2282 | 2282 | |
2283 | 2283 | /** |