From 9a504d18fb13a6afdc9cc3388a13937d58821bba Mon Sep 17 00:00:00 2001 From: umherirrender Date: Fri, 17 Apr 2015 18:49:50 +0200 Subject: [PATCH] Always set duration/flags of type block for new api logparam style 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 | 4 ++-- includes/logging/BlockLogFormatter.php | 30 +++++++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index b2397272b0..553747e548 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -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(); } } } diff --git a/includes/logging/BlockLogFormatter.php b/includes/logging/BlockLogFormatter.php index 38a279f5f5..07ef24b454 100644 --- a/includes/logging/BlockLogFormatter.php +++ b/includes/logging/BlockLogFormatter.php @@ -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; -- 2.20.1