From 8c328d030fc1f7f2b9d6fb707e8e21fee13b8569 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Wed, 17 Apr 2013 20:39:58 -0300 Subject: [PATCH] Add identifying info (img_timestamp and img_sha1) to upload log. I came across people complaining that it was hard to associate upload log events to actual images since img_timestamp could be different from log_timestamp, and generally no unique id. Well I was there I made uploads use the new logging system. Change-Id: Icd8662ecb9eb0f6c0ff9841bdbd5736d6dd0d015 --- RELEASE-NOTES-1.22 | 2 ++ includes/api/ApiQueryLogEvents.php | 5 +++++ includes/filerepo/file/LocalFile.php | 26 +++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 50444a7a13..07afffe3e8 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -110,6 +110,8 @@ production. * (bug 47219) Allow specifying change type of Wikipedia feed items * prop=imageinfo now allows setting iiurlheight without setting iiurlwidth * prop=info now adds the content model of the title. +* New upload log entries will now contain information on the relavent + image (sha1 and timestamp). === Languages updated in 1.22=== diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index eaa2b47550..2aa5c28e92 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -265,6 +265,11 @@ class ApiQueryLogEvents extends ApiQueryBase { $vals[$type] = $vals2; $params = null; break; + case 'upload': + if ( isset( $params['img_timestamp'] ) ) { + $params['img_timestamp'] = wfTimestamp( TS_ISO_8601, $params['img_timestamp'] ); + } + break; } if ( !is_null( $params ) ) { $logParams = array(); diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 325c6739a2..932a1d4778 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1275,9 +1275,27 @@ class LocalFile extends File { $wikiPage->setFile( $this ); # Add the log entry - $log = new LogPage( 'upload' ); $action = $reupload ? 'overwrite' : 'upload'; - $logId = $log->addEntry( $action, $descTitle, $comment, array(), $user ); + + $logEntry = new ManualLogEntry( 'upload', $action ); + $logEntry->setPerformer( $user ); + $logEntry->setComment( $comment ); + $logEntry->setTarget( $descTitle ); + + // Allow people using the api to associate log entries with the upload. + // Log has a timestamp, but sometimes different from upload timestamp. + $logEntry->setParameters( + array( + 'img_sha1' => $this->sha1, + 'img_timestamp' => $timestamp, + ) + ); + // Note we keep $logId around since during new image + // creation, page doesn't exist yet, so log_page = 0 + // but we want it to point to the page we're making, + // so we later modify the log entry. + $logId = $logEntry->insert(); + $logEntry->publish( $logId ); wfProfileIn( __METHOD__ . '-edit' ); $exists = $descTitle->exists(); @@ -1285,10 +1303,12 @@ class LocalFile extends File { if ( $exists ) { # Create a null revision $latest = $descTitle->getLatestRevID(); + $editSummary = LogFormatter::newFromEntry( $logEntry )->getPlainActionText(); + $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleID(), - $log->getRcComment(), + $editSummary, false ); if ( !is_null( $nullRevision ) ) { -- 2.20.1