Add identifying info (img_timestamp and img_sha1) to upload log.
authorBrian Wolff <bawolff+wn@gmail.com>
Wed, 17 Apr 2013 23:39:58 +0000 (20:39 -0300)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 10 May 2013 21:10:49 +0000 (21:10 +0000)
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
includes/api/ApiQueryLogEvents.php
includes/filerepo/file/LocalFile.php

index 50444a7..07afffe 100644 (file)
@@ -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===
 
index eaa2b47..2aa5c28 100644 (file)
@@ -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();
index 325c673..932a1d4 100644 (file)
@@ -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 ) ) {