r23452 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23451‎ | r23452 | r23453 >
Date:04:46, 27 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Duh, that was *exactly* was I wanted in the first place; most logs just need stuff appending and don't need the hassle of re-doing the action message...
Modified paths:
  • /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, using custom
40 - * action formatter if set
 39+ * Default formatter; all the standard bits plus the
 40+ * appropriate "appender" if set
4141 *
4242 * @param LogItem $item
4343 * @param int $flags
@@ -54,17 +54,14 @@
5555 $parts[] = $skin->userLink( $item->getUser()->getId(), $item->getUser()->getName() )
5656 . $skin->userToolLinks( $item->getUser()->getId(), $item->getUser()->getName() );
5757 # 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 );
6966
7067 return "<li>" . implode( ' ', $parts ) . "</li>\n";
7168 }
@@ -85,16 +82,16 @@
8683 }
8784
8885 /**
89 - * Get the callback to build action text for the
 86+ * Get the callback to append to the log line for
9087 * specified log item, if there is one
9188 *
9289 * @param LogItem $item
9390 * @return mixed
9491 */
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() ]
9996 : false;
10097 }
10198
Index: branches/robchurch/logs/includes/PatrolLog.php
@@ -33,32 +33,54 @@
3434 }
3535
3636 /**
37 - * Generate the log action text corresponding to a patrol log item
 37+ * Format a complete patrol log line
3838 *
3939 * @param LogItem $item
 40+ * @param int $flags
4041 * @return string
4142 */
42 - public static function makeActionText( $item ) {
43 - global $wgUser;
 43+ public static function formatLine( $item, $flags ) {
 44+ global $wgUser, $wgLang, $wgLogActions;
4445 $skin = $wgUser->getSkin();
4546
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;
4770 # 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() ) {
5073 # Generate a diff link
5174 $bits[] = 'oldid=' . urlencode( $cur );
5275 $bits[] = 'diff=prev';
5376 $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 );
5678 } else {
5779 # Don't bother with a diff link, it's useless
5880 $diff = htmlspecialchars( wfMsg( 'patrol-log-diff', $cur ) );
5981 }
6082 # Indicate whether or not the patrolling was automatic
6183 $auto = $auto ? wfMsgHtml( 'patrol-log-auto' ) : '';
62 -
 84+ # Put it all together
6385 return wfMsgHtml( 'patrol-log-line', $diff, $link, $auto );
6486 }
6587
Index: branches/robchurch/logs/includes/DefaultSettings.php
@@ -2262,11 +2262,11 @@
22632263
22642264 /**
22652265 * 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
22682268 */
2269 -$wgLogActionCallbacks = array(
2270 - 'patrol' => array( 'PatrolLog', 'makeActionText' ),
 2269+$wgLogFormatAppenders = array(
 2270+
22712271 );
22722272
22732273 /**
@@ -2275,7 +2275,9 @@
22762276 * LogFormatter::format() and should return a complete
22772277 * line including <li></li>
22782278 */
2279 -$wgLogFormatters = array();
 2279+$wgLogFormatters = array(
 2280+ 'patrol' => array( 'PatrolLog', 'formatLine' ),
 2281+);
22802282
22812283 /**
22822284 * Experimental preview feature to fetch rendered text

Follow-up revisions

RevisionCommit summaryAuthorDate
r23456* Forget r23452, this method provides for less code duplication and is just c...robchurch06:44, 27 June 2007

Status & tagging log