r23454 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23453‎ | r23454 | r23455 >
Date:06:09, 27 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Block log formatter; took the opportunity to add in target tool links and pretty things up a bit
Modified paths:
  • /branches/robchurch/logs/includes/AutoLoader.php (modified) (history)
  • /branches/robchurch/logs/includes/BlockLogFormatter.php (added) (history)
  • /branches/robchurch/logs/includes/CoreLogFormatter.php (added) (history)
  • /branches/robchurch/logs/includes/DefaultSettings.php (modified) (history)
  • /branches/robchurch/logs/includes/SpecialLog.php (modified) (history)
  • /branches/robchurch/logs/languages/messages/MessagesEn.php (modified) (history)
  • /branches/robchurch/logs/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: branches/robchurch/logs/maintenance/language/messages.inc
@@ -1326,9 +1326,9 @@
13271327 'contribslink',
13281328 'autoblocker',
13291329 'blocklogpage',
1330 - 'blocklogentry',
13311330 'blocklogtext',
1332 - 'unblocklogentry',
 1331+ 'block-log-blocked',
 1332+ 'block-log-unblocked',
13331333 'block-log-flags-anononly',
13341334 'block-log-flags-nocreate',
13351335 'block-log-flags-noautoblock',
Index: branches/robchurch/logs/includes/AutoLoader.php
@@ -254,6 +254,8 @@
255255 'EmaillingJob' => 'includes/JobQueue.php',
256256
257257 # Logging
 258+ 'BlockLogFormatter' => 'includes/BlockLogFormatter.php',
 259+ 'CoreLogFormatter' => 'includes/CoreLogFormatter.php',
258260 'LogFormatter' => 'includes/LogFormatter.php',
259261 'LogItem' => 'includes/LogItem.php',
260262 'LogUser' => 'includes/LogUser.php',
Index: branches/robchurch/logs/includes/BlockLogFormatter.php
@@ -0,0 +1,116 @@
 2+<?php
 3+
 4+/**
 5+ * Formatting functions for the block log
 6+ *
 7+ * @addtogroup Logging
 8+ * @author Rob Church <robchur@gmail.com>
 9+ */
 10+class BlockLogFormatter {
 11+
 12+ /**
 13+ * Tool link constants
 14+ */
 15+ const LINK_BLOCK = 1;
 16+ const LINK_UNBLOCK = 2;
 17+
 18+ /**
 19+ * Format a complete block log item
 20+ *
 21+ * @param LogItem $item
 22+ * @param int $flags
 23+ * @return string
 24+ */
 25+ public static function formatBlock( $item, $flags ) {
 26+ global $wgUser, $wgLang, $wgLogActions;
 27+ $skin = $wgUser->getSkin();
 28+ $data = $item->getParameters();
 29+
 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+ # Target link
 37+ $link = $item->getAction() == 'block' ? self::LINK_BLOCK : self::LINK_UNBLOCK;
 38+ $params[] = self::formatTarget( $item->getTarget(), $link );
 39+
 40+ # Format block flags, etc. if applicable
 41+ if( $item->getAction() == 'block' ) {
 42+ $params[] = $wgLang->translateBlockExpiry( $data[0] );
 43+ $params[] = ( isset( $data[1] ) ? self::formatBlockFlags( $data[1] ) : '' );
 44+ }
 45+
 46+ $parts[] = wfMsgReal( $wgLogActions[ $item->getActionKey() ], $params );
 47+ return "<li>" . implode( ' ', $parts ) . "</li>\n";
 48+ }
 49+
 50+ /**
 51+ * Format the block target; link to the user page, standard tool
 52+ * links and an unblock link (if required)
 53+ *
 54+ * @param Title $target
 55+ * @param int $link
 56+ * @return string
 57+ */
 58+ private static function formatTarget( $target, $link ) {
 59+ global $wgUser;
 60+ $skin = $wgUser->getSkin();
 61+
 62+ $tools[] = $skin->makeLinkObj( $target->getTalkPage(), wfMsgHtml( 'talkpagelinktext' ) );
 63+ $tools[] = $skin->makeKnownLinkObj(
 64+ SpecialPage::getTitleFor( 'Contributions', $target->getText() ), wfMsgHtml( 'contribslink' ) );
 65+
 66+ if( $wgUser->isAllowed( 'block' ) ) {
 67+ if( $link == self::LINK_BLOCK ) {
 68+ $tools[] = $skin->makeKnownLinkObj(
 69+ SpecialPage::getTitleFor( 'Blockip', $target->getText() ), wfMsgHtml( 'blocklink' ) );
 70+ } else {
 71+ $tools[] = $skin->makeKnownLinkObj(
 72+ SpecialPage::getTitleFor( 'Ipblocklist', wfMsgHtml( 'unblocklink' ),
 73+ 'action=unblock&ip=' . $target->getPartialUrl() ) );
 74+ }
 75+ }
 76+
 77+ return $skin->makeLinkObj( $target, htmlspecialchars( $target->getText() ) )
 78+ . ' (' . implode( ' | ', $tools ) . ')';
 79+ }
 80+
 81+ /**
 82+ * Convert a comma-delimited list of block log flags
 83+ * into a more readable (and translated) form
 84+ *
 85+ * @param $flags Flags to format
 86+ * @return string
 87+ */
 88+ private static function formatBlockFlags( $flags ) {
 89+ $flags = explode( ',', trim( $flags ) );
 90+ if( count( $flags ) > 0 ) {
 91+ for( $i = 0; $i < count( $flags ); $i++ )
 92+ $flags[$i] = self::formatBlockFlag( $flags[$i] );
 93+ return '(' . implode( ', ', $flags ) . ')';
 94+ } else {
 95+ return '';
 96+ }
 97+ }
 98+
 99+ /**
 100+ * Translate a block log flag if possible
 101+ *
 102+ * @param $flag Flag to translate
 103+ * @return string
 104+ */
 105+ private static function formatBlockFlag( $flag ) {
 106+ static $messages = array();
 107+ if( !isset( $messages[$flag] ) ) {
 108+ $k = 'block-log-flags-' . $flag;
 109+ $msg = wfMsg( $k );
 110+ $messages[$flag] = htmlspecialchars( wfEmptyMsg( $k, $msg ) ? $flag : $msg );
 111+ }
 112+ return $messages[$flag];
 113+ }
 114+
 115+}
 116+
 117+?>
\ No newline at end of file
Property changes on: branches/robchurch/logs/includes/BlockLogFormatter.php
___________________________________________________________________
Added: svn:eol-style
1118 + native
Index: branches/robchurch/logs/includes/SpecialLog.php
@@ -392,11 +392,6 @@
393393 wfMsg( 'undeletebtn' ) ,
394394 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
395395
396 - // show unblock link
397 - } elseif ( $s->log_action == 'block' && $wgUser->isAllowed( 'block' ) ) {
398 - $revert = '(' . $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ),
399 - wfMsg( 'unblocklink' ),
400 - 'action=unblock&ip=' . urlencode( $s->log_title ) ) . ')';
401396 // show change protection link
402397 } elseif ( ( $s->log_action == 'protect' || $s->log_action == 'modify' ) && $wgUser->isAllowed( 'protect' ) ) {
403398 $revert = '(' . $skin->makeKnownLinkObj( $title, wfMsg( 'protect_change' ), 'action=unprotect' ) . ')';
Index: branches/robchurch/logs/includes/DefaultSettings.php
@@ -2243,8 +2243,8 @@
22442244 * Extensions with custom log types may add to this array.
22452245 */
22462246 $wgLogActions = array(
2247 - 'block/block' => 'blocklogentry',
2248 - 'block/unblock' => 'unblocklogentry',
 2247+ 'block/block' => 'block-log-blocked',
 2248+ 'block/unblock' => 'block-log-unblocked',
22492249 'protect/protect' => 'protectedarticle',
22502250 'protect/modify' => 'modifiedarticleprotection',
22512251 'protect/unprotect' => 'unprotectedarticle',
@@ -2266,7 +2266,6 @@
22672267 * a log line during formatting
22682268 */
22692269 $wgLogFormatAppenders = array(
2270 -
22712270 );
22722271
22732272 /**
@@ -2276,6 +2275,7 @@
22772276 * line including <li></li>
22782277 */
22792278 $wgLogFormatters = array(
 2279+ 'block' => array( 'BlockLogFormatter', 'formatBlock' ),
22802280 'patrol' => array( 'PatrolLog', 'formatLine' ),
22812281 );
22822282
Index: branches/robchurch/logs/includes/CoreLogFormatter.php
@@ -0,0 +1,14 @@
 2+<?php
 3+
 4+/**
 5+ * Log formatting functions for all built-in logs
 6+ * which need them
 7+ *
 8+ * @addtogroup Logging
 9+ * @author Rob Church <robchur@gmail.com>
 10+ */
 11+class CoreLogFormatter {
 12+
 13+}
 14+
 15+?>
\ No newline at end of file
Property changes on: branches/robchurch/logs/includes/CoreLogFormatter.php
___________________________________________________________________
Added: svn:eol-style
116 + native
Index: branches/robchurch/logs/languages/messages/MessagesEn.php
@@ -2019,11 +2019,11 @@
20202020 'contribslink' => 'contribs',
20212021 'autoblocker' => 'Autoblocked because your IP address has been recently used by "[[User:$1|$1]]". The reason given for $1\'s block is: "$2"',
20222022 'blocklogpage' => 'Block log',
2023 -'blocklogentry' => 'blocked "[[$1]]" with an expiry time of $2 $3',
20242023 'blocklogtext' => 'This is a log of user blocking and unblocking actions. Automatically
20252024 blocked IP addresses are not listed. See the [[Special:Ipblocklist|IP block list]] for
20262025 the list of currently operational bans and blocks.',
2027 -'unblocklogentry' => 'unblocked $1',
 2026+'block-log-blocked' => 'blocked $1 with an expiry time of $2 $3',
 2027+'block-log-unblocked' => 'unblocked $1',
20282028 'block-log-flags-anononly' => 'anonymous users only',
20292029 'block-log-flags-nocreate' => 'account creation disabled',
20302030 'block-log-flags-noautoblock' => 'autoblock disabled',

Status & tagging log