jenkins-bot has submitted this change and it was merged.
Change subject: Make it possible to tag new file uploads without messy queries
......................................................................
Make it possible to tag new file uploads without messy queries
UploadBase::performUpload() now takes a $tags parameter and passes it
to LocalFile::upload() and LocalFile::recordUpload2(), which
eventually adds the requested tags to the log_id, rev_id and rc_id
that are created for the file upload.
Previously you'd have to query the database for the latest rev_id and
log_id for the page title under which the title is being uploaded, as
performUpload() is unable to return them to you because it's all
deferred in funny ways.
Bug: T121874
Change-Id: I99a8fd67c84219d2715d3d88cc21500614431179
---
M includes/filerepo/file/LocalFile.php
M includes/logging/LogEntry.php
M includes/upload/UploadBase.php
3 files changed, 26 insertions(+), 10 deletions(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/filerepo/file/LocalFile.php
b/includes/filerepo/file/LocalFile.php
index 9e214f6..01a73dc 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -1119,12 +1119,12 @@
* @param string|bool $timestamp Timestamp for img_timestamp, or false
to use the
* current time
* @param User|null $user User object or null to use $wgUser
- *
+ * @param string[] $tags Change tags to add to the log entry and page
revision.
* @return FileRepoStatus On success, the value member contains the
* archive name, or an empty string if it was a new file.
*/
function upload( $srcPath, $comment, $pageText, $flags = 0, $props =
false,
- $timestamp = false, $user = null
+ $timestamp = false, $user = null, $tags = array()
) {
global $wgContLang;
@@ -1166,7 +1166,8 @@
// It is only *preferable* to avoid leaving such files
orphaned.
// Once the second operation goes through, then the
current version was
// updated and we must therefore update the DB too.
- if ( !$this->recordUpload2( $status->value, $comment,
$pageText, $props, $timestamp, $user ) ) {
+ $oldver = $status->value;
+ if ( !$this->recordUpload2( $oldver, $comment,
$pageText, $props, $timestamp, $user, $tags ) ) {
$status->fatal( 'filenotfound', $srcPath );
}
}
@@ -1216,10 +1217,11 @@
* @param bool|array $props
* @param string|bool $timestamp
* @param null|User $user
+ * @param string[] $tags
* @return bool
*/
function recordUpload2(
- $oldver, $comment, $pageText, $props = false, $timestamp =
false, $user = null
+ $oldver, $comment, $pageText, $props = false, $timestamp =
false, $user = null, $tags = array()
) {
if ( is_null( $user ) ) {
global $wgUser;
@@ -1413,7 +1415,7 @@
# b) They won't cause rollback of the log publish/update above
$that = $this;
$dbw->onTransactionIdle( function () use (
- $that, $reupload, $wikiPage, $newPageContent, $comment,
$user, $logEntry, $logId, $descId
+ $that, $reupload, $wikiPage, $newPageContent, $comment,
$user, $logEntry, $logId, $descId, $tags
) {
# Update memcache after the commit
$that->invalidateCache();
@@ -1476,7 +1478,17 @@
);
# Now that the log entry is up-to-date, make an RC
entry.
- $logEntry->publish( $logId );
+ $recentChange = $logEntry->publish( $logId );
+
+ if ( $tags ) {
+ ChangeTags::addTags(
+ $tags,
+ $recentChange ?
$recentChange->getAttribute( 'rc_id' ) : null,
+ $logEntry->getAssociatedRevId(),
+ $logId
+ );
+ }
+
# Run hook for other updates (typically more cache
purging)
Hooks::run( 'FileUpload', array( $that, $reupload,
!$newPageContent ) );
diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php
index db588fd..ddcb636 100644
--- a/includes/logging/LogEntry.php
+++ b/includes/logging/LogEntry.php
@@ -672,11 +672,12 @@
*
* @param int $newId Id of the log entry.
* @param string $to One of: rcandudp (default), rc, udp
+ * @return RecentChange|null
*/
public function publish( $newId, $to = 'rcandudp' ) {
$log = new LogPage( $this->getType() );
if ( $log->isRestricted() ) {
- return;
+ return null;
}
$rc = $this->getRecentChange( $newId );
@@ -694,6 +695,8 @@
$rc->getAttribute( 'rc_patrolled' ) === 1 ) {
PatrolLog::record( $rc, true, $this->getPerformer() );
}
+
+ return $rc;
}
public function getType() {
diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php
index f8624d0..ad26f7d 100644
--- a/includes/upload/UploadBase.php
+++ b/includes/upload/UploadBase.php
@@ -692,10 +692,10 @@
* @param string $pageText
* @param bool $watch
* @param User $user
- *
+ * @param string[] $tags Change tags to add to the log entry and page
revision.
* @return Status Indicating the whether the upload succeeded.
*/
- public function performUpload( $comment, $pageText, $watch, $user ) {
+ public function performUpload( $comment, $pageText, $watch, $user,
$tags = array() ) {
$this->getLocalFile()->load( File::READ_LATEST );
$status = $this->getLocalFile()->upload(
@@ -705,7 +705,8 @@
File::DELETE_SOURCE,
$this->mFileProps,
false,
- $user
+ $user,
+ $tags
);
if ( $status->isGood() ) {
--
To view, visit https://gerrit.wikimedia.org/r/265620
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I99a8fd67c84219d2715d3d88cc21500614431179
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits