Always set duration/flags of type block for new api logparam style
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 17 Apr 2015 16:49:50 +0000 (18:49 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Fri, 17 Apr 2015 17:57:18 +0000 (19:57 +0200)
Old and very old log params may omit a duration or flags. Always adds
these parameters to the output.
Also simplify the infinity check (see also
I5eb68c1fb6029da8289276ecf7c81330575029ef) and check the return of
strtotime.

Bug: T92902
Follow-Up: I6846ce09322eb404c506b5a51780a44ce9279fe2
Change-Id: I9109a27f416b002e5c562a1454d8c373dcf98fb4

includes/api/ApiQueryLogEvents.php
includes/logging/BlockLogFormatter.php

index b239727..553747e 100644 (file)
@@ -295,8 +295,8 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                        $vals['pageid'] = intval( $row->page_id );
                                        $vals['logpage'] = intval( $row->log_page );
                                }
-                               if ( $this->fld_details && $row->log_params !== '' ) {
-                                       $vals['params'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
+                               if ( $this->fld_details ) {
+                                       $vals['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
                                }
                        }
                }
index 38a279f..07ef24b 100644 (file)
@@ -187,17 +187,27 @@ class BlockLogFormatter extends LogFormatter {
                        }
                }
 
-               if ( isset( $params['6:array:flags'] ) && !is_array( $params['6:array:flags'] ) ) {
-                       $params['6:array:flags'] = $params['6:array:flags'] === ''
-                               ? array()
-                               : explode( ',', $params['6:array:flags'] );
-               }
+               $subtype = $entry->getSubtype();
+               if ( $subtype === 'block' || $subtype === 'reblock' ) {
+                       // Defaults for old log entries missing some fields
+                       $params += array(
+                               '5::duration' => 'infinite',
+                               '6:array:flags' => array(),
+                       );
+
+                       if ( !is_array( $params['6:array:flags'] ) ) {
+                               $params['6:array:flags'] = $params['6:array:flags'] === ''
+                                       ? array()
+                                       : explode( ',', $params['6:array:flags'] );
+                       }
 
-               if ( isset( $params['5::duration'] ) &&
-                       SpecialBlock::parseExpiryInput( $params['5::duration'] ) !== wfGetDB( DB_SLAVE )->getInfinity()
-               ) {
-                       $ts = wfTimestamp( TS_UNIX, $entry->getTimestamp() );
-                       $params[':timestamp:expiry'] = strtotime( $params['5::duration'], $ts );
+                       if ( !wfIsInfinity( $params['5::duration'] ) ) {
+                               $ts = wfTimestamp( TS_UNIX, $entry->getTimestamp() );
+                               $expiry = strtotime( $params['5::duration'], $ts );
+                               if ( $expiry !== false && $expiry > 0 ) {
+                                       $params[':timestamp:expiry'] = $expiry;
+                               }
+                       }
                }
 
                return $params;