From fd9feb907b8d652745d0a142becb8a3ccaaaffad Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sat, 28 Mar 2015 18:55:45 +0100 Subject: [PATCH] Added LogEntryBase::extractParams/makeParamBlob Centralize the serialize and unserialize call in the new logging system into two functions to allow reuse by tests. Change-Id: Ibedca39558cbd566661b20e7ebb9d2b6537e4f24 --- includes/logging/LogEntry.php | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 66c2bde1a9..b391be3959 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -115,6 +115,28 @@ abstract class LogEntryBase implements LogEntry { public function isLegacy() { return false; } + + /** + * Create a blob from a parameter array + * + * @param array $params + * @return string + * @since 1.26 + */ + public static function makeParamBlob( $params ) { + return serialize( (array)$params ); + } + + /** + * Extract a parameter array from a blob + * + * @param string $blob + * @return array + * @since 1.26 + */ + public static function extractParams( $blob ) { + return unserialize( $blob ); + } } /** @@ -225,13 +247,13 @@ class DatabaseLogEntry extends LogEntryBase { if ( !isset( $this->params ) ) { $blob = $this->getRawParameters(); wfSuppressWarnings(); - $params = unserialize( $blob ); + $params = LogEntryBase::extractParams( $blob ); wfRestoreWarnings(); if ( $params !== false ) { $this->params = $params; $this->legacy = false; } else { - $this->params = $blob === '' ? array() : explode( "\n", $blob ); + $this->params = LogPage::extractParams( $blob ); $this->legacy = true; } } @@ -516,7 +538,7 @@ class ManualLogEntry extends LogEntryBase { 'log_title' => $this->getTarget()->getDBkey(), 'log_page' => $this->getTarget()->getArticleID(), 'log_comment' => $comment, - 'log_params' => serialize( (array)$this->getParameters() ), + 'log_params' => LogEntryBase::makeParamBlob( $this->getParameters() ), ); if ( isset( $this->deleted ) ) { $data['log_deleted'] = $this->deleted; @@ -584,7 +606,7 @@ class ManualLogEntry extends LogEntryBase { $this->getSubtype(), $this->getTarget(), $this->getComment(), - serialize( (array)$this->getParameters() ), + LogEntryBase::makeParamBlob( $this->getParameters() ), $newId, $formatter->getIRCActionComment() // Used for IRC feeds ); -- 2.20.1