From 44eab3b9f07325b5a79ad104054a03f37f2b5aa8 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 14 Jan 2005 13:47:19 +0000 Subject: [PATCH] elaborate fix for bug 1156: Block log: missing expiry time. Changed schema for logging table --- includes/LogPage.php | 49 ++++++++++++++++++----- includes/SpecialBlockip.php | 3 +- includes/SpecialLog.php | 5 ++- maintenance/archives/patch-log_params.sql | 1 + maintenance/tables.sql | 3 ++ 5 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 maintenance/archives/patch-log_params.sql diff --git a/includes/LogPage.php b/includes/LogPage.php index fbe245a19c..373e9a1310 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -32,7 +32,7 @@ * @package MediaWiki */ class LogPage { - /* private */ var $type, $action, $comment; + /* private */ var $type, $action, $comment, $params; var $updateRecentChanges = true; function LogPage( $type ) { @@ -58,7 +58,8 @@ class LogPage { 'log_user' => $uid, 'log_namespace' => $this->target->getNamespace(), 'log_title' => $this->target->getDBkey(), - 'log_comment' => $this->comment + 'log_comment' => $this->comment, + 'log_params' => $this->params ), $fname ); @@ -137,7 +138,7 @@ class LogPage { /** * @static */ - function actionText( $type, $action, $titleLink = NULL ) { + function actionText( $type, $action, $titleLink = NULL, $params = array() ) { static $actions = array( 'block/block' => 'blocklogentry', 'block/unblock' => 'unblocklogentry', @@ -152,9 +153,12 @@ class LogPage { $key = "$type/$action"; if( isset( $actions[$key] ) ) { if( is_null( $titleLink ) ) { - return wfMsg( $actions[$key] ); + return wfMsgForContent( $actions[$key] ); + } elseif ( count( $params ) == 0 ) { + return wfMsgForContent( $actions[$key], $titleLink ); } else { - return wfMsg( $actions[$key], $titleLink ); + array_unshift( $params, $titleLink ); + return wfMsgReal( $actions[$key], $params, true, true ); } } else { wfDebug( "LogPage::actionText - unknown action $key\n" ); @@ -168,17 +172,44 @@ class LogPage { * @param &$target * @param string $comment Description associated */ - function addEntry( $action, &$target, $comment ) { + function addEntry( $action, &$target, $comment, $params = array() ) { global $wgLang, $wgUser; + if ( !is_array( $params ) ) { + $params = array( $params ); + } + $this->action = $action; $this->target =& $target; $this->comment = $comment; - $this->actionText = LogPage::actionText( $this->type, $action, - $target->getPrefixedText() ); - + $this->params = LogPage::makeParamBlob( $params ); + + $this->actionText = LogPage::actionText( $this->type, $action, + $target->getPrefixedText(), $params ); return $this->saveContent(); } + + /** + * Create a blob from a parameter array + * @static + */ + function makeParamBlob( $params ) + { + return implode( "\n", $params ); + } + + /** + * Extract a parameter array from a blob + * @static + */ + function extractParams( $blob ) + { + if ( $blob === '' ) { + return array(); + } else { + return explode( "\n", $blob ); + } + } } ?> diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index 9c698f544e..e95f8aa937 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -170,7 +170,8 @@ class IPBlockForm { # Make log entry $log = new LogPage( 'block' ); - $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), $this->BlockReason ); + $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), + $this->BlockReason, $this->BlockExpiry ); # Report to the user $titleObj = Title::makeTitle( NS_SPECIAL, 'Blockip' ); diff --git a/includes/SpecialLog.php b/includes/SpecialLog.php index 1e0a1933cf..4481d02131 100644 --- a/includes/SpecialLog.php +++ b/includes/SpecialLog.php @@ -146,7 +146,7 @@ class LogReader { $sql = "SELECT log_type, log_action, log_timestamp, log_user, user_name, log_namespace, log_title, page_id, - log_comment FROM $user, $logging "; + log_comment, log_params FROM $user, $logging "; if( !empty( $this->joinClauses ) ) { $sql .= implode( ',', $this->joinClauses ); } @@ -261,8 +261,9 @@ class LogViewer { } else { $comment = '(' . $this->skin->formatComment( $s->log_comment ) . ')'; } + $paramArray = LogPage::extractParams( $s->log_params ); - $action = LogPage::actionText( $s->log_type, $s->log_action, $titleLink ); + $action = LogPage::actionText( $s->log_type, $s->log_action, $titleLink, $paramArray ); $out = "
  • $time $userLink $action $comment
  • \n"; return $out; } diff --git a/maintenance/archives/patch-log_params.sql b/maintenance/archives/patch-log_params.sql new file mode 100644 index 0000000000..aa00a673df --- /dev/null +++ b/maintenance/archives/patch-log_params.sql @@ -0,0 +1 @@ +ALTER TABLE /*$wgDBprefix*/logging ADD log_params blob NOT NULL default ''; diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 9ddddb71cd..1935fcc766 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -333,6 +333,9 @@ CREATE TABLE /*$wgDBprefix*/logging ( -- Freeform text. Interpreted as edit history comments. log_comment varchar(255) NOT NULL default '', + -- LF separated list of miscellaneous parameters + log_params blob NOT NULL default '', + KEY type_time (log_type, log_timestamp), KEY user_time (log_user, log_timestamp), KEY page_time (log_namespace, log_title, log_timestamp) -- 2.20.1