Fix IRC lines for blocks published with the old logging system
authorumherirrender <umherirrender_de.wp@web.de>
Sat, 14 Mar 2015 11:17:24 +0000 (12:17 +0100)
committerumherirrender <umherirrender_de.wp@web.de>
Sat, 14 Mar 2015 12:43:13 +0000 (13:43 +0100)
The CheckUser and GlobalBlocking extension are inserting the block logs
over the old logging system, where the keys are numeric.
This case is not known when building the irc line, because that was
already migrated to just get the new style.
Added compatibility code for legacy rows.

Needs the legacy flag also in ManualLogEntry to make this happen,
because it is using the LogFormatter of the new logging system to format
the actionText.

Have not found the old way for block/reblock, so just for block/block.

Bug: T92713
Follow-Up: Ibc7fcaa5a952ff90d42a6477da4baa429f3de64b
Change-Id: I08aea8399ce766e98c1a76e237169f220c6cc751

includes/logging/LogEntry.php
includes/logging/LogFormatter.php
includes/logging/LogPage.php

index 85a3052..e9b479b 100644 (file)
@@ -370,6 +370,9 @@ class ManualLogEntry extends LogEntryBase {
        /** @var int ID of the log entry */
        protected $id;
 
+       /** @var bool Whether this is a legacy log entry */
+       protected $legacy = false;
+
        /**
         * Constructor.
         *
@@ -459,6 +462,16 @@ class ManualLogEntry extends LogEntryBase {
                $this->comment = $comment;
        }
 
+       /**
+        * Set the 'legacy' flag
+        *
+        * @since 1.25
+        * @param bool $legacy
+        */
+       public function setLegacy( $legacy ) {
+               $this->legacy = $legacy;
+       }
+
        /**
         * TODO: document
         *
@@ -641,6 +654,14 @@ class ManualLogEntry extends LogEntryBase {
                return $this->comment;
        }
 
+       /**
+        * @since 1.25
+        * @return bool
+        */
+       public function isLegacy() {
+               return $this->legacy;
+       }
+
        public function getDeleted() {
                return (int)$this->deleted;
        }
index 16cf5a1..ce6e0ad 100644 (file)
@@ -336,8 +336,17 @@ class LogFormatter {
                                switch ( $entry->getSubtype() ) {
                                        case 'block':
                                                global $wgContLang;
-                                               $duration = $wgContLang->translateBlockExpiry( $parameters['5::duration'] );
-                                               $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'], $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;
index 30dee81..82e5808 100644 (file)
@@ -422,6 +422,10 @@ class LogPage {
                $logEntry->setTarget( $target );
                $logEntry->setPerformer( $doer );
                $logEntry->setParameters( $params );
+               // All log entries using the LogPage to insert into the logging table
+               // are using the old logging system and therefore the legacy flag is
+               // needed to say the LogFormatter the parameters have numeric keys
+               $logEntry->setLegacy( true );
 
                $formatter = LogFormatter::newFromEntry( $logEntry );
                $context = RequestContext::newExtraneousContext( $target );