X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flogging%2FBlockLogFormatter.php;h=72fcc3a5df8da050435a7f9684d3328b93679db0;hb=bcdf83c3f9cb77560193cd31c8fb9013e80c86c8;hp=436fed84bb61f9322cfab3bdc672383e6417454c;hpb=0850a99ef198cab515b5b094c9bca6005255e11a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/logging/BlockLogFormatter.php b/includes/logging/BlockLogFormatter.php index 436fed84bb..72fcc3a5df 100644 --- a/includes/logging/BlockLogFormatter.php +++ b/includes/logging/BlockLogFormatter.php @@ -125,7 +125,7 @@ class BlockLogFormatter extends LogFormatter { public static function formatBlockFlags( $flags, $lang ) { $flags = trim( $flags ); if ( $flags === '' ) { - return ''; //nothing to do + return ''; // nothing to do } $flags = explode( ',', $flags ); $flagsCount = count( $flags ); @@ -168,4 +168,57 @@ class BlockLogFormatter extends LogFormatter { return $messages[$flag]; } + + protected function getParametersForApi() { + $entry = $this->entry; + $params = $entry->getParameters(); + + static $map = array( + // While this looks wrong to be starting at 5 rather than 4, it's + // because getMessageParameters uses $4 for its own purposes. + '5::duration', + '6:array:flags', + '6::flags' => '6:array:flags', + ); + foreach ( $map as $index => $key ) { + if ( isset( $params[$index] ) ) { + $params[$key] = $params[$index]; + unset( $params[$index] ); + } + } + + $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 ( !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; + } + + public function formatParametersForApi() { + $ret = parent::formatParametersForApi(); + if ( isset( $ret['flags'] ) ) { + ApiResult::setIndexedTagName( $ret['flags'], 'f' ); + } + return $ret; + } + }