r23456 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23455‎ | r23456 | r23457 >
Date:06:44, 27 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* Forget r23452, this method provides for less code duplication and is just cleaner and saner
* Bring back comments, might need those...
Modified paths:
  • /branches/robchurch/logs/includes/BlockLogFormatter.php (modified) (history)
  • /branches/robchurch/logs/includes/DefaultSettings.php (modified) (history)
  • /branches/robchurch/logs/includes/LogFormatter.php (modified) (history)
  • /branches/robchurch/logs/includes/PatrolLog.php (modified) (history)

Diff [purge]

Index: branches/robchurch/logs/includes/LogFormatter.php
@@ -35,8 +35,8 @@
3636 }
3737
3838 /**
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
4141 *
4242 * @param LogItem $item
4343 * @param int $flags
@@ -54,16 +54,32 @@
5555 $parts[] = $skin->userLink( $item->getUser()->getId(), $item->getUser()->getName() )
5656 . $skin->userToolLinks( $item->getUser()->getId(), $item->getUser()->getName() );
5757 # 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() );
6469
6570 return "<li>" . implode( ' ', $parts ) . "</li>\n";
6671 }
6772
 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+ }
6884
6985 /**
7086 * Get the LogFormatter::format()-compliant callback
@@ -80,19 +96,19 @@
8197 }
8298
8399 /**
84 - * Get the callback to append to the log line for
 100+ * Get the callback to build action text for the
85101 * specified log item, if there is one
86102 *
87103 * @param LogItem $item
88104 * @return mixed
89105 */
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() ]
94110 : false;
95111 }
96112
97113 }
98114
99 -?>
\ No newline at end of file
 115+?>
Index: branches/robchurch/logs/includes/PatrolLog.php
@@ -33,54 +33,32 @@
3434 }
3535
3636 /**
37 - * Format a complete patrol log line
 37+ * Generate the log action text corresponding to a patrol log item
3838 *
3939 * @param LogItem $item
40 - * @param int $flags
4140 * @return string
4241 */
43 - public static function formatLine( $item, $flags ) {
44 - global $wgUser, $wgLang, $wgLogActions;
 42+ public static function makeActionText( $item ) {
 43+ global $wgUser;
4544 $skin = $wgUser->getSkin();
4645
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();
7047 # 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() ) {
7350 # Generate a diff link
7451 $bits[] = 'oldid=' . urlencode( $cur );
7552 $bits[] = 'diff=prev';
7653 $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 );
7856 } else {
7957 # Don't bother with a diff link, it's useless
8058 $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
8159 }
8260 # Indicate whether or not the patrolling was automatic
8361 $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
84 - # Put it all together
 62+
8563 return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
8664 }
8765
Index: branches/robchurch/logs/includes/BlockLogFormatter.php
@@ -15,23 +15,16 @@
1616 const LINK_UNBLOCK = 2;
1717
1818 /**
19 - * Format a complete block log item
 19+ * Build the action text for a block log item
2020 *
2121 * @param LogItem $item
22 - * @param int $flags
2322 * @return string
2423 */
25 - public static function formatBlock( $item, $flags ) {
 24+ public static function makeActionText( $item ) {
2625 global $wgUser, $wgLang, $wgLogActions;
2726 $skin = $wgUser->getSkin();
2827 $data = $item->getParameters();
2928
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 -
3629 # Target link
3730 $link = $item->getAction() == 'block' ? self::LINK_BLOCK : self::LINK_UNBLOCK;
3831 $params[] = self::formatTarget( $item->getTarget(), $link );
@@ -42,8 +35,7 @@
4336 $params[] = ( isset( $data[1] ) ? self::formatBlockFlags( $data[1] ) : '' );
4437 }
4538
46 - $parts[] = wfMsgReal( $wgLogActions[ $item->getActionKey() ], $params );
47 - return "<li>" . implode( ' ', $parts ) . "</li>\n";
 39+ return LogFormatter::getActionText( $item, $params );
4840 }
4941
5042 /**
Index: branches/robchurch/logs/includes/DefaultSettings.php
@@ -2262,10 +2262,12 @@
22632263
22642264 /**
22652265 * 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
22682268 */
2269 -$wgLogFormatAppenders = array(
 2269+$wgLogActionCallbacks = array(
 2270+ 'block' => array( 'BlockLogFormatter', 'makeActionText' ),
 2271+ 'patrol' => array( 'PatrolLog', 'makeActionText' ),
22702272 );
22712273
22722274 /**
@@ -2275,8 +2277,6 @@
22762278 * line including <li></li>
22772279 */
22782280 $wgLogFormatters = array(
2279 - 'block' => array( 'BlockLogFormatter', 'formatBlock' ),
2280 - 'patrol' => array( 'PatrolLog', 'formatLine' ),
22812281 );
22822282
22832283 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r23452Duh, that was *exactly* was I wanted in the first place; most logs just need ...robchurch04:46, 27 June 2007

Status & tagging log