Merge "Remove a hack, and a hack for the hack, for MediaWiki UI input fields"
[lhc/web/wiklou.git] / includes / logging / LogFormatter.php
index c6fcdb0..267a319 100644 (file)
@@ -80,6 +80,9 @@ class LogFormatter {
        /** @var int Constant for handling log_deleted */
        protected $audience = self::FOR_PUBLIC;
 
+       /** @var IContextSource Context for logging */
+       public $context;
+
        /** @var bool Whether to output user tool links */
        protected $linkFlood = false;
 
@@ -328,6 +331,51 @@ class LogFormatter {
                                        ->rawParams( $target, $parameters['4::dest'], $parameters['5::mergepoint'] )
                                        ->inContentLanguage()->escaped();
                                break;
+
+                       case 'block':
+                               switch ( $entry->getSubtype() ) {
+                                       case 'block':
+                                               global $wgContLang;
+                                               // Keep compatibility with extensions by checking for
+                                               // new key (5::duration/6::flags) or old key (0/optional 1)
+                                               if ( $entry->isLegacy() ) {
+                                                       $rawDuration = $parameters[0];
+                                                       $rawFlags = isset( $parameters[1] ) ? $parameters[1] : '';
+                                               } else {
+                                                       $rawDuration = $parameters['5::duration'];
+                                                       $rawFlags = $parameters['6::flags'];
+                                               }
+                                               $duration = $wgContLang->translateBlockExpiry( $rawDuration );
+                                               $flags = BlockLogFormatter::formatBlockFlags( $rawFlags, $wgContLang );
+                                               $text = wfMessage( 'blocklogentry' )
+                                                       ->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped();
+                                               break;
+                                       case 'unblock':
+                                               $text = wfMessage( 'unblocklogentry' )
+                                                       ->rawParams( $target )->inContentLanguage()->escaped();
+                                               break;
+                                       case 'reblock':
+                                               global $wgContLang;
+                                               $duration = $wgContLang->translateBlockExpiry( $parameters['5::duration'] );
+                                               $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'], $wgContLang );
+                                               $text = wfMessage( 'reblock-logentry' )
+                                                       ->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped();
+                                               break;
+                               }
+                               break;
+
+                       case 'import':
+                               switch ( $entry->getSubtype() ) {
+                                       case 'upload':
+                                               $text = wfMessage( 'import-logentry-upload' )
+                                                       ->rawParams( $target )->inContentLanguage()->escaped();
+                                               break;
+                                       case 'interwiki':
+                                               $text = wfMessage( 'import-logentry-interwiki' )
+                                                       ->rawParams( $target )->inContentLanguage()->escaped();
+                                               break;
+                               }
+                               break;
                        // case 'suppress' --private log -- aaron  (so we know who to blame in a few years :-D)
                        // default:
                }
@@ -430,7 +478,8 @@ class LogFormatter {
                 */
                if ( count( $params ) ) {
                        $max = max( array_keys( $params ) );
-                       for ( $i = 4; $i < $max; $i++ ) {
+                       // index 0 to 2 are added in getMessageParameters
+                       for ( $i = 3; $i < $max; $i++ ) {
                                if ( !isset( $params[$i] ) ) {
                                        $params[$i] = '';
                                }
@@ -637,7 +686,7 @@ class LogFormatter {
                return $this->context->msg( $key );
        }
 
-       protected function makeUserLink( User $user ) {
+       protected function makeUserLink( User $user, $toolFlags = 0 ) {
                if ( $this->plaintext ) {
                        $element = $user->getName();
                } else {
@@ -647,9 +696,11 @@ class LogFormatter {
                        );
 
                        if ( $this->linkFlood ) {
-                               $element .= Linker::userToolLinksRedContribs(
+                               $element .= Linker::userToolLinks(
                                        $user->getId(),
                                        $user->getName(),
+                                       true, // redContribsWhenNoEdits
+                                       $toolFlags,
                                        $user->getEditCount()
                                );
                        }
@@ -755,29 +806,7 @@ class LegacyLogFormatter extends LogFormatter {
                $type = $this->entry->getType();
                $subtype = $this->entry->getSubtype();
 
-               // Show unblock/change block link
-               if ( ( $type == 'block' || $type == 'suppress' )
-                       && ( $subtype == 'block' || $subtype == 'reblock' )
-               ) {
-                       if ( !$this->context->getUser()->isAllowed( 'block' ) ) {
-                               return '';
-                       }
-
-                       $links = array(
-                               Linker::linkKnown(
-                                       SpecialPage::getTitleFor( 'Unblock', $title->getDBkey() ),
-                                       $this->msg( 'unblocklink' )->escaped()
-                               ),
-                               Linker::linkKnown(
-                                       SpecialPage::getTitleFor( 'Block', $title->getDBkey() ),
-                                       $this->msg( 'change-blocklink' )->escaped()
-                               )
-                       );
-
-                       return $this->msg( 'parentheses' )->rawParams(
-                               $this->context->getLanguage()->pipeList( $links ) )->escaped();
-               // Show change protection link
-               } elseif ( $type == 'protect'
+               if ( $type == 'protect'
                        && ( $subtype == 'protect' || $subtype == 'modify' || $subtype == 'unprotect' )
                ) {
                        $links = array(